### Question:
AuthenticationUtils { public static void getUser( final Optional<AuthenticationService> authenticationService, final String token, final Handler<Optional<User>> handler) { try { if (authenticationService.isEmpty()) { handler.handle(Optional.empty()); } else { authenticationService .get() .getJwtAuthProvider() .authenticate( new JsonObject().put("jwt", token), (r) -> { if (r.succeeded()) { final Optional<User> user = Optional.ofNullable(r.result()); validateExpiryExists(user); handler.handle(user); } else { LOG.debug("Invalid JWT token", r.cause()); handler.handle(Optional.empty()); } }); } } catch (Exception e) { handler.handle(Optional.empty()); } }  @VisibleForTesting static boolean isPermitted(
      final Optional<AuthenticationService> authenticationService,
      final Optional<User> optionalUser,
      final JsonRpcMethod jsonRpcMethod); static void getUser(
      final Optional<AuthenticationService> authenticationService,
      final String token,
      final Handler<Optional<User>> handler); static String getJwtTokenFromAuthorizationHeaderValue(final String value);  }### Answer:
@Test public void getUserFailsIfTokenDoesNotHaveExpiryClaim() { final AuthenticationService authenticationService = mock(AuthenticationService.class); final JWTAuth jwtAuth = new JWTAuthProviderImpl(null, new JWTAuthOptions()); final StubUserHandler handler = new StubUserHandler(); when(authenticationService.getJwtAuthProvider()).thenReturn(jwtAuth); AuthenticationUtils.getUser( Optional.of(authenticationService), INVALID_TOKEN_WITHOUT_EXP, handler); assertThat(handler.getEvent()).isEmpty(); }
@Test public void getUserSucceedsWithValidToken() { final AuthenticationService authenticationService = mock(AuthenticationService.class); final JWTAuth jwtAuth = new JWTAuthProviderImpl(null, new JWTAuthOptions()); final StubUserHandler handler = new StubUserHandler(); when(authenticationService.getJwtAuthProvider()).thenReturn(jwtAuth); AuthenticationUtils.getUser(Optional.of(authenticationService), VALID_TOKEN, handler); assertThat(handler.getEvent().get().principal()) .isEqualTo(new JsonObject(VALID_TOKEN_DECODED_PAYLOAD)); }