Last active
July 27, 2019 10:07
-
-
Save Audhil/eab6abe946e83be670f0eb5123de5888 to your computer and use it in GitHub Desktop.
ResponseDispatcher - https://android.jlelse.eu/instrumentation-testing-with-dagger2-retrofit2-mockwebserver-android-4cca7cb7373c
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
class MockServerDispatcher { | |
// response dispatcher | |
class ResponseDispatcher : Dispatcher() { | |
override fun dispatch(request: RecordedRequest): MockResponse { | |
if (request.path.equals("/todos/1", true)) | |
return MockResponse().setResponseCode(200).setBody( | |
"{\n" + | |
" \"id\" : 1,\n" + | |
" \"title\" : \"delectus aut autem\",\n" + | |
" \"userId\" : 1,\n" + | |
" \"completed\" : false\n" + | |
"}" | |
) | |
return MockResponse().setResponseCode(400) | |
} | |
} | |
// error dispatcher | |
class ErrorDispatcher : Dispatcher() { | |
override fun dispatch(request: RecordedRequest): MockResponse = MockResponse().setResponseCode(400) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment