### Question:
LevelOfAssuranceValidator { public void validate(Optional<LevelOfAssurance> responseLevelOfAssurance, LevelOfAssurance requiredLevelOfAssurance) { if (!responseLevelOfAssurance.isPresent()) { throw noLevelOfAssurance(); } if (!responseLevelOfAssurance.get().equals(requiredLevelOfAssurance)) { throw wrongLevelOfAssurance(java.util.Optional.of(responseLevelOfAssurance.get()), singletonList(requiredLevelOfAssurance)); } }  void validate(Optional<LevelOfAssurance> responseLevelOfAssurance, LevelOfAssurance requiredLevelOfAssurance);  }### Answer:
@Test public void validate_shouldNotThrowExceptionIfLevelOfAssuranceFromMatchingServiceMatchesOneFromIdp() throws Exception { LevelOfAssurance levelOfAssurance = LevelOfAssurance.LEVEL_2; levelOfAssuranceValidator.validate(Optional.ofNullable(levelOfAssurance), levelOfAssurance); }
@Test public void validate_shouldThrowExceptionIfLevelOfAssuranceFromMatchingServiceDoesNotExist() throws Exception { LevelOfAssurance levelOfAssurance = LevelOfAssurance.LEVEL_2; try { levelOfAssuranceValidator.validate(Optional.empty(), levelOfAssurance); fail("fail"); } catch (StateProcessingValidationException e) { assertThat(e.getMessage()).isEqualTo(StateProcessingValidationException.noLevelOfAssurance().getMessage()); } }
@Test public void validate_shouldThrowExceptionIfLevelOfAssuranceFromMatchingServiceDoesNotMatchOneFromIdp() throws Exception { try { levelOfAssuranceValidator.validate(Optional.ofNullable(LevelOfAssurance.LEVEL_2), LevelOfAssurance.LEVEL_4); fail("fail"); } catch (StateProcessingValidationException e) { assertThat(e.getMessage()).isEqualTo(StateProcessingValidationException.wrongLevelOfAssurance(java.util.Optional.of(LevelOfAssurance.LEVEL_2), singletonList(LevelOfAssurance.LEVEL_4)).getMessage()); } }