SimpleTokenManager implements TokenManager { @Override public String getTokenString(ContainerRequestContext requestContext) { javax.ws.rs.core.Cookie cookie = requestContext.getCookies().get(TOKEN_NAME); if (cookie == null) { LOG.debug("Mobi web token cookie not found."); return null; } else { return cookie.getValue(); } }  @Activate void start(Map<String, Object> props); @Modified void modified(Map<String, Object> props); @Override Optional<SignedJWT> verifyToken(String tokenString); @Override SignedJWT generateUnauthToken(); @Override SignedJWT generateAuthToken(String username); @Override String getTokenString(ContainerRequestContext requestContext); @Override String getTokenString(HttpServletRequest servletRequest); @Override Cookie createSecureTokenCookie(SignedJWT token); @Override NewCookie createSecureTokenNewCookie(SignedJWT token);  }
@Test public void getTokenStringContextTest() { String result = manager.getTokenString(requestContext); assertEquals(MOBI_TOKEN, result); verify(requestContext).getCookies(); }
@Test public void getTokenStringContextNoCookieTest() { when(requestContext.getCookies()).thenReturn(new HashMap<>()); String result = manager.getTokenString(requestContext); assertNull(result); verify(requestContext).getCookies(); }
@Test public void getTokenStringRequestTest() { String result = manager.getTokenString(servletRequest); assertEquals(MOBI_TOKEN, result); verify(servletRequest).getCookies(); }
@Test public void getTokenStringRequestNoCookieTest() { when(servletRequest.getCookies()).thenReturn(new Cookie[] {}); String result = manager.getTokenString(servletRequest); assertNull(result); verify(servletRequest).getCookies(); }