-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edcd2d4
commit 444892b
Showing
10 changed files
with
468 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...rc/test/java/com/owncloud/android/domain/authentication/usecases/LoginAsyncUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* ownCloud Android client application | ||
* | ||
* @author Abel García de Prada | ||
* Copyright (C) 2020 ownCloud GmbH. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.owncloud.android.domain.authentication.usecases | ||
|
||
import com.owncloud.android.domain.authentication.AuthenticationRepository | ||
import io.mockk.every | ||
import io.mockk.spyk | ||
import io.mockk.verify | ||
import org.junit.Assert | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class LoginAsyncUseCaseTest { | ||
private val authRepository: AuthenticationRepository = spyk() | ||
private val useCase = LoginAsyncUseCase(authRepository) | ||
private val useCaseParams = LoginAsyncUseCase.Params( | ||
serverPath = "http://demo.owncloud.com", | ||
username = "test", | ||
password = "test" | ||
) | ||
|
||
@Test | ||
fun invalidParams() { | ||
var invalidUseCaseParams = useCaseParams.copy(serverPath = "") | ||
var useCaseResult = useCase.execute(invalidUseCaseParams) | ||
|
||
assertTrue(useCaseResult.isError) | ||
assertTrue(useCaseResult.getThrowableOrNull() is IllegalArgumentException) | ||
|
||
invalidUseCaseParams = useCaseParams.copy(username = "") | ||
useCaseResult = useCase.execute(invalidUseCaseParams) | ||
|
||
assertTrue(useCaseResult.isError) | ||
assertTrue(useCaseResult.getThrowableOrNull() is IllegalArgumentException) | ||
|
||
invalidUseCaseParams = useCaseParams.copy(password = "") | ||
useCaseResult = useCase.execute(invalidUseCaseParams) | ||
|
||
assertTrue(useCaseResult.isError) | ||
assertTrue(useCaseResult.getThrowableOrNull() is IllegalArgumentException) | ||
|
||
verify(exactly = 0) { authRepository.login(any(), any(), any()) } | ||
} | ||
|
||
@Test | ||
fun loginSuccess() { | ||
every { authRepository.login(any(), any(), any()) } returns Unit | ||
val useCaseResult = useCase.execute(useCaseParams) | ||
|
||
assertTrue(useCaseResult.isSuccess) | ||
assertFalse(useCaseResult.isError) | ||
|
||
assertNull(useCaseResult.getThrowableOrNull()) | ||
assertEquals(Unit, useCaseResult.getDataOrNull()) | ||
|
||
verify(exactly = 1) { authRepository.login(any(), any(), any()) } | ||
} | ||
|
||
@Test | ||
fun getServerInfoWithException() { | ||
every { authRepository.login(any(), any(), any()) } throws Exception() | ||
|
||
val useCaseResult = useCase.execute(useCaseParams) | ||
|
||
assertFalse(useCaseResult.isSuccess) | ||
assertTrue(useCaseResult.isError) | ||
|
||
assertNull(useCaseResult.getDataOrNull()) | ||
assertTrue(useCaseResult.getThrowableOrNull() is Exception) | ||
|
||
verify(exactly = 1) { authRepository.login(any(), any(), any()) } | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
owncloudDomain/src/test/java/com/owncloud/android/domain/server/model/ServerInfoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* ownCloud Android client application | ||
* | ||
* @author Abel García de Prada | ||
* Copyright (C) 2020 ownCloud GmbH. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.owncloud.android.domain.server.model | ||
|
||
import com.owncloud.android.domain.server.model.AuthenticationMethod.BASIC_HTTP_AUTH | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class ServerInfoTest { | ||
|
||
@Test | ||
fun testConstructor() { | ||
val item = ServerInfo( | ||
"10.3.2.1", | ||
"https://demo.owncloud.com", | ||
BASIC_HTTP_AUTH, | ||
false | ||
) | ||
|
||
assertEquals(BASIC_HTTP_AUTH, item.authenticationMethod) | ||
assertEquals("https://demo.owncloud.com", item.baseUrl) | ||
assertEquals("10.3.2.1", item.ownCloudVersion) | ||
assertEquals(false, item.isSecureConnection) | ||
} | ||
|
||
@Test | ||
fun testEqualsOk() { | ||
val item1 = ServerInfo( | ||
authenticationMethod = BASIC_HTTP_AUTH, | ||
baseUrl = "https://demo.owncloud.com", | ||
ownCloudVersion = "10.3.2.1", | ||
isSecureConnection = false | ||
) | ||
|
||
val item2 = ServerInfo( | ||
"10.3.2.1", | ||
"https://demo.owncloud.com", | ||
BASIC_HTTP_AUTH, | ||
false | ||
) | ||
|
||
assertTrue(item1 == item2) | ||
assertFalse(item1 === item2) | ||
} | ||
|
||
@Test | ||
fun testEqualsKo() { | ||
val item1 = ServerInfo( | ||
authenticationMethod = BASIC_HTTP_AUTH, | ||
baseUrl = "https://demo.owncloud.com", | ||
ownCloudVersion = "10.3.2.1", | ||
isSecureConnection = false | ||
) | ||
|
||
val item2 = ServerInfo( | ||
"10.0.0.0", | ||
"https://demo.owncloud.com", | ||
BASIC_HTTP_AUTH, | ||
false | ||
) | ||
|
||
assertFalse(item1 == item2) | ||
assertFalse(item1 === item2) | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...rc/test/java/com/owncloud/android/domain/server/usecases/CheckPathExistenceUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* ownCloud Android client application | ||
* | ||
* @author Abel García de Prada | ||
* Copyright (C) 2020 ownCloud GmbH. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.owncloud.android.domain.server.usecases | ||
|
||
import com.owncloud.android.domain.server.ServerRepository | ||
import io.mockk.every | ||
import io.mockk.spyk | ||
import io.mockk.verify | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class CheckPathExistenceUseCaseTest { | ||
private val serverRepository: ServerRepository = spyk() | ||
private val useCase = CheckPathExistenceUseCase(serverRepository) | ||
private val useCaseParams = CheckPathExistenceUseCase.Params( | ||
remotePath = "http://demo.owncloud.com", | ||
isUserLogged = false | ||
) | ||
|
||
@Test | ||
fun getServerInfoSuccess() { | ||
every { serverRepository.checkPathExistence(any(), any()) } returns true | ||
val useCaseResult = useCase.execute(useCaseParams) | ||
|
||
assertTrue(useCaseResult.isSuccess) | ||
assertFalse(useCaseResult.isError) | ||
|
||
assertNull(useCaseResult.getThrowableOrNull()) | ||
assertEquals(true, useCaseResult.getDataOrNull()) | ||
|
||
verify(exactly = 1) { serverRepository.checkPathExistence(any(), any()) } | ||
} | ||
|
||
@Test | ||
fun getServerInfoWithException() { | ||
every { serverRepository.checkPathExistence(any(), any()) } throws Exception() | ||
|
||
val useCaseResult = useCase.execute(useCaseParams) | ||
|
||
assertFalse(useCaseResult.isSuccess) | ||
assertTrue(useCaseResult.isError) | ||
|
||
assertNull(useCaseResult.getDataOrNull()) | ||
assertTrue(useCaseResult.getThrowableOrNull() is Exception) | ||
|
||
verify(exactly = 1) { serverRepository.checkPathExistence(any(), any()) } | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...ain/src/test/java/com/owncloud/android/domain/server/usecases/GetServerInfoUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* ownCloud Android client application | ||
* | ||
* @author Abel García de Prada | ||
* Copyright (C) 2020 ownCloud GmbH. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License version 2, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.owncloud.android.domain.server.usecases | ||
|
||
import com.owncloud.android.domain.server.AnonymousServerRepository | ||
import com.owncloud.android.testutil.OCServerInfo | ||
import io.mockk.every | ||
import io.mockk.spyk | ||
import io.mockk.verify | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class GetServerInfoUseCaseTest { | ||
private val anonymousServerRepository: AnonymousServerRepository = spyk() | ||
private val useCase = GetServerInfoUseCase((anonymousServerRepository)) | ||
private val useCaseParams = GetServerInfoUseCase.Params(serverPath = "http://demo.owncloud.com") | ||
|
||
@Test | ||
fun getServerInfoSuccess() { | ||
every { anonymousServerRepository.getServerInfo(useCaseParams.serverPath) } returns OCServerInfo | ||
val useCaseResult = useCase.execute(useCaseParams) | ||
|
||
assertTrue(useCaseResult.isSuccess) | ||
assertFalse(useCaseResult.isError) | ||
|
||
assertNull(useCaseResult.getThrowableOrNull()) | ||
assertEquals(OCServerInfo, useCaseResult.getDataOrNull()) | ||
|
||
verify(exactly = 1) { anonymousServerRepository.getServerInfo(useCaseParams.serverPath) } | ||
} | ||
|
||
@Test | ||
fun getServerInfoWithException() { | ||
every { anonymousServerRepository.getServerInfo(useCaseParams.serverPath) } throws Exception() | ||
|
||
val useCaseResult = useCase.execute(useCaseParams) | ||
|
||
assertFalse(useCaseResult.isSuccess) | ||
assertTrue(useCaseResult.isError) | ||
|
||
assertNull(useCaseResult.getDataOrNull()) | ||
assertTrue(useCaseResult.getThrowableOrNull() is Exception) | ||
|
||
verify(exactly = 1) { anonymousServerRepository.getServerInfo(useCaseParams.serverPath)} | ||
} | ||
} |
Oops, something went wrong.