### Question:
JsonWebTokenAuthenticator implements Authenticator<String, Principal> { public static String createJwtToken(SignatureAlgorithm alg, Key secretKey, Principal principal) { return Jwts.builder().setSubject(principal.getName()).signWith(alg, secretKey).compact(); } JsonWebTokenAuthenticator(Key secretKey, SignatureAlgorithm algorithm); static String createJwtToken(SignatureAlgorithm alg, Key secretKey, Principal principal); @Override Optional<Principal> authenticate(String s); String createJwtToken(Principal principal);  }### Answer:
@Test(expected = NullPointerException.class) public void testCreateJwtTokenThrowsIfUserIsNull() { final JsonWebTokenAuthenticator authenticator = createValidAuthenticatorInstance(); authenticator.createJwtToken(null); }
@Test public void testCreateJwtTokenDoesNotReturnNull() { final Principal Principal = generatePrincipal(); final JsonWebTokenAuthenticator authenticator = createValidAuthenticatorInstance(); final String returnedToken = authenticator.createJwtToken(Principal); assertThat(returnedToken).isNotNull(); }
@Test public void testCreateJwtTokenReturnsValidJWTString() { final Key secretKey = createSecretKey(); final Principal Principal = generatePrincipal(); final JsonWebTokenAuthenticator authenticator = createAuthenticatorWithSecretKey(secretKey); final String returnedToken = authenticator.createJwtToken(Principal); assertIsValidJWT(secretKey, returnedToken); }