HeaderUtils { public static Integer extractIntegerHeader(Map<String, String> headers, ResponseHeader responseHeader) { return formatIntHeader(extractHeader(headers, responseHeader)); }  @Nullable static String extractHeader(Map<String, String> headers, ResponseHeader responseHeader); static Integer extractIntegerHeader(Map<String, String> headers, ResponseHeader responseHeader); static boolean extractBooleanHeader(Map<String, String> headers, ResponseHeader responseHeader, boolean defaultValue); static String extractHeader(HttpResponse response, ResponseHeader responseHeader); static boolean extractBooleanHeader(HttpResponse response, ResponseHeader responseHeader, boolean defaultValue); static Integer extractIntegerHeader(HttpResponse response, ResponseHeader responseHeader); static int extractIntHeader(HttpResponse response, ResponseHeader responseHeader, int defaultValue);  }
@Test public void extractIntegerHeader_shouldReturnIntegerValue() throws Exception { response.addHeader(AD_TIMEOUT.getKey(), "10"); assertThat(HeaderUtils.extractIntegerHeader(response, AD_TIMEOUT)).isEqualTo(10); response.addHeader(AD_TIMEOUT.getKey(), "0"); assertThat(HeaderUtils.extractIntegerHeader(response, AD_TIMEOUT)).isEqualTo(0); response.addHeader(AD_TIMEOUT.getKey(), "-2"); assertThat(HeaderUtils.extractIntegerHeader(response, AD_TIMEOUT)).isEqualTo(-2); }
@Test public void extractIntegerHeader_withDoubleValue_shouldTruncateValue() throws Exception { response.addHeader(AD_TIMEOUT.getKey(), "3.14"); assertThat(HeaderUtils.extractIntegerHeader(response, AD_TIMEOUT)).isEqualTo(3); response.addHeader(AD_TIMEOUT.getKey(), "-3.14"); assertThat(HeaderUtils.extractIntegerHeader(response, AD_TIMEOUT)).isEqualTo(-3); }
@Test public void extractIntegerHeader_whenNoHeaderPresent_shouldReturnNull() throws Exception { assertThat(HeaderUtils.extractIntegerHeader(response, AD_TIMEOUT)).isNull(); response.addHeader(AD_TIMEOUT.getKey(), null); assertThat(HeaderUtils.extractIntegerHeader(response, AD_TIMEOUT)).isNull(); }
@Test public void extractIntegerHeader_withNonsenseStringValue_shouldReturnNull() throws Exception { response.addHeader(AD_TIMEOUT.getKey(), "llama!!guy"); assertThat(HeaderUtils.extractIntegerHeader(response, AD_TIMEOUT)).isNull(); }