### Question:
HeaderToRetryAfterException implements PropagateIfRetryAfter { @Override public Object createOrPropagate(Throwable t) throws Exception { if (!(t instanceof HttpResponseException)) throw propagate(t); HttpResponse response = HttpResponseException.class.cast(t).getResponse(); if (response == null) { return null; } String retryAfter = response.getFirstHeaderOrNull(HttpHeaders.RETRY_AFTER); if (retryAfter != null) { Optional<RetryAfterException> retryException = tryCreateRetryAfterException(t, retryAfter); if (retryException.isPresent()) throw retryException.get(); } return null; } @Inject private  HeaderToRetryAfterException(DateCodecFactory factory); private  HeaderToRetryAfterException(Ticker ticker, DateCodec dateCodec); static HeaderToRetryAfterException create(Ticker ticker, DateCodec dateCodec); @Override Object createOrPropagate(Throwable t); Optional<RetryAfterException> tryCreateRetryAfterException(Throwable in, String retryAfter);  }### Answer:
@Test(expectedExceptions = RuntimeException.class) public void testArbitraryExceptionDoesntConvert() throws Exception { fn.createOrPropagate(new RuntimeException()); }
@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())); }