This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Adopt PublishedApi #36
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6532108
Add PublishedApi to BaseRetrofitHelper
Goooler 8503127
Add JsonUtil to JsonUtil
Goooler b093e57
Add JsonUtilTest
Goooler f998570
Add test cases
Goooler 7e63dbf
Rename
Goooler 4d6b3b1
Replace assert with Assert.assertTrue
Goooler 95b2fbf
Update unit-tests job
Goooler 932972b
kaptTest moshiCompiler
Goooler a55725e
Add @Language annotations
Goooler 5f7e50d
Fix tests
Goooler 47a0b02
Cleanup
Goooler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,6 @@ dependencies { | |
implementations(*Libs.coil) | ||
debugImplementations(Libs.chuckerDebug) | ||
releaseImplementations(Libs.chuckerRelease) | ||
|
||
kaptTests(Libs.moshiCompiler) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
common/src/test/kotlin/io/goooler/demoapp/common/JsonUtilTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package io.goooler.demoapp.common | ||
|
||
import com.squareup.moshi.JsonClass | ||
import io.goooler.demoapp.common.util.JsonUtil | ||
import io.goooler.demoapp.common.util.fromJson | ||
import io.goooler.demoapp.common.util.toJson | ||
import org.intellij.lang.annotations.Language | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class JsonUtilTest { | ||
@Test | ||
fun `JsonUtil fromJson(String)`() { | ||
assertTrue(JsonUtil.fromJson<Repo>(firstStr) == firstBean) | ||
assertTrue(JsonUtil.fromJson<Repo>(secondStr) == secondBean) | ||
} | ||
|
||
@Test | ||
fun `JsonUtil fromJson(String, Class, Class)`() { | ||
val array: Array<Repo> = JsonUtil.fromJson(strArray, Array::class.java, Repo::class.java) | ||
?: throw Exception("Parse json error") | ||
assertTrue(array.first() == firstBean) | ||
assertTrue(array[1] == secondBean) | ||
} | ||
|
||
@Test | ||
fun `JsonUtil toJson(T)`() { | ||
assertTrue(JsonUtil.toJson(firstBean) == firstStr) | ||
assertTrue(JsonUtil.toJson(secondBean) == secondStr) | ||
} | ||
|
||
@Test | ||
fun `String fromJson()`() { | ||
assertTrue(firstStr.fromJson<Repo>() == firstBean) | ||
assertTrue(secondStr.fromJson<Repo>() == secondBean) | ||
} | ||
|
||
@Test | ||
fun `String fromJson(Class, Class)`() { | ||
val array: Array<Repo> = strArray.fromJson(Array::class.java, Repo::class.java) | ||
?: throw Exception("Parse json error") | ||
assertTrue(array.first() == firstBean) | ||
assertTrue(array[1] == secondBean) | ||
} | ||
|
||
@Test | ||
fun `Any? toJson(T)`() { | ||
assertTrue(firstBean.toJson() == firstStr) | ||
assertTrue(secondBean.toJson() == secondStr) | ||
} | ||
|
||
@JsonClass(generateAdapter = true) | ||
internal data class Repo(val id: Long, val name: String, val owner: Owner) { | ||
@JsonClass(generateAdapter = true) | ||
data class Owner(val login: String) | ||
|
||
override fun equals(other: Any?): Boolean = if (other is Repo) { | ||
this.id == other.id && this.name == other.name && this.owner.login == other.owner.login | ||
} else { | ||
false | ||
} | ||
|
||
override fun hashCode(): Int = id.hashCode() | ||
} | ||
|
||
companion object { | ||
@Language("JSON") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
private val firstStr = """ | ||
{ | ||
"id": 126987864, | ||
"name": "1024_hosts", | ||
"owner": { | ||
"login": "Goooler" | ||
} | ||
} | ||
""".trimIndent() | ||
|
||
@Language("JSON") | ||
private val secondStr = """ | ||
{ | ||
"id": 374913489, | ||
"name": "AndroidUiDemo", | ||
"owner": { | ||
"login": "Goooler" | ||
} | ||
} | ||
""".trimIndent() | ||
|
||
// https://api.github.com/users/goooler/repos?&page=1&per_page=2 | ||
@Language("JSON") | ||
private val strArray = "[$firstStr,$secondStr]" | ||
|
||
private val firstBean = Repo(126987864, "1024_hosts", Repo.Owner("Goooler")) | ||
private val secondBean = Repo(374913489, "AndroidUiDemo", Repo.Owner("Goooler")) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.