Skip to content

Instantly share code, notes, and snippets.

@ShaishavGandhi
Created December 17, 2017 23:48
Show Gist options
  • Save ShaishavGandhi/ea8f236ed8c19cca8280dfe6d770ce6a to your computer and use it in GitHub Desktop.
Save ShaishavGandhi/ea8f236ed8c19cca8280dfe6d770ce6a to your computer and use it in GitHub Desktop.
@Test fun testBlogsReturnsListOfBlogs() {
val testObserver = TestObserver<List<Blog>>()
val path = "/blogs"
// Mock a response with status 200 and sample JSON output
val mockReponse = MockReponse()
.setResponseCode(200)
.setBody(getJson("json/blog/blogs.json"))
// Enqueue request
mockServer.enqueue(mockResponse)
// Call the API
blogRepository.blogs().subscribe(testObserver)
testObserver.awaitTerminalEvent(2, TimeUnit.SECONDS)
// No errors
testObserver.assertNoErrors()
// One list emitted
testObserver.assertValueCount(1)
// Get the request that was just made
val request = mockServer.takeRequest()
// Make sure we made the request to the required path
assertEquals(path, request.path)
}
@moloccoGymondo
Copy link

val mockReponse = MockReponse() should be => val mockResponse = MockResponse()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment