mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-07 16:06:08 +00:00
apply changes acording to review
This commit is contained in:
parent
257494a9dc
commit
ce9fc3f189
@ -28,8 +28,9 @@ import com.owncloud.android.lib.resources.CommonOcsResponse
|
|||||||
import com.squareup.moshi.JsonAdapter
|
import com.squareup.moshi.JsonAdapter
|
||||||
import com.squareup.moshi.Moshi
|
import com.squareup.moshi.Moshi
|
||||||
import com.squareup.moshi.Types
|
import com.squareup.moshi.Types
|
||||||
|
import org.junit.Assert.assertNotNull
|
||||||
|
import org.junit.Assert.assertNull
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Assert.assertNotEquals
|
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
@ -38,85 +39,91 @@ import java.lang.reflect.Type
|
|||||||
|
|
||||||
class ShareeResponseTest {
|
class ShareeResponseTest {
|
||||||
|
|
||||||
lateinit var response: CommonOcsResponse<ShareeOcsResponse>
|
lateinit var adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>>
|
||||||
|
|
||||||
private fun loadResponses(fileName: String, adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>>) =
|
private fun loadResponses(fileName: String) =
|
||||||
adapter.fromJson(File(fileName).readText())
|
adapter.fromJson(File(fileName).readText())
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
fun prepare() {
|
fun prepare() {
|
||||||
val moshi = Moshi.Builder().build()
|
val moshi = Moshi.Builder().build()
|
||||||
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
|
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
|
||||||
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
|
adapter = moshi.adapter(type)
|
||||||
response = loadResponses(EXAMPLE_RESPONSE_JSON, adapter)!!
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `check structure - ok - example response files exist`() {
|
|
||||||
val file = File(EXAMPLE_RESPONSE_JSON)
|
|
||||||
assertTrue(file.exists())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains meta`() {
|
fun `check structure - ok - contains meta`() {
|
||||||
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
assertEquals("OK", response.ocs.meta.message!!)
|
assertEquals("OK", response.ocs.meta.message!!)
|
||||||
assertEquals(200, response.ocs.meta.statusCode!!)
|
assertEquals(200, response.ocs.meta.statusCode)
|
||||||
assertEquals("ok", response.ocs.meta.status!!)
|
assertEquals("ok", response.ocs.meta.status)
|
||||||
assertTrue(response.ocs.meta.itemsPerPage?.isEmpty()!!)
|
assertTrue(response.ocs.meta.itemsPerPage?.isEmpty()!!)
|
||||||
assertTrue(response.ocs.meta.totalItems?.isEmpty()!!)
|
assertTrue(response.ocs.meta.totalItems?.isEmpty()!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains exact`() {
|
fun `check structure - ok - contains exact`() {
|
||||||
assertNotEquals(null, response.ocs.data.exact)
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
|
assertNotNull(response.ocs.data.exact)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains groups`() {
|
fun `check structure - ok - contains groups`() {
|
||||||
assertNotEquals(null, response.ocs.data.groups)
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
|
assertNotNull(response.ocs.data.groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains remotes`() {
|
fun `check structure - ok - contains remotes`() {
|
||||||
assertNotEquals(null, response.ocs.data.remotes)
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
|
assertNotNull(response.ocs.data.remotes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - contains users`() {
|
fun `check structure - ok - contains users`() {
|
||||||
assertNotEquals(null, response.ocs.data.users)
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
|
assertNotNull(response.ocs.data.users)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - groups contains two items`() {
|
fun `check structure - ok - groups contains two items`() {
|
||||||
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
assertEquals(2, response.ocs.data.groups.size)
|
assertEquals(2, response.ocs.data.groups.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - users contains two items`() {
|
fun `check structure - ok - users contains two items`() {
|
||||||
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
assertEquals(2, response.ocs.data.users.size)
|
assertEquals(2, response.ocs.data.users.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - exact_users contains one item`() {
|
fun `check structure - ok - exact_users contains one item`() {
|
||||||
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
assertEquals(1, response.ocs.data.exact?.users?.size)
|
assertEquals(1, response.ocs.data.exact?.users?.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - user1 contains additional data`() {
|
fun `check structure - ok - user1 contains additional data`() {
|
||||||
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
assertEquals("user1@user1.com", response.ocs.data.users.get(0).value.additionalInfo)
|
assertEquals("user1@user1.com", response.ocs.data.users.get(0).value.additionalInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check structure - ok - user2 does not contain additional data`() {
|
fun `check structure - ok - user2 does not contain additional data`() {
|
||||||
assertEquals(null, response.ocs.data.users[1].value.additionalInfo)
|
val response = loadResponses(EXAMPLE_RESPONSE_JSON)!!
|
||||||
|
assertNull(response.ocs.data.users[1].value.additionalInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check empty response - ok - parsing ok`() {
|
fun `check empty response - ok - parsing ok`() {
|
||||||
val moshi = Moshi.Builder().build()
|
val response = loadResponses(EMPTY_RESPONSE_JSON)!!
|
||||||
val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareeOcsResponse::class.java)
|
assertTrue(response.ocs.data.exact?.groups?.isEmpty()!!)
|
||||||
val adapter: JsonAdapter<CommonOcsResponse<ShareeOcsResponse>> = moshi.adapter(type)
|
assertTrue(response.ocs.data.exact?.remotes?.isEmpty()!!)
|
||||||
loadResponses(EMPTY_RESPONSE_JSON, adapter)!!
|
assertTrue(response.ocs.data.exact?.users?.isEmpty()!!)
|
||||||
|
assertTrue(response.ocs.data.groups.isEmpty())
|
||||||
|
assertTrue(response.ocs.data.remotes.isEmpty())
|
||||||
|
assertTrue(response.ocs.data.users.isEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user