Skip to content

Instantly share code, notes, and snippets.

@dhiraj
Last active August 9, 2018 11:37
Show Gist options
  • Save dhiraj/1958edf1beb4d3f9be7cd5d359287c16 to your computer and use it in GitHub Desktop.
Save dhiraj/1958edf1beb4d3f9be7cd5d359287c16 to your computer and use it in GitHub Desktop.
@Test
fun getTodos(){
OkHttpClient().newCall(Request.Builder().url("https://jsonplaceholder.typicode.com/todos").build()).enqueue(object : Callback {
override fun onFailure(call: Call?, e: IOException?) {} //Handle Network failure
override fun onResponse(call: Call?, response: Response?) {
response!!.body()!!.use {responsebody ->
val root = JsonParser().parse(responsebody.charStream())
assertTrue(root is JsonElement) //root is a JsonElement object
assertTrue(root is JsonArray) //root is actually, a JsonArray object
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment