### Question:
RelayStateValidator { public void validate(String relayState) { if (relayState == null){ return; } if (relayState.length() > MAXIMUM_NUMBER_OF_CHARACTERS) { SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.invalidRelayState(relayState); throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel()); } for (String invalidCharacter : INVALID_CHARACTERS) { if (relayState.contains(invalidCharacter)) { SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.relayStateContainsInvalidCharacter(invalidCharacter, relayState); throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel()); } } }  void validate(String relayState);  }### Answer:
@Test public void validate_shouldCheckRelayStateLengthIsLessThanEightyOneCharactersOrRaiseException() { final String aStringMoreThanEightyCharacters = "a".repeat(82); SamlTransformationErrorManagerTestHelper.validateFail( () -> relayStateValidator.validate(aStringMoreThanEightyCharacters), SamlTransformationErrorFactory.invalidRelayState(aStringMoreThanEightyCharacters) ); }
@Test public void validate_shouldCheckRelayStateForValidStringAndNotThrowAnException() { String aStringLessThanEightyCharacters = "short string"; relayStateValidator.validate(aStringLessThanEightyCharacters); }
@Test public void validate_shouldCheckForInvalidCharacters() { final String aString = "aStringWith"; for (final String i : asList(">", "<", "'", "\"", "%", "&", ";")) { SamlTransformationErrorManagerTestHelper.validateFail( () -> relayStateValidator.validate(aString + i), SamlTransformationErrorFactory.relayStateContainsInvalidCharacter(i, aString + i) ); } }