Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 257cbcf

Browse files
theScrabiabelgardep
authored andcommitted
add basic test functionality for andorid library
1 parent cc91ad9 commit 257cbcf

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteStatusOperation.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
6868
return latestResult
6969
}
7070

71-
private fun updateLocationWithRelativePath(oldLocation: String, redirectedLocation: String): String {
71+
fun updateLocationWithRedirectPath(oldLocation: String, redirectedLocation: String): String {
7272
if(!redirectedLocation.startsWith("/"))
7373
return redirectedLocation
7474
val oldLocation = URL(oldLocation)
@@ -97,7 +97,7 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
9797
return successfulConnection
9898
}
9999

100-
var redirectedLocation = updateLocationWithRelativePath(baseUrlStr, latestResult.redirectedLocation)
100+
var redirectedLocation = updateLocationWithRedirectPath(baseUrlStr, latestResult.redirectedLocation)
101101
while (!redirectedLocation.isNullOrEmpty() && !latestResult.isSuccess) {
102102
isRedirectToNonSecureConnection =
103103
isRedirectToNonSecureConnection ||
@@ -112,7 +112,7 @@ class GetRemoteStatusOperation : RemoteOperation<OwnCloudVersion>() {
112112

113113
status = client.executeHttpMethod(getMethod)
114114
latestResult = RemoteOperationResult(getMethod)
115-
redirectedLocation = updateLocationWithRelativePath(redirectedLocation, latestResult.redirectedLocation)
115+
redirectedLocation = updateLocationWithRedirectPath(redirectedLocation, latestResult.redirectedLocation)
116116
}
117117

118118
if (isSuccess(status)) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.owncloud.android.lib
2+
3+
import com.owncloud.android.lib.resources.status.GetRemoteStatusOperation
4+
import org.junit.Assert.assertEquals
5+
import org.junit.Test
6+
7+
class GetRemoteStatusOperationTest {
8+
private val remoteStatusOperation = GetRemoteStatusOperation()
9+
10+
@Test
11+
fun `update location with an absolute path`() {
12+
val newLocation = remoteStatusOperation.updateLocationWithRedirectPath(
13+
"https://cloud.somewhere.com", "https://cloud.somewhere.com/subdir"
14+
)
15+
assertEquals("https://cloud.somewhere.com/subdir", newLocation)
16+
}
17+
18+
@Test
19+
fun `update location with a smaler aboslute path`() {
20+
21+
val newLocation = remoteStatusOperation.updateLocationWithRedirectPath(
22+
"https://cloud.somewhere.com/subdir", "https://cloud.somewhere.com/"
23+
)
24+
assertEquals("https://cloud.somewhere.com/", newLocation)
25+
}
26+
27+
@Test
28+
fun `update location with a relative path`() {
29+
val newLocation = remoteStatusOperation.updateLocationWithRedirectPath(
30+
"https://cloud.somewhere.com", "/subdir"
31+
)
32+
assertEquals("https://cloud.somewhere.com/subdir", newLocation)
33+
}
34+
35+
@Test
36+
fun `update location by replacing the relative path`() {
37+
val newLocation = remoteStatusOperation.updateLocationWithRedirectPath(
38+
"https://cloud.somewhere.com/some/other/subdir", "/subdir"
39+
)
40+
assertEquals("https://cloud.somewhere.com/subdir", newLocation)
41+
}
42+
}

0 commit comments

Comments
 (0)