Created
December 18, 2017 00:03
-
-
Save ShaishavGandhi/c442c3706a2d9d115120f6ffd252f21e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 testBlogsReturnsError() { | |
val testObserver = TestObserver<List<Blog>>() | |
val path = "/blogs" | |
// Mock a response with status 200 and sample JSON output | |
val mockReponse = MockReponse() | |
.setResponseCode(500) // Simulate a 500 HTTP Code | |
// Enqueue request | |
mockServer.enqueue(mockResponse) | |
// Call the API | |
blogRepository.blogs().subscribe(testObserver) | |
testObserver.awaitTerminalEvent(2, TimeUnit.SECONDS) | |
// No values | |
testObserver.assertNoValues() | |
// One error recorded | |
assertEquals(1, testObserver.errorCount()) | |
// 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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment