### Question:
STSTokenGenerator { public static String generateToken(String incomingJWT, String audience, String issuer, String destination) throws CelleryCellSTSException { STSJWTBuilder stsjwtBuilder = new STSJWTBuilder(); JWTClaimsSet jwtClaims = getJWTClaims(incomingJWT); HashMap originalClaims = new HashMap(jwtClaims.getClaims()); replaceCellInformation(originalClaims, destination); stsjwtBuilder.subject(jwtClaims.getSubject()); stsjwtBuilder.expiryInSeconds(1200); stsjwtBuilder.audience(audience); stsjwtBuilder.claims(originalClaims); stsjwtBuilder.issuer(issuer); return stsjwtBuilder.build(); }  static String generateToken(String incomingJWT, String audience, String issuer, String destination); static String generateToken(String audience, String issuer, String destination); static JWTClaimsSet getJWTClaims(String jwt);  }### Answer:
@Test public void testGenerateToken() throws Exception { String issuer = "issuer-cell"; String audience = "audience-cell"; String token = STSTokenGenerator.generateToken(audience, issuer, "destination"); JWTClaimsSet jwtClaimsSet = SignedJWT.parse(token).getJWTClaimsSet(); Assert.assertEquals(jwtClaimsSet.getClaim("cellInstanceName"), CELL_NAME); Assert.assertEquals(jwtClaimsSet.getIssuer(), issuer); Assert.assertEquals(jwtClaimsSet.getAudience().get(0), audience); Assert.assertTrue(jwtClaimsSet.getExpirationTime().after(jwtClaimsSet.getIssueTime())); }
@Test public void testGenerateTokenWithExistingJWT() throws Exception { String issuer = "issuer-cell"; String audience = "audience-cell"; String initialToken = generateToken(audience, issuer, "Alice"); String token = STSTokenGenerator.generateToken(initialToken, audience + "-secondary", issuer + "-secondary", "destination"); JWTClaimsSet jwtClaimsSet = SignedJWT.parse(token).getJWTClaimsSet(); Assert.assertEquals(jwtClaimsSet.getClaim("cellInstanceName"), CELL_NAME); Assert.assertEquals(jwtClaimsSet.getIssuer(), issuer + "-secondary"); Assert.assertEquals(jwtClaimsSet.getAudience().get(0), audience + "-secondary"); Assert.assertTrue(jwtClaimsSet.getExpirationTime().after(jwtClaimsSet.getIssueTime())); Assert.assertEquals(jwtClaimsSet.getSubject(), "Alice"); }