Skip to content

Commit

Permalink
Added example with json test
Browse files Browse the repository at this point in the history
  • Loading branch information
luis-gustavo committed Jun 10, 2018
1 parent c05e5ed commit 478e09c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ dependencies {

// It makes the ImageViews rounded
implementation 'de.hdodenhof:circleimageview:2.2.0'

// Json
testImplementation 'org.json:json:20180130'
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.nexte.nexte.LikeListScene

import com.nexte.nexte.Entities.Like.LikeAdapter
import com.nexte.nexte.Entities.Like.LikeAdapterSpy
import com.nexte.nexte.Entities.Like.LikeManager
import com.nexte.nexte.Entities.Story.StoryAdapterSpy
import com.nexte.nexte.Entities.Story.StoryManager
import com.nexte.nexte.Entities.User.UserAdapterSpy
import com.nexte.nexte.Entities.User.UserManager
import org.json.JSONArray
import org.json.JSONObject
import org.junit.After
import org.junit.Before

Expand Down Expand Up @@ -41,6 +42,30 @@ class LikeListWorkerTest {
assertEquals(this.mock?.response?.players!![0].name, "User test")
}

@Test
fun testJsonConvertJsonToListOfLikes(){
val likeJson = JSONObject()
likeJson.put("date", "2018-01-07T00:00:00.000Z")
likeJson.put("id", "asdasd")
likeJson.put("user", "asdasd")

val likesJsonArray = JSONArray()
likesJsonArray.put(likeJson)

val dataObject = JSONObject()
dataObject.put("likes",likesJsonArray)

val jsonObject = JSONObject()
jsonObject.put("data", dataObject)

println(jsonObject)

val likes = this.worker?.convertJsonToListOfLikes(jsonObject)

assertEquals(likes!![0].id, likeJson["id"] as String)
assertEquals(likes!![0].userId, likeJson["user"] as String)
}

@After
fun tearDown() {
this.worker = null
Expand Down

0 comments on commit 478e09c

Please sign in to comment.