### Question:
JwtService { public String getAuthenticationFromToken(final String base64EncodedToken) throws JwtException { try { final Jws<Claims> jws = parseTokenFromBase64EncodedString(base64EncodedToken); if (jws == null) { throw new JwtException("Unable to parse token"); } if (StringUtils.isEmpty(jws.getBody().getSubject())) { throw new JwtException("No subject available in token"); } if (StringUtils.isEmpty(jws.getBody().getIssuer())) { throw new JwtException("No issuer available in token"); } return jws.getBody().getSubject(); } catch (JwtException e) { logger.debug("The Base64 encoded JWT: " + base64EncodedToken); final String errorMessage = "There was an error validating the JWT"; logger.error(errorMessage, e); throw e; } } JwtService(final KeyService keyService); String getAuthenticationFromToken(final String base64EncodedToken); String generateSignedToken(final LoginAuthenticationToken authenticationToken);  }### Answer:
@Test public void testShouldGetAuthenticationForValidToken() throws Exception { String token = VALID_SIGNED_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); assertEquals("Identity", DEFAULT_IDENTITY, identity); }
@Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForInvalidToken() throws Exception { String token = INVALID_SIGNED_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }
@Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForEmptyToken() throws Exception { String token = ""; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }
@Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForUnsignedToken() throws Exception { String token = VALID_UNSIGNED_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }
@Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForMalsignedToken() throws Exception { String token = VALID_MALSIGNED_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }
@Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForTokenWithWrongAlgorithm() throws Exception { String token = VALID_MALSIGNED_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }
@Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForTokenWithWrongAlgorithmAndNoSignature() throws Exception { String token = VALID_MALSIGNED_NO_SIG_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }
@Ignore("Not yet implemented") @Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForTokenFromUnknownIdentityProvider() throws Exception { String token = UNKNOWN_ISSUER_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }
@Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForTokenFromEmptyIdentityProvider() throws Exception { String token = NO_ISSUER_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }
@Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForExpiredToken() throws Exception { String token = EXPIRED_SIGNED_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }
@Test(expected = JwtException.class) public void testShouldNotGetAuthenticationForImposterToken() throws Exception { String token = IMPOSTER_SIGNED_TOKEN; String identity = jwtService.getAuthenticationFromToken(token); logger.debug("Extracted identity: " + identity); }