Source:
public void interceptWithAccessTokenTest() throws IOException, DotSecurityException, DotDataException { loginService = mock(LoginServiceAPI.class); jsonWebTokenService = JsonWebTokenFactory.getInstance().getJsonWebTokenService(); final JsonWebTokenInterceptor jsonWebTokenInterceptor = new JsonWebTokenInterceptor(jsonWebTokenService, null, null, loginService, null); when(loginService.isLoggedIn(request)).thenReturn(false); final User user = APILocator.getUserAPI().loadUserById(userId); final UserToken userToken = new UserToken(jwtId, userId, date, date.getTime(), user.getSkinId()); final String jsonWebToken = jsonWebTokenService.generateUserToken(userToken); when(request.getSession(false)).thenReturn(session); when(session.getAttribute(WebKeys.USER_ID)).thenReturn(null); when(request.isSecure()).thenReturn(true); when(request.getCookies()).thenAnswer(new Answer<Cookie[]>() { @Override public Cookie[] answer(InvocationOnMock invocation) throws Throwable { System.out.println("getting the access token:" + jsonWebToken); return new Cookie[] { new Cookie(CookieKeys.JWT_ACCESS_TOKEN, jsonWebToken) }; } }); when(loginService.doCookieLogin(anyObject(), anyObject(), anyObject())).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { System.out.println("Success calling the do cookie for a valid scenario"); calledDoCookieLogin = true; return true; } }); jsonWebTokenInterceptor.setCompanyLocalManager(companyLocalManager); jsonWebTokenInterceptor.setEncryptor(encryptor); jsonWebTokenInterceptor.setLoginService(loginService); jsonWebTokenInterceptor.setUserAPI(userAPI); jsonWebTokenInterceptor.init(); jsonWebTokenInterceptor.intercept(request, response); jsonWebTokenInterceptor.destroy(); if (!calledDoCookieLogin) { fail("Failed. doCookieLogin must be called on successfully scenario..."); } }

Target:
public void interceptWithAccessTokenTest() throws IOException, DotSecurityException, DotDataException { loginService = mock(LoginServiceAPI.class); jsonWebTokenService = JsonWebTokenFactory.getInstance().getJsonWebTokenService(); final JsonWebTokenInterceptor jsonWebTokenInterceptor = new JsonWebTokenInterceptor(jsonWebTokenService, null, null, loginService, null); when(loginService.isLoggedIn(request)).thenReturn(false); final User user = APILocator.getUserAPI().loadUserById(userId); final String jwtId = user.getRememberMeToken(); final UserToken userToken = new UserToken.Builder().id(jwtId).subject(userId).modificationDate(date) .expiresDate(date.getTime()).build(); final String jsonWebToken = jsonWebTokenService.generateUserToken(userToken); when(request.getSession(false)).thenReturn(session); when(session.getAttribute(WebKeys.USER_ID)).thenReturn(null); when(request.isSecure()).thenReturn(true); when(request.getCookies()).thenAnswer(new Answer<Cookie[]>() { @Override public Cookie[] answer(InvocationOnMock invocation) throws Throwable { System.out.println("getting the access token:" + jsonWebToken); return new Cookie[] { new Cookie(CookieKeys.JWT_ACCESS_TOKEN, jsonWebToken) }; } }); when(loginService.doCookieLogin(anyObject(), anyObject(), anyObject())).thenAnswer(new Answer<Boolean>() { @Override public Boolean answer(InvocationOnMock invocation) throws Throwable { System.out.println("Success calling the do cookie for a valid scenario"); calledDoCookieLogin = true; return true; } }); jsonWebTokenInterceptor.setCompanyLocalManager(companyLocalManager); jsonWebTokenInterceptor.setEncryptor(encryptor); jsonWebTokenInterceptor.setLoginService(loginService); jsonWebTokenInterceptor.setUserAPI(userAPI); jsonWebTokenInterceptor.init(); jsonWebTokenInterceptor.intercept(request, response); jsonWebTokenInterceptor.destroy(); if (!calledDoCookieLogin) { fail("Failed. doCookieLogin must be called on successfully scenario..."); } }