@@ -0,0 +1,3371 @@
+package util;%0A%0Aimport com.google.gson.JsonObject;%0Aimport okhttp3.*;%0Aimport okio.Buffer;%0Aimport org.junit.Assert;%0A%0Aimport java.io.IOException;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0A/**%0A * Generic interceptor that matches a URL regex, checks request body params, and sends a JSON response.%0A */%0Apublic class GenericInterceptor implements Interceptor %7B%0A    private static final MediaType JSON_MEDIA_TYPE = MediaType.parse(%22application/response%22);%0A%0A    private String urlRegex;%0A    private Map%3CString, String%3E params;%0A    private JsonObject response;%0A%0A    private GenericInterceptor() %7B%0A        this.params = new HashMap%3C%3E();%0A        this.response = new JsonObject();%0A    %7D%0A%0A    private void validateBody(Request request) throws IOException %7B%0A        RequestBody body = request.body();%0A        Assert.assertNotNull(body);%0A        Buffer buffer = new Buffer();%0A        body.writeTo(buffer);%0A        String bodyString = buffer.readUtf8();%0A%0A        for (String key : params.keySet()) %7B%0A            String value = params.get(key);%0A            Assert.assertTrue(%22Missing key: %22 + key, bodyString.contains(%22name=%5C%22%22 + key + %22%5C%22%22));%0A            if (value != null)%0A                Assert.assertTrue(%22Missing key: %22 + value, bodyString.contains(value));%0A        %7D%0A    %7D%0A%0A    @Override%0A    public Response intercept(Chain chain) throws IOException %7B%0A        Request request = chain.request();%0A        String url = request.url().toString();%0A%0A        if (!url.matches(urlRegex))%0A            return chain.proceed(request);%0A%0A        validateBody(request);%0A%0A        ResponseBody body = ResponseBody.create(JSON_MEDIA_TYPE, response.toString());%0A%0A        return new Response.Builder()%0A                .protocol(Protocol.HTTP_1_1)%0A                .request(request)%0A                .code(200)%0A                .message(%22Okay%22)%0A                .body(body)%0A                .build();%0A    %7D%0A%0A    public static class Builder %7B%0A        private GenericInterceptor interceptor = new GenericInterceptor();%0A%0A        public Builder urlRegex(String urlRegex) %7B%0A            interceptor.urlRegex = urlRegex;%0A            return this;%0A        %7D%0A%0A        public Builder addEmptyParam(String... keys) %7B%0A            for (String key : keys)%0A                interceptor.params.put(key, null);%0A            return this;%0A        %7D%0A%0A        public Builder addParam(String key, String value) %7B%0A            interceptor.params.put(key, value);%0A            return this;%0A        %7D%0A%0A        public Builder addEmptyResponse(String... keys) %7B%0A            for (String key : keys)%0A                interceptor.response.addProperty(key, %22test%22);%0A            return this;%0A        %7D%0A%0A        public Builder addEmptyResponseObject(String key, String... objectKeys) %7B%0A            JsonObject object = new JsonObject();%0A            for (String objectKey : objectKeys)%0A                object.addProperty(objectKey, %22test%22);%0A            interceptor.response.add(key, object);%0A            return this;%0A        %7D%0A%0A        public Builder addResponse(String key, Object value) %7B%0A            interceptor.response.addProperty(key, value.toString());%0A            return this;%0A        %7D%0A%0A        public Builder addResponse(String key, JsonObject object) %7B%0A            interceptor.response.add(key, object);%0A            return this;%0A        %7D%0A%0A        public GenericInterceptor build() %7B%0A            return interceptor;%0A        %7D%0A    %7D%0A%7D%0A

Add generic OkHttp Interceptor for tests