Skip to content

Commit

Permalink
Add test without names property
Browse files Browse the repository at this point in the history
  • Loading branch information
philipbrito committed May 1, 2019
1 parent 4f3a062 commit 83d9c62
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.mockito.MockitoAnnotations
import org.hamcrest.CoreMatchers.`is` as isEqualTo

const val REACTIONS_JSON_PAYLOAD = "{\"reactions\":{\":croissant:\":{\"usernames\":[\"test.user\",\"test.user2\"],\"names\":[\"Test User\",\"Test User 2\"]}, \":thumbsup:\":{\"usernames\":[\"test.user\",\"test.user2\"],\"names\":[\"Test User\",\"Test User 2\"]}}}"
//const val REACTIONS_JSON_PAYLOAD = "{\"reactions\":{\":croissant:\":{\"usernames\":[\"test.user\",\"test.user2\"],\"names\":[\"Test User\",\"Test User 2\"]}}}"
const val REACTIONS_JSON_PAYLOAD_WITHOUT_NAME = "{\"reactions\":{\":croissant:\":{\"usernames\":[\"test.user\",\"test.user2\"]}, \":thumbsup:\":{\"usernames\":[\"test.user\",\"test.user2\"]}}}"

const val REACTIONS_EMPTY_JSON_PAYLOAD = "[]"

Expand Down Expand Up @@ -42,7 +42,7 @@ class ReactionsAdapterTest {
}

@Test
fun `should deserialize JSON with reactions`() {
fun `should deserialize JSON with reactions (with names)`() {
val adapter = moshi.adapter<Reactions>(Reactions::class.java)
adapter.fromJson(REACTIONS_JSON_PAYLOAD)?.let { reactions ->
assertThat(reactions.size, isEqualTo(2))
Expand All @@ -53,6 +53,17 @@ class ReactionsAdapterTest {
}
}

@Test
fun `should deserialize JSON with reactions (without names)`() {
val adapter = moshi.adapter<Reactions>(Reactions::class.java)
adapter.fromJson(REACTIONS_JSON_PAYLOAD_WITHOUT_NAME)?.let { reactions ->
assertThat(reactions.size, isEqualTo(2))
assertThat(reactions[":croissant:"]?.first?.size, isEqualTo(2))
assertThat(reactions[":croissant:"]?.second?.size, isEqualTo(0))
assertThat(reactions[":croissant:"]?.first?.get(0), isEqualTo("test.user"))
}
}

@Test
fun `should deserialize empty reactions JSON`() {
val adapter = moshi.adapter<Reactions>(Reactions::class.java)
Expand Down

0 comments on commit 83d9c62

Please sign in to comment.