Last active
June 28, 2018 02:20
-
-
Save brianPlummer/4596451941684a8c07d9d73bbf2933f8 to your computer and use it in GitHub Desktop.
Loading a json file from an Android unit test
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
@Test | |
fun loadData () { | |
val moshi = Moshi.Builder().build() | |
val listType = Types.newParameterizedType(List::class.java, Complaint::class.java) | |
val source = Okio.buffer(Okio.source(inputStream("/gov_complaints.json"))) | |
val complaints = moshi.adapter<List<Complaint>>(listType).fromJson(source) | |
Assert.assertNotNull(complaints) | |
Assert.assertEquals(complaints!!.isEmpty(), false) | |
} | |
private fun inputStream(path: String): InputStream { | |
return ComplaintsTest::class.java!!.getResourceAsStream(path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment