ThrowError implements ResponseFeature { public Response process(ResponseChain responseChain, Response response) { int code = response.getCode(); if (code >= 100 && code <= 299) { return responseChain.next(response); } if (code >= 300 && code <= 399) { throw new RedicetionException("Http error " + code + " when executing request"); } if (code == 400) { throw new BadRequestException("Http error " + code + " when executing request"); } if (code == 401) { throw new UnauthorizedException("Http error " + code + " when executing request"); } if (code == 403) { throw new ForbiddenException("Http error " + code + " when executing request"); } if (code == 404) { throw new NotFoundException("Http error " + code + " when executing request"); } if (code == 405) { throw new MethodNotAllowedException("Http error " + code + " when executing request"); } if (code == 407) { throw new ProxyAuthenticationRequiredException("Http error " + code + " when executing request"); } if (code == 409) { throw new ConflictException("Http error " + code + " when executing request"); } if (code == 410) { throw new GoneException("Http error " + code + " when executing request"); } if (code == 412) { throw new PreconditionFailedException("Http error " + code + " when executing request"); } if (code == 402 || code == 406 || code == 408 || code == 411 || (code >= 413 && code <= 499)) { throw new ClientException("Http error " + code + " when executing request"); } if (code == 501) { throw new NotImplementedException("Http error " + code + " when executing request"); } if (code == 500 || (code >= 502 && code <= 599)) { throw new ServerException("Http error " + code + " when executing request"); } throw new UnknowCodeException("http erro"); }  Response process(ResponseChain responseChain, Response response);  }
@Test public void shouldNotThrowExceptionWhenCode100() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(100); new ThrowError().process(chain, response); verify(chain).next(response); }
@Test public void shouldNotThrowExceptionWhenCode200() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(200); new ThrowError().process(chain, response); verify(chain).next(response); }
@Test public void shouldNotThrowExceptionWhenCode299() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(299); new ThrowError().process(chain, response); verify(chain).next(response); }
@Test(expected=RedicetionException.class) public void shouldThrowRedirectionExceptionWhenCode300() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(300); new ThrowError().process(chain, response); }
@Test(expected=RedicetionException.class) public void shouldThrowRedirectionExceptionWhenCode350() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(350); new ThrowError().process(chain, response); }
@Test(expected=RedicetionException.class) public void shouldThrowRedirectionExceptionWhenCode399() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(399); new ThrowError().process(chain, response); }
@Test(expected=BadRequestException.class) public void shouldThrowBadRequestWhenCode400() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(400); new ThrowError().process(chain, response); }
@Test(expected=UnauthorizedException.class) public void shouldThrowUnauthorizedExceptionWhenCode401() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(401); new ThrowError().process(chain, response); }
@Test(expected=ForbiddenException.class) public void shouldThrowForbiddenExceptionWhenCode403() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(403); new ThrowError().process(chain, response); }
@Test(expected=NotFoundException.class) public void shouldThrowNotFoundExceptionWhenCode404() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(404); new ThrowError().process(chain, response); }
@Test(expected=MethodNotAllowedException.class) public void shouldThrowMethodNotAllowedExceptionWhenCode405() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(405); new ThrowError().process(chain, response); }
@Test(expected=ProxyAuthenticationRequiredException.class) public void shouldThrowProxyAuthenticationRequiredExceptionWhenCode407() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(407); new ThrowError().process(chain, response); }
@Test(expected=ConflictException.class) public void shouldThrowConflictExceptionWhenCode409() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(409); new ThrowError().process(chain, response); }
@Test(expected=GoneException.class) public void shouldThrowGoneExceptionWhenCode410() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(410); new ThrowError().process(chain, response); }
@Test(expected=PreconditionFailedException.class) public void shouldThrowPreconditionFailedExceptionWhenCode412() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(412); new ThrowError().process(chain, response); }
@Test(expected=ClientException.class) public void shouldThrowClientExceptionWhenCode402() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(402); new ThrowError().process(chain, response); }
@Test(expected=ClientException.class) public void shouldThrowClientExceptionWhenCode406() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(406); new ThrowError().process(chain, response); }
@Test(expected=ClientException.class) public void shouldThrowClientExceptionWhenCode408() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(408); new ThrowError().process(chain, response); }
@Test(expected=ClientException.class) public void shouldThrowClientExceptionWhenCode411() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(411); new ThrowError().process(chain, response); }
@Test(expected=ClientException.class) public void shouldThrowClientExceptionWhenCode413() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(413); new ThrowError().process(chain, response); }
@Test(expected=ClientException.class) public void shouldThrowClientExceptionWhenCode450() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(450); new ThrowError().process(chain, response); }
@Test(expected=ClientException.class) public void shouldThrowClientExceptionWhenCode499() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(499); new ThrowError().process(chain, response); }
@Test(expected=NotImplementedException.class) public void shouldThrowNotImplementedExceptionWhenCode501() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(501); new ThrowError().process(chain, response); }
@Test(expected=ServerException.class) public void shouldThrowServerExceptionWhenCode500() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(500); new ThrowError().process(chain, response); }
@Test(expected=ServerException.class) public void shouldThrowServerExceptionWhenCode502() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(502); new ThrowError().process(chain, response); }
@Test(expected=ServerException.class) public void shouldThrowServerExceptionWhenCode550() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(550); new ThrowError().process(chain, response); }
@Test(expected=ServerException.class) public void shouldThrowServerExceptionWhenCode599() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(599); new ThrowError().process(chain, response); }
@Test(expected=UnknowCodeException.class) public void shouldThrowUnkownCodeExceptionWhenUnknonwCode() { when(request.get()).thenReturn(response); when(response.getCode()).thenReturn(600); new ThrowError().process(chain, response); }