### Question:
CORSFilter extends BaseAlwaysPostRequestFilter { @Override protected void doFilter(HttpServletRequest request, HttpServletResponse response) { if(corsConfiguration.isEnabled()) { response.addHeader("Access-Control-Allow-Origin", corsConfiguration.getOrigin()); response.addHeader("Access-Control-Allow-Headers", corsConfiguration.getHeaders()); response.addHeader("Access-Control-Allow-Credentials", corsConfiguration.getCredentials()); response.addHeader("Access-Control-Allow-Methods", corsConfiguration.getMethods()); response.addHeader("Access-Control-Max-Age", corsConfiguration.getMaxAge()); } }    }### Answer:
@Test public void shouldNotAddHeadersWhenNotEnabled() { when(corsConfiguration.isEnabled()).thenReturn(false); corsFilter.doFilter(null, response); verify(response, never()).addHeader(anyString(), anyString()); }
@Test public void shouldAddCORSHeadersWhenEnabled() { when(corsConfiguration.isEnabled()).thenReturn(true); when(corsConfiguration.getOrigin()).thenReturn("origin"); when(corsConfiguration.getHeaders()).thenReturn("headers"); when(corsConfiguration.getCredentials()).thenReturn("credentials"); when(corsConfiguration.getMethods()).thenReturn("methods"); when(corsConfiguration.getMaxAge()).thenReturn("maxAge"); corsFilter.doFilter(null, response); verify(response).addHeader("Access-Control-Allow-Origin", corsConfiguration.getOrigin()); verify(response).addHeader("Access-Control-Allow-Headers", corsConfiguration.getHeaders()); verify(response).addHeader("Access-Control-Allow-Credentials", corsConfiguration.getCredentials()); verify(response).addHeader("Access-Control-Allow-Methods", corsConfiguration.getMethods()); verify(response).addHeader("Access-Control-Max-Age", corsConfiguration.getMaxAge()); }