### Question:
TokenParser { @Nonnull ParsedToken parse(@Nonnull final DecryptedToken decryptedToken) { Assert.notNull(decryptedToken, "decryptedToken must not be null"); Assert.state(decryptedToken.isValid(), () -> "Expected valid decryptedToken, but got: " + decryptedToken); final JWTClaimsSet result; try { result = decryptedToken.getPayload(); } catch (ParseException e) { return ParsedToken.invalid(PAYLOAD_PARSING_ERROR, format("Payload parsing error: [%s]", e.getMessage())); } return parsePayload(result); }    }### Answer:
@Test void should_parse_token() throws ParseException { final DecryptedToken decryptedToken = givenDecryptedToken( with -> with.subject(SUBJECT) .claim(STIGMA_VALUE_FIELD_NAME, STIGMA.getValue()) ); final ParsedToken result = tokenParser.parse(decryptedToken); assertThat(result).isEqualTo(valid(STIGMA)); }
@Test void should_fail_parsing_on_incorrect_subject() throws ParseException { final DecryptedToken decryptedToken = givenDecryptedToken( with -> with.subject("INVALID_SUBJECT") .claim(STIGMA_VALUE_FIELD_NAME, STIGMA.getValue()) ); final ParsedToken result = tokenParser.parse(decryptedToken); assertThat(result.isValid()).isFalse(); assertThat(result.getStatus()).isEqualTo(ParsingStatus.INVALID_PAYLOAD); }
@Test void should_fail_parsing_on_missing_stigma() throws ParseException { final DecryptedToken decryptedToken = givenDecryptedToken( with -> with.subject(SUBJECT) ); final ParsedToken result = tokenParser.parse(decryptedToken); assertThat(result.isValid()).isFalse(); assertThat(result.getStatus()).isEqualTo(ParsingStatus.MISSING_STIGMA); }
@Test void should_fail_parsing_on_payload_parsing_error() throws ParseException { final DecryptedToken decryptedToken = Mockito.mock(DecryptedToken.class); given(decryptedToken.isValid()).willReturn(true); given(decryptedToken.getPayload()).willThrow(ParseException.class); final ParsedToken result = tokenParser.parse(decryptedToken); assertThat(result.isValid()).isFalse(); assertThat(result.getStatus()).isEqualTo(ParsingStatus.PAYLOAD_PARSING_ERROR); }