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

Commit f9bc792

Browse files
committed
Do data field not mandatory on ocs response
1 parent 9adadbd commit f9bc792

File tree

3 files changed

+21
-21
lines changed

3 files changed

+21
-21
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ data class CommonOcsResponse<T>(
3636
@JsonClass(generateAdapter = true)
3737
data class OCSResponse<T>(
3838
val meta: MetaData,
39-
val data: T
39+
val data: T?
4040
)
4141

4242
@JsonClass(generateAdapter = true)

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteShareesOperation.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ class GetRemoteShareesOperation
9999
.appendQueryParameter(PARAM_PER_PAGE, perPage.toString())
100100
.build()
101101

102-
private fun parseResponse(response: String): ShareeOcsResponse? {
102+
private fun parseResponse(response: String?): ShareeOcsResponse? {
103103
val moshi = Moshi.Builder().build()
104104
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
105105
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
106-
return adapter.fromJson(response)!!.ocs.data
106+
return response?.let { adapter.fromJson(it)?.ocs?.data }
107107
}
108108

109109
private fun onResultUnsuccessful(
@@ -123,7 +123,7 @@ class GetRemoteShareesOperation
123123
private fun onRequestSuccessful(response: String?): RemoteOperationResult<ShareeOcsResponse> {
124124
val result = RemoteOperationResult<ShareeOcsResponse>(OK)
125125
Timber.d("Successful response: $response")
126-
result.data = parseResponse(response!!)
126+
result.data = parseResponse(response)
127127
Timber.d("*** Get Users or groups completed ")
128128
return result
129129
}

owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponseTest.kt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,31 @@ class ShareeResponseTest {
6363
@Test
6464
fun `example response - ok - correct sturcture`() {
6565
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
66-
assertEquals(2, response.ocs.data.groups.size)
67-
assertEquals(0, response.ocs.data.remotes.size)
68-
assertEquals(2, response.ocs.data.users.size)
69-
assertEquals(0, response.ocs.data.exact?.groups?.size)
70-
assertEquals(0, response.ocs.data.exact?.remotes?.size)
71-
assertEquals(1, response.ocs.data.exact?.users?.size)
72-
assertEquals("[email protected]", response.ocs.data.users.get(0).value.additionalInfo)
73-
assertNull(response.ocs.data.users[1].value.additionalInfo)
66+
assertEquals(2, response.ocs.data?.groups?.size)
67+
assertEquals(0, response.ocs.data?.remotes?.size)
68+
assertEquals(2, response.ocs.data?.users?.size)
69+
assertEquals(0, response.ocs.data?.exact?.groups?.size)
70+
assertEquals(0, response.ocs.data?.exact?.remotes?.size)
71+
assertEquals(1, response.ocs.data?.exact?.users?.size)
72+
assertEquals("[email protected]", response.ocs.data?.users?.get(0)?.value?.additionalInfo)
73+
assertNull(response.ocs.data?.users?.get(1)?.value?.additionalInfo)
7474
}
7575

7676
@Test
7777
fun `check empty response - ok - parsing ok`() {
7878
val response = loadResponses(EMPTY_RESPONSE_JSON)!!
79-
assertTrue(response.ocs.data.exact?.groups?.isEmpty()!!)
80-
assertTrue(response.ocs.data.exact?.remotes?.isEmpty()!!)
81-
assertTrue(response.ocs.data.exact?.users?.isEmpty()!!)
82-
assertTrue(response.ocs.data.groups.isEmpty())
83-
assertTrue(response.ocs.data.remotes.isEmpty())
84-
assertTrue(response.ocs.data.users.isEmpty())
79+
assertTrue(response.ocs.data?.exact?.groups?.isEmpty()!!)
80+
assertTrue(response.ocs.data?.exact?.remotes?.isEmpty()!!)
81+
assertTrue(response.ocs.data?.exact?.users?.isEmpty()!!)
82+
assertTrue(response.ocs.data?.groups?.isEmpty()!!)
83+
assertTrue(response.ocs.data?.remotes?.isEmpty()!!)
84+
assertTrue(response.ocs.data?.users?.isEmpty()!!)
8585
}
8686

8787
companion object {
88-
val RESOURCES_PATH =
88+
private const val RESOURCES_PATH =
8989
"src/test/responses/com.owncloud.android.lib.resources.sharees.responses"
90-
val EXAMPLE_RESPONSE_JSON = "$RESOURCES_PATH/example_sharee_response.json"
91-
val EMPTY_RESPONSE_JSON = "$RESOURCES_PATH/empty_sharee_response.json"
90+
const val EXAMPLE_RESPONSE_JSON = "$RESOURCES_PATH/example_sharee_response.json"
91+
const val EMPTY_RESPONSE_JSON = "$RESOURCES_PATH/empty_sharee_response.json"
9292
}
9393
}

0 commit comments

Comments
 (0)