@@ -28,8 +28,9 @@ import com.owncloud.android.lib.resources.CommonOcsResponse
28
28
import com.squareup.moshi.JsonAdapter
29
29
import com.squareup.moshi.Moshi
30
30
import com.squareup.moshi.Types
31
+ import org.junit.Assert.assertNotNull
32
+ import org.junit.Assert.assertNull
31
33
import org.junit.Assert.assertEquals
32
- import org.junit.Assert.assertNotEquals
33
34
import org.junit.Assert.assertTrue
34
35
import org.junit.Before
35
36
import org.junit.Test
@@ -38,85 +39,91 @@ import java.lang.reflect.Type
38
39
39
40
class ShareeResponseTest {
40
41
41
- lateinit var response : CommonOcsResponse <ShareeOcsResponse >
42
+ lateinit var adapter : JsonAdapter < CommonOcsResponse <ShareeOcsResponse > >
42
43
43
- private fun loadResponses (fileName : String , adapter : JsonAdapter < CommonOcsResponse < ShareeOcsResponse >> ) =
44
+ private fun loadResponses (fileName : String ) =
44
45
adapter.fromJson(File (fileName).readText())
45
46
46
47
@Before
47
48
fun prepare () {
48
49
val moshi = Moshi .Builder ().build()
49
50
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)
58
52
}
59
53
60
54
@Test
61
55
fun `check structure - ok - contains meta` () {
56
+ val response = loadResponses(EXAMPLE_RESPONSE_JSON )!!
62
57
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)
65
60
assertTrue(response.ocs.meta.itemsPerPage?.isEmpty()!! )
66
61
assertTrue(response.ocs.meta.totalItems?.isEmpty()!! )
67
62
}
68
63
69
64
@Test
70
65
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)
72
68
}
73
69
74
70
@Test
75
71
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)
77
74
}
78
75
79
76
@Test
80
77
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)
82
80
}
83
81
84
82
@Test
85
83
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)
87
86
}
88
87
89
88
@Test
90
89
fun `check structure - ok - groups contains two items` () {
90
+ val response = loadResponses(EXAMPLE_RESPONSE_JSON )!!
91
91
assertEquals(2 , response.ocs.data.groups.size)
92
92
}
93
93
94
94
@Test
95
95
fun `check structure - ok - users contains two items` () {
96
+ val response = loadResponses(EXAMPLE_RESPONSE_JSON )!!
96
97
assertEquals(2 , response.ocs.data.users.size)
97
98
}
98
99
99
100
@Test
100
101
fun `check structure - ok - exact_users contains one item` () {
102
+ val response = loadResponses(EXAMPLE_RESPONSE_JSON )!!
101
103
assertEquals(1 , response.ocs.data.exact?.users?.size)
102
104
}
103
105
104
106
@Test
105
107
fun `check structure - ok - user1 contains additional data` () {
108
+ val response = loadResponses(EXAMPLE_RESPONSE_JSON )!!
106
109
assertEquals(
" [email protected] " , response.ocs.data.users.get(
0 ).value.additionalInfo)
107
110
}
108
111
109
112
@Test
110
113
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)
112
116
}
113
117
114
118
@Test
115
119
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())
120
127
}
121
128
122
129
companion object {
0 commit comments