### Question:
StigmaExtractor { @Nullable public Stigma extractStigma(@Nonnull final RawStigmaToken stigmaToken) { Assert.notNull(stigmaToken, "stigmaToken must not be null"); final JWT jwt; try { jwt = JWTParser.parse(stigmaToken.getValue()); } catch (ParseException e) { if (logger.isDebugEnabled()) { logger.debug("Parsing stigma token to JWT failed.", e); } return null; } final DecryptedToken decryptedToken = tokenDecrypter.decrypt(jwt); if (!decryptedToken.isValid()) { if (logger.isDebugEnabled()) { logger.debug("Failed to decrypt token: " + decryptedToken); } return null; } final ParsedToken parsedToken = tokenParser.parse(decryptedToken); if (!parsedToken.isValid()) { if (logger.isDebugEnabled()) { logger.debug("Failed to parse token: " + parsedToken); } return null; } if (logger.isTraceEnabled()) { logger.trace("Extracting stigma from token: " + parsedToken); } return parsedToken.getStigma(); } StigmaExtractor(final TokenDecrypter tokenDecrypter, final TokenParser tokenParser); @Nullable Stigma extractStigma(@Nonnull final RawStigmaToken stigmaToken);  }### Answer:
@Test void should_extract_stigma_from_valid_token() { given(tokenDecrypter.decrypt(any(com.nimbusds.jwt.JWT.class))).willReturn(decryptedToken); given(decryptedToken.isValid()).willReturn(true); given(tokenParser.parse(decryptedToken)).willReturn(parsedToken); given(parsedToken.isValid()).willReturn(true); given(parsedToken.getStigma()).willReturn(STIGMA); final Stigma stigma = stigmaExtractor.extractStigma(STIGMA_TOKEN); assertThat(stigma).isEqualTo(STIGMA); }
@Test void should_return_no_result_on_parsing_failure() { given(tokenDecrypter.decrypt(any(com.nimbusds.jwt.JWT.class))).willReturn(decryptedToken); given(decryptedToken.isValid()).willReturn(true); given(tokenParser.parse(decryptedToken)).willReturn(parsedToken); given(parsedToken.isValid()).willReturn(false); final Stigma stigma = stigmaExtractor.extractStigma(STIGMA_TOKEN); assertThat(stigma).isNull(); }
@Test void should_return_no_result_on_decrypting_failure() { given(tokenDecrypter.decrypt(any(com.nimbusds.jwt.JWT.class))).willReturn(decryptedToken); given(decryptedToken.isValid()).willReturn(false); final Stigma stigma = stigmaExtractor.extractStigma(STIGMA_TOKEN); assertThat(stigma).isNull(); verifyNoInteractions(tokenParser); }
@Test void should_return_no_result_on_JWT_parsing_failure() { final RawStigmaToken stigmaToken = new RawStigmaToken("not-parsable-to-JWT"); final Stigma stigma = stigmaExtractor.extractStigma(stigmaToken); assertThat(stigma).isNull(); verifyNoInteractions(tokenDecrypter); verifyNoInteractions(tokenParser); }