GuestAuthNetworkInterceptor implements Interceptor { @Override public Response intercept(Chain chain) throws IOException { Response response = chain.proceed(chain.request()); if (response.code() == 403) { response = response.newBuilder().code(401).message("Unauthorized").build(); } return response; }  @Override Response intercept(Chain chain);  }
@Test public void testIntercept_with403() throws Exception { final Response response = new Response.Builder() .protocol(Protocol.HTTP_1_1) .request(request) .code(403) .message("Forbidden") .build(); when(mockChain.request()).thenReturn(request); when(mockChain.proceed(request)).thenReturn(response); final Response modifiedResponse = interceptor.intercept(mockChain); assertFalse(response == modifiedResponse); assertEquals(401, modifiedResponse.code()); }
@Test public void testIntercept_with400() throws Exception { final Response response = new Response.Builder() .protocol(Protocol.HTTP_1_1) .request(request) .message("Bad Request") .code(400) .build(); when(mockChain.request()).thenReturn(request); when(mockChain.proceed(request)).thenReturn(response); final Response unmodifiedResponse = interceptor.intercept(mockChain); assertTrue(response == unmodifiedResponse); assertEquals(400, unmodifiedResponse.code()); }