UserController { @RequestMapping(value = "check", method = RequestMethod.GET) public LoginResponse check(final HttpServletResponse response) { if (JwtFilter.SUBJECT_ANONYMOUS.equals(response.getHeader(JwtFilter.HEADER_CLAIMS_SUBJECT))) { return new LoginResponse(JwtFilter.ANONYMOUS_USER_ID, response.getHeader(JwtFilter.HEADER_CLAIMS_SUBJECT), authenticationService.anonymousToken()); } return new LoginResponse(response.getHeader(JwtFilter.HEADER_CLAIMS_USER_ID), response.getHeader(JwtFilter.HEADER_CLAIMS_SUBJECT), response.getHeader(JwtFilter.JWT_TOKEN)); } @Autowired  UserController(final UserService userService, final AuthenticationService authenticationService); @RequestMapping(value = "login", method = RequestMethod.POST) LoginResponse login(@NonNull @RequestBody final LoginRequest login); @RequestMapping(value = "check", method = RequestMethod.GET) LoginResponse check(final HttpServletResponse response); @RequestMapping(value = "role/{role}", method = RequestMethod.GET) Boolean claimContainsRole(@PathVariable final String role,
        final HttpServletRequest request);  }
@Test public void testCheckAnonymousHeader() { Mockito.when(mockHttpServletResponse.getHeader(JwtFilter.HEADER_CLAIMS_SUBJECT)) .thenReturn(JwtFilter.SUBJECT_ANONYMOUS); final LoginResponse loginResponse = userController.check(mockHttpServletResponse); assertNotNull(loginResponse); Mockito.verify(mockHttpServletResponse, Mockito.times(2)).getHeader(JwtFilter.HEADER_CLAIMS_SUBJECT); Mockito.verify(mockAuthenticationService).anonymousToken(); }
@Test public void testCheckNotAnonymousHeader() { Mockito.when(mockHttpServletResponse.getHeader(JwtFilter.HEADER_CLAIMS_SUBJECT)).thenReturn("not anonymous"); Mockito.when(mockHttpServletResponse.getHeader(JwtFilter.JWT_TOKEN)).thenReturn("token"); final LoginResponse loginResponse = userController.check(mockHttpServletResponse); assertNotNull(loginResponse); Mockito.verify(mockHttpServletResponse, Mockito.times(2)).getHeader(JwtFilter.HEADER_CLAIMS_SUBJECT); Mockito.verify(mockHttpServletResponse).getHeader(JwtFilter.JWT_TOKEN); }