@Test
public void testDoFilterFailure() throws Exception {

  AmbariEntryPoint entryPoint = createMock(AmbariEntryPoint.class);
  JwtAuthenticationProperties properties = createMock(JwtAuthenticationProperties.class);
  expect(properties.getAuthenticationProviderUrl()).andReturn("some url").once();
  expect(properties.getPublicKey()).andReturn(publicKey).once();
  expect(properties.getAudiences()).andReturn(Collections.singletonList("foobar")).once();
  expect(properties.getCookieName()).andReturn("chocolate chip").once();
  expect(properties.getOriginalUrlQueryParam()).andReturn("question").once();
  Configuration configuration = createMock(Configuration.class);
  expect(configuration.getJwtProperties()).andReturn(properties).once();
  Users users = createMock(Users.class);
  AuditLogger auditLogger = createMock(AuditLogger.class);
  expect(auditLogger.isEnabled()).andReturn(false).times(2);
  PermissionHelper permissionHelper = createMock(PermissionHelper.class);
  Cookie cookie = createMock(Cookie.class);
  expect(cookie.getName()).andReturn("chocolate chip").once();
  expect(cookie.getValue()).andReturn("invalid token").once();
  HttpServletRequest servletRequest = createMock(HttpServletRequest.class);
  expect(servletRequest.getCookies()).andReturn(new Cookie[]{cookie}).once();
  HttpServletResponse servletResponse = createMock(HttpServletResponse.class);
  FilterChain filterChain = createMock(FilterChain.class);
  filterChain.doFilter(servletRequest, servletResponse);
  expectLastCall().once();
  replayAll();
  AmbariJWTAuthenticationFilter filter = new AmbariJWTAuthenticationFilter(entryPoint, configuration, users, auditLogger, permissionHelper);
  filter.doFilter(servletRequest, servletResponse, filterChain);
  verifyAll();
}