Package okhttp3.mock
Class MockInterceptor
- java.lang.Object
-
- okhttp3.mock.MockInterceptor
-
- All Implemented Interfaces:
okhttp3.Interceptor
public class MockInterceptor extends java.lang.Object implements okhttp3.InterceptorAnInterceptorforOkHttpClient, which with match request and provide pre-configured mock responses.
-
-
Constructor Summary
Constructors Constructor Description MockInterceptor()Creates a MockInterceptor with a defaultBehavior.SEQUENTIALbehaviorMockInterceptor(Behavior behavior)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Rule.BuilderaddRule()Short hand foraddRule(Response.Builder builder)MockInterceptoraddRule(Rule rule)Adds a new mock rule to this interceptor.MockInterceptoraddRule(okhttp3.Response.Builder builder)Adds a new mock rule to this interceptor.Behaviorbehavior()MockInterceptorbehavior(Behavior behavior)java.util.List<Rule>getRules()okhttp3.Responseintercept(okhttp3.Interceptor.Chain chain)MockInterceptorreset()
-
-
-
Constructor Detail
-
MockInterceptor
public MockInterceptor()
Creates a MockInterceptor with a defaultBehavior.SEQUENTIALbehavior
-
MockInterceptor
public MockInterceptor(Behavior behavior)
-
-
Method Detail
-
getRules
public java.util.List<Rule> getRules()
-
addRule
public MockInterceptor addRule(okhttp3.Response.Builder builder)
Adds a new mock rule to this interceptor. UseRule.Builderto create one and call the final statementsRule.Builder.respond(java.lang.String).Example:
interceptor.addRule(new Rule.Builder() .get() .urlStarts("https://someserver/") .respond(HTTP_200_OK) .header("SomeHeader", "SomeValue"));- Parameters:
builder- the rule to add- Returns:
- this instance
-
addRule
public MockInterceptor addRule(Rule rule)
Adds a new mock rule to this interceptor.- Parameters:
rule- the rule to add- Returns:
- this instance
-
addRule
public Rule.Builder addRule()
Short hand foraddRule(Response.Builder builder)- Returns:
- a rule builder
-
reset
public MockInterceptor reset()
-
behavior
public Behavior behavior()
-
behavior
public MockInterceptor behavior(Behavior behavior)
-
intercept
public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws java.io.IOException- Specified by:
interceptin interfaceokhttp3.Interceptor- Throws:
java.io.IOException
-
-