### Question:
HubAssertionMarshaller { public Assertion toSaml(HubAssertion hubAssertion) { Assertion transformedAssertion = openSamlXmlObjectFactory.createAssertion(); transformedAssertion.setIssueInstant(hubAssertion.getIssueInstant()); Issuer transformedIssuer = openSamlXmlObjectFactory.createIssuer(hubAssertion.getIssuerId()); transformedAssertion.setIssuer(transformedIssuer); transformedAssertion.setID(hubAssertion.getId()); if (hubAssertion.getCycle3Data().isPresent()){ Cycle3Dataset cycle3Data = hubAssertion.getCycle3Data().get(); transformedAssertion.getAttributeStatements().add(transform(cycle3Data)); } transformedAssertion.setSubject(outboundAssertionToSubjectTransformer.transform(hubAssertion)); return transformedAssertion; } HubAssertionMarshaller(
            OpenSamlXmlObjectFactory openSamlXmlObjectFactory,
            AttributeFactory attributeFactory,
            OutboundAssertionToSubjectTransformer outboundAssertionToSubjectTransformer); Assertion toSaml(HubAssertion hubAssertion);  }### Answer:
@Test public void transform_shouldTransformAssertionId() throws Exception { String assertionId = "assertion-id"; HubAssertion assertion = aHubAssertion().withId(assertionId).build(); Assertion transformedAssertion = marshaller.toSaml(assertion); assertThat(transformedAssertion.getID()).isEqualTo(assertionId); }
@Test public void transform_shouldTransformAssertionIssuer() throws Exception { String assertionIssuerId = "assertion issuer"; HubAssertion assertion = aHubAssertion().withIssuerId(assertionIssuerId).build(); Assertion transformedAssertion = marshaller.toSaml(assertion); assertThat(transformedAssertion.getIssuer().getValue()).isEqualTo(assertionIssuerId); }
@Test public void transform_shouldTransformAssertionIssuerInstance() throws Exception { DateTime issueInstant = DateTime.parse("2012-12-31T12:34:56Z"); HubAssertion assertion = aHubAssertion().withIssueInstant(issueInstant).build(); Assertion transformedAssertion = marshaller.toSaml(assertion); assertThat(transformedAssertion.getIssueInstant()).isEqualTo(issueInstant); }
@Test public void transform_shouldTransformCycle3DataAssertion() throws Exception { String attributeName = "someName"; String value = "some value"; HubAssertion assertion = aHubAssertion().withCycle3Data(aCycle3Dataset().addCycle3Data(attributeName, value).build()).build(); Attribute expectedAttribute = aSimpleStringAttribute().build(); when(attributeFactory.createCycle3DataAttribute(attributeName, value)).thenReturn(expectedAttribute); Assertion transformedAssertion = marshaller.toSaml(assertion); List<AttributeStatement> attributeStatements = transformedAssertion.getAttributeStatements(); assertThat(attributeStatements.size()).isGreaterThan(0); Attribute attribute = attributeStatements.get(0).getAttributes().get(0); assertThat(attribute).isEqualTo(expectedAttribute); }
@Test public void transform_shouldTransformLevelOfCycle3DataAssertion() throws Exception { String attributeName = "someName"; String value = "some value"; HubAssertion assertion = aHubAssertion().withCycle3Data(aCycle3Dataset().addCycle3Data(attributeName, value).build()).build(); Attribute expectedAttribute = aSimpleStringAttribute().build(); when(attributeFactory.createCycle3DataAttribute(attributeName, value)).thenReturn(expectedAttribute); Assertion transformedAssertion = marshaller.toSaml(assertion); List<AttributeStatement> attributeStatements = transformedAssertion.getAttributeStatements(); assertThat(attributeStatements.size()).isGreaterThan(0); Attribute attribute = attributeStatements.get(0).getAttributes().get(0); assertThat(attribute).isEqualTo(expectedAttribute); }