GoogleJwtAuthenticator implements Authenticator { @VisibleForTesting GoogleIdToken verifyToken(String token) { if (token == null) { return null; } try { return verifier.verify(token); } catch (GeneralSecurityException | IOException | IllegalArgumentException e) { logger.atWarning().withCause(e).log("error while verifying JWT"); return null; } } GoogleJwtAuthenticator();  GoogleJwtAuthenticator(GoogleIdTokenVerifier verifier); @Override User authenticate(HttpServletRequest request);  }
@Test public void testVerifyToken() throws Exception { when(verifier.verify(TOKEN)) .thenReturn(token) .thenThrow(new GeneralSecurityException()) .thenThrow(new IOException()) .thenThrow(new IllegalArgumentException()); assertEquals(token, authenticator.verifyToken(TOKEN)); for (int i = 0; i < 3; i++) { assertNull(authenticator.verifyToken(TOKEN)); } }