HttpHeaderUtilities { public static String getHeaderValue(HttpServletRequest httpRequest, HttpHeader header) { return getHeaderValue(httpRequest, header, null); } private  HttpHeaderUtilities(); static String getHeaderValue(HttpServletRequest httpRequest, HttpHeader header); static String getHeaderValue(HttpServletRequest httpRequest, HttpHeader header, String defaultValue); static String getHeaderValue(HttpServletResponse httpResponse, HttpHeader header); static String getHeaderValue(HttpServletResponse httpResponse, HttpHeader header, String defaultValue);  }
@Test public void readsHeaderFromRequest() throws Exception { when(request.getHeader("test_header")).thenReturn("test_value"); String value = HttpHeaderUtilities.getHeaderValue(request, header); assertThat(value, is("test_value")); }
@Test public void readsHeaderFromResponse() throws Exception { when(response.getHeader("test_header")).thenReturn("test_value"); String value = HttpHeaderUtilities.getHeaderValue(response, header); assertThat(value, is("test_value")); }
@Test public void returnsDefaultOnMissingRequestHeader() throws Exception { String value = HttpHeaderUtilities.getHeaderValue(request, header, "default_value"); assertThat(value, is("default_value")); }
@Test public void returnsDefaultOnMissingResponseHeader() throws Exception { String value = HttpHeaderUtilities.getHeaderValue(response, header, "default_value"); assertThat(value, is("default_value")); }
@Test public void usesAliasOnMissingRequestHeader() throws Exception { HttpHeader alias = Mockito.mock(HttpHeader.class); when(alias.getName()).thenReturn("test_alias"); when(header.getAliases()).thenReturn(Arrays.asList(alias)); when(request.getHeader("test_alias")).thenReturn("test_value"); String value = HttpHeaderUtilities.getHeaderValue(request, header); assertThat(value, is("test_value")); }
@Test public void usesAliasOnMissingResponseHeader() throws Exception { HttpHeader alias = Mockito.mock(HttpHeader.class); when(alias.getName()).thenReturn("test_alias"); when(header.getAliases()).thenReturn(Arrays.asList(alias)); when(response.getHeader("test_alias")).thenReturn("test_value"); String value = HttpHeaderUtilities.getHeaderValue(response, header); assertThat(value, is("test_value")); }
@Test public void ignoresUnknownAliasOnMissingRequestHeader() throws Exception { HttpHeader alias = Mockito.mock(HttpHeader.class); when(alias.getName()).thenReturn("test_alias"); when(header.getAliases()).thenReturn(Arrays.asList(alias)); String value = HttpHeaderUtilities.getHeaderValue(request, header, "default_value"); assertThat(value, is("default_value")); }
@Test public void ignoresUnknownAliasOnMissingResponseHeader() throws Exception { HttpHeader alias = Mockito.mock(HttpHeader.class); when(alias.getName()).thenReturn("test_alias"); when(header.getAliases()).thenReturn(Arrays.asList(alias)); String value = HttpHeaderUtilities.getHeaderValue(response, header, "default_value"); assertThat(value, is("default_value")); }