### Question:
ApimAdapterFilter implements Filter { @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; final HttpServletResponse httpResponse = (HttpServletResponse) servletResponse; final HttpMethod httpMethod = HttpMethod.valueOf(httpRequest.getMethod().toUpperCase()); final String token = AuthUtils.extractJwtFromAuthHeader(httpRequest.getHeader(AuthUtils.HTTP_AUTHORIZATION_HEADER_NAME)); if (apimAdapterService.getApiWatch().isApiWatchRequest(token, httpMethod)) { apimAdapterService.getApiWatch().writeResponse(httpResponse); } else if (excludeFilterMethods.contains(httpMethod)) { filterChain.doFilter(servletRequest, httpResponse); } else { applyApimFilter(httpRequest, httpMethod, httpResponse, token, filterChain); } } ApimAdapterFilter(ApimAdapterService threeScaleAdapterService, List<HttpMethod> excludeFilterMethods); @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain); @Override void destroy();  }### Answer:
@Test public void testFilterSuccess() throws IOException, ServletException { mockHttpServletRequest.setRequestURI(V1_LOCATIONS); mockHttpServletRequest.setMethod(HttpMethod.GET.toString()); String token = TokenGenerator.getInstance().generateBearerToken(CLIENT_ID, 30_000); mockHttpServletRequest.addHeader(HTTP_AUTHORIZATION_HEADER_NAME, mapJwtToHttpAuthorizationHeaderValue(token)); stubFor(get(patternForAuthorization()) .atPriority(5) .willReturn(aResponse() .withStatus(HttpStatus.SC_OK) .withBody(StubGenerator.authResponseForAnUnlimitedPlan()))); filter.doFilter(mockHttpServletRequest, mockHttpServletResponse, mockFilterChain); assertNotNull(mockHttpServletResponse.getOutputStream()); assertEquals(200, mockHttpServletResponse.getStatus()); assertEquals(null, mockHttpServletResponse.getErrorMessage()); }
@Test public void testFilterFailure() throws IOException, ServletException { mockHttpServletRequest.setRequestURI(V1_LOCATIONS); mockHttpServletRequest.setMethod(HttpMethod.GET.toString()); String token = TokenGenerator.getInstance().generateBearerToken("invalidClientId", 30_000); mockHttpServletRequest.addHeader(HTTP_AUTHORIZATION_HEADER_NAME, mapJwtToHttpAuthorizationHeaderValue(token)); stubFor(get(patternForAuthorization()) .atPriority(5) .willReturn(aResponse() .withStatus(HttpStatus.SC_FORBIDDEN) .withBody(StubGenerator.authResponseForAnInvalidClientId()))); filter.doFilter(mockHttpServletRequest, mockHttpServletResponse, mockFilterChain); assertNotNull(mockHttpServletResponse.getOutputStream()); assertEquals(403, mockHttpServletResponse.getStatus()); assertTrue(mockHttpServletResponse.getErrorMessage().contains("Client has no permission")); }