From 478e09c5963891e48cf3f58546a32d04baf9fc68 Mon Sep 17 00:00:00 2001 From: Luis Gustavo Date: Sat, 9 Jun 2018 23:25:27 -0300 Subject: [PATCH] Added example with json test --- project/app/build.gradle | 3 +++ .../nexte/LikeListScene/LikeListWorkerTest.kt | 27 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/project/app/build.gradle b/project/app/build.gradle index afa19ef7..a03ad4a9 100644 --- a/project/app/build.gradle +++ b/project/app/build.gradle @@ -134,6 +134,9 @@ dependencies { // It makes the ImageViews rounded implementation 'de.hdodenhof:circleimageview:2.2.0' + + // Json + testImplementation 'org.json:json:20180130' } diff --git a/project/app/src/test/java/com/nexte/nexte/LikeListScene/LikeListWorkerTest.kt b/project/app/src/test/java/com/nexte/nexte/LikeListScene/LikeListWorkerTest.kt index 87a8bba0..3ceeb5f1 100644 --- a/project/app/src/test/java/com/nexte/nexte/LikeListScene/LikeListWorkerTest.kt +++ b/project/app/src/test/java/com/nexte/nexte/LikeListScene/LikeListWorkerTest.kt @@ -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 @@ -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