### Question:
ResponseFromCountryValidator extends EncryptedResponseFromIdpValidator<CountryAuthenticationStatus.Status> { protected void validateAssertionPresence(Response response) { boolean responseWasSuccessful = response.getStatus().getStatusCode().getValue().equals(StatusCode.SUCCESS); if (responseWasSuccessful && !response.getAssertions().isEmpty()) { SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.unencryptedAssertion(); throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel()); } if (responseWasSuccessful && response.getEncryptedAssertions().isEmpty()) { SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.missingSuccessUnEncryptedAssertions(); throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel()); } if (!responseWasSuccessful && !response.getEncryptedAssertions().isEmpty()) { SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.nonSuccessHasUnEncryptedAssertions(); throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel()); } if (responseWasSuccessful && response.getEncryptedAssertions().size() != 1) { SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.unexpectedNumberOfAssertions(1, response.getEncryptedAssertions().size()); throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel()); } } ResponseFromCountryValidator(SamlStatusToCountryAuthenticationStatusCodeMapper samlStatusToCountryAuthenticationStatusCodeMapper);   }### Answer:
@Test public void shouldThrowIfResponseIsSuccessfulAndHasUnencryptedAssertions() { exception.expect(SamlTransformationErrorException.class); exception.expectMessage("Response has unencrypted assertion."); when(response.getAssertions()).thenReturn(List.of(assertion)); validator.validateAssertionPresence(response); }
@Test public void shouldNotThrowIfResponseIsNotSuccessfulAndHasUnencryptedAssertions() { when(statusCode.getValue()).thenReturn(StatusCode.AUTHN_FAILED); validator.validateAssertionPresence(response); }
@Test public void shouldThrowIfResponseIsSuccessfulButHasNoEncryptedAssertions() { exception.expect(SamlTransformationErrorException.class); exception.expectMessage("Success response has no unencrypted assertions."); when(response.getEncryptedAssertions()).thenReturn(Collections.emptyList()); validator.validateAssertionPresence(response); }
@Test public void shouldThrowIfResponseNotSuccessfulButHasEncryptedAssertions() { exception.expect(SamlTransformationErrorException.class); exception.expectMessage("Non-success response has unencrypted assertions. Should contain no assertions."); when(statusCode.getValue()).thenReturn(StatusCode.AUTHN_FAILED); when(response.getEncryptedAssertions()).thenReturn(List.of(encryptedAssertion)); validator.validateAssertionPresence(response); }
@Test public void shouldThrowIfResponseIsSuccessfulButHasMultipleEncryptedAssertions() { exception.expect(SamlTransformationErrorException.class); exception.expectMessage("Response expected to contain 1 assertions. 2 assertion(s) found."); when(response.getEncryptedAssertions()).thenReturn(List.of(encryptedAssertion, encryptedAssertion)); validator.validateAssertionPresence(response); }