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

Commit ce9fc3f

Browse files
theScrabiabelgardep
authored andcommitted
apply changes acording to review
1 parent 257494a commit ce9fc3f

File tree

1 file changed

+29
-22
lines changed
  • owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses

1 file changed

+29
-22
lines changed

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

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ import com.owncloud.android.lib.resources.CommonOcsResponse
2828
import com.squareup.moshi.JsonAdapter
2929
import com.squareup.moshi.Moshi
3030
import com.squareup.moshi.Types
31+
import org.junit.Assert.assertNotNull
32+
import org.junit.Assert.assertNull
3133
import org.junit.Assert.assertEquals
32-
import org.junit.Assert.assertNotEquals
3334
import org.junit.Assert.assertTrue
3435
import org.junit.Before
3536
import org.junit.Test
@@ -38,85 +39,91 @@ import java.lang.reflect.Type
3839

3940
class ShareeResponseTest {
4041

41-
lateinit var response: CommonOcsResponse<ShareeOcsResponse>
42+
lateinit var adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>>
4243

43-
private fun loadResponses(fileName: String, adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>>) =
44+
private fun loadResponses(fileName: String) =
4445
adapter.fromJson(File(fileName).readText())
4546

4647
@Before
4748
fun prepare() {
4849
val moshi = Moshi.Builder().build()
4950
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
50-
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
51-
response = loadResponses(EXAMPLE_RESPONSE_JSON, adapter)!!
52-
}
53-
54-
@Test
55-
fun `check structure - ok - example response files exist`() {
56-
val file = File(EXAMPLE_RESPONSE_JSON)
57-
assertTrue(file.exists())
51+
adapter = moshi.adapter(type)
5852
}
5953

6054
@Test
6155
fun `check structure - ok - contains meta`() {
56+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
6257
assertEquals("OK", response.ocs.meta.message!!)
63-
assertEquals(200, response.ocs.meta.statusCode!!)
64-
assertEquals("ok", response.ocs.meta.status!!)
58+
assertEquals(200, response.ocs.meta.statusCode)
59+
assertEquals("ok", response.ocs.meta.status)
6560
assertTrue(response.ocs.meta.itemsPerPage?.isEmpty()!!)
6661
assertTrue(response.ocs.meta.totalItems?.isEmpty()!!)
6762
}
6863

6964
@Test
7065
fun `check structure - ok - contains exact`() {
71-
assertNotEquals(null, response.ocs.data.exact)
66+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
67+
assertNotNull(response.ocs.data.exact)
7268
}
7369

7470
@Test
7571
fun `check structure - ok - contains groups`() {
76-
assertNotEquals(null, response.ocs.data.groups)
72+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
73+
assertNotNull(response.ocs.data.groups)
7774
}
7875

7976
@Test
8077
fun `check structure - ok - contains remotes`() {
81-
assertNotEquals(null, response.ocs.data.remotes)
78+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
79+
assertNotNull(response.ocs.data.remotes)
8280
}
8381

8482
@Test
8583
fun `check structure - ok - contains users`() {
86-
assertNotEquals(null, response.ocs.data.users)
84+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
85+
assertNotNull(response.ocs.data.users)
8786
}
8887

8988
@Test
9089
fun `check structure - ok - groups contains two items`() {
90+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
9191
assertEquals(2, response.ocs.data.groups.size)
9292
}
9393

9494
@Test
9595
fun `check structure - ok - users contains two items`() {
96+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
9697
assertEquals(2, response.ocs.data.users.size)
9798
}
9899

99100
@Test
100101
fun `check structure - ok - exact_users contains one item`() {
102+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
101103
assertEquals(1, response.ocs.data.exact?.users?.size)
102104
}
103105

104106
@Test
105107
fun `check structure - ok - user1 contains additional data`() {
108+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
106109
assertEquals("[email protected]", response.ocs.data.users.get(0).value.additionalInfo)
107110
}
108111

109112
@Test
110113
fun `check structure - ok - user2 does not contain additional data`() {
111-
assertEquals(null, response.ocs.data.users[1].value.additionalInfo)
114+
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
115+
assertNull(response.ocs.data.users[1].value.additionalInfo)
112116
}
113117

114118
@Test
115119
fun `check empty response - ok - parsing ok`() {
116-
val moshi = Moshi.Builder().build()
117-
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
118-
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
119-
loadResponses(EMPTY_RESPONSE_JSON, adapter)!!
120+
val response = loadResponses(EMPTY_RESPONSE_JSON)!!
121+
assertTrue(response.ocs.data.exact?.groups?.isEmpty()!!)
122+
assertTrue(response.ocs.data.exact?.remotes?.isEmpty()!!)
123+
assertTrue(response.ocs.data.exact?.users?.isEmpty()!!)
124+
assertTrue(response.ocs.data.groups.isEmpty())
125+
assertTrue(response.ocs.data.remotes.isEmpty())
126+
assertTrue(response.ocs.data.users.isEmpty())
120127
}
121128

122129
companion object {

0 commit comments

Comments
 (0)