### Question:
IPAddressValidator { public void validate(Assertion assertion) { for (AttributeStatement attributeStatement : assertion.getAttributeStatements()) { for (Attribute attribute : attributeStatement.getAttributes()) { if (attribute.getName().equals(IdaConstants.Attributes_1_1.IPAddress.NAME)) { IPAddress ipAddressAttributeValue = (IPAddress) attribute.getAttributeValues().get(0); String addressValue = ipAddressAttributeValue.getValue(); if (!Strings.isNullOrEmpty(addressValue)) { return; } SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.emptyIPAddress(assertion.getID()); throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel()); } } } SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.missingIPAddress(assertion.getID()); throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel()); }  void validate(Assertion assertion);  }### Answer:
@Test public void validate_shouldNotThrowWhenFirstAttributeStatementContainsAnIPAddressAttribute() throws Exception { Assertion assertion = anAssertion() .addAttributeStatement(anAttributeStatement().addAttribute(IPAddressAttributeBuilder.anIPAddress().build()).build()) .buildUnencrypted(); validator.validate(assertion); }
@Test public void validate_shouldNotThrowWhenSecondAttributeStatementContainsAnIPAddressAttribute() throws Exception { Assertion assertion = anAssertion() .addAttributeStatement(anAttributeStatement().build()) .addAttributeStatement(anAttributeStatement().addAttribute(IPAddressAttributeBuilder.anIPAddress().build()).build()) .buildUnencrypted(); validator.validate(assertion); }
@Test public void validate_shouldNotThrowWhenFirstAttributeStatementContainsMultipleAttributesIncludingIPAddressAttribute() throws Exception { Assertion assertion = anAssertion() .addAttributeStatement(anAttributeStatement() .addAttribute(aPersonName_1_1().buildAsFirstname()) .addAttribute(IPAddressAttributeBuilder.anIPAddress().build()) .build()) .buildUnencrypted(); validator.validate(assertion); }
@Test public void validate_shouldNotWarnWhenAssertionContainsAnInvalidIPAddress() throws Exception { final String ipAddress = "10.10.10.1a"; final Assertion assertion = anAssertion() .addAttributeStatement(anAttributeStatement().addAttribute(IPAddressAttributeBuilder.anIPAddress().withValue(ipAddress).build()).build()) .buildUnencrypted(); validator.validate(assertion); }