Skip to content

Instantly share code, notes, and snippets.

@murattuzel
Created November 6, 2021 19:21
Show Gist options
  • Save murattuzel/d5448e5c383e007c23192be575e74ebb to your computer and use it in GitHub Desktop.
Save murattuzel/d5448e5c383e007c23192be575e74ebb to your computer and use it in GitHub Desktop.
Mock interceptor reads local json file and returns the file as a response.
class MockRequestInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
return with(chain.request()) {
when (val mockRequestType = findMockTag()) {
is MockRequestType -> createLocalResponse(
request = this,
filePath = mockRequestType.filePath
)
else -> chain.proceed(this)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment