Creating Interceptor
Once iris mock dependency is configured, you can start creating your custom interceptors.
Creating class¶
Create a new class implementing the Interceptor
interface and annotate it with @IrisMockInterceptor
.
Using irisMock(chain)
, all DSL functions will be available:
@IrisMockInterceptor
class MyFirstInterceptor : Interceptor {
override fun intercept(chain: Chain) = irisMock(chain) {
onGet(endsWith = "/my/endpoint") mockResponse "myCoolJsonResponse"
}
}
That's all
Run your app and you should see the following output on logcat:
IrisMock I Intercepting: [GET] https://myhost.com/my/endpoint
IrisMock I Mocking Response: [GET] https://myhost.com/my/endpoint
You can create as many interceptors as you like. It's a good idea to split them according to
responsibilities/context, like creating LoginInterceptor
, ProfileInterceptor
and so on.
Need more examples? take a look at the app sample
If you configured iris mock for a specific build variant, you need to create the classes according.