### Question:
MapHttp4xxCodesToExceptions implements Fallback<Object> { @Override public Object createOrPropagate(Throwable t) throws Exception { propagateIfRetryAfter.createOrPropagate(t); if (t instanceof HttpResponseException) { HttpResponseException responseException = HttpResponseException.class.cast(t); if (responseException.getResponse() != null) switch (responseException.getResponse().getStatusCode()) { case 401: throw new AuthorizationException(responseException); case 403: throw new AuthorizationException(responseException); case 404: throw new ResourceNotFoundException(responseException); case 409: throw new IllegalStateException(responseException); } } throw propagate(t); } @Inject  MapHttp4xxCodesToExceptions(PropagateIfRetryAfter propagateIfRetryAfter); @Override Object createOrPropagate(Throwable t);  }### Answer:
@Test(expectedExceptions = AuthorizationException.class) public void test401ToAuthorizationException() throws Exception { fn.createOrPropagate(new HttpResponseException(command, HttpResponse.builder().statusCode(401).build())); }
@Test(expectedExceptions = AuthorizationException.class) public void test403ToAuthorizationException() throws Exception { fn.createOrPropagate(new HttpResponseException(command, HttpResponse.builder().statusCode(403).build())); }
@Test(expectedExceptions = ResourceNotFoundException.class) public void test404ToResourceNotFoundException() throws Exception { fn.createOrPropagate(new HttpResponseException(command, HttpResponse.builder().statusCode(404).build())); }
@Test(expectedExceptions = IllegalStateException.class) public void test409ToIllegalStateException() throws Exception { fn.createOrPropagate(new HttpResponseException(command, HttpResponse.builder().statusCode(409).build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry now") public void testHttpResponseExceptionWithRetryAfterDate() throws Exception { fn.createOrPropagate(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Fri, 31 Dec 1999 23:59:59 GMT").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 700 seconds") public void testHttpResponseExceptionWithRetryAfterOffset() throws Exception { fn.createOrPropagate(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "700").build())); }
@Test(expectedExceptions = RetryAfterException.class, expectedExceptionsMessageRegExp = "retry in 86400 seconds") public void testHttpResponseExceptionWithRetryAfterPastIsZero() throws Exception { fn.createOrPropagate(new HttpResponseException(command, HttpResponse.builder() .statusCode(503) .addHeader(HttpHeaders.RETRY_AFTER, "Sun, 2 Jan 2000 00:00:00 GMT").build())); }