MDNReport { public static Builder builder() { return new Builder(); } @VisibleForTesting  MDNReport(Optional<ReportingUserAgent> reportingUserAgentField, Optional<Gateway> gatewayField, Optional<OriginalRecipient> originalRecipientField,
                      FinalRecipient finalRecipientField, Optional<OriginalMessageId> originalMessageIdField, Disposition dispositionField,
                      ImmutableList<Error> errorFields, ImmutableList<ExtensionField> extensionFields); static Builder builder(); Optional<ReportingUserAgent> getReportingUserAgentField(); Optional<OriginalRecipient> getOriginalRecipientField(); FinalRecipient getFinalRecipientField(); Optional<OriginalMessageId> getOriginalMessageIdField(); Disposition getDispositionField(); Optional<Gateway> getGatewayField(); List<Error> getErrorFields(); String formattedValue(); @Override final boolean equals(Object o); @Override final int hashCode(); @Override String toString(); static final String LINE_END; static final String EXTENSION_DELIMITER; }
@Test void generateMDNReportThrowOnNullDisposition() { assertThatThrownBy(() -> MDNReport.builder() .reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build()) .finalRecipientField(FinalRecipient.builder().finalRecipient(Text.fromRawText("final_recipient")).build()) .originalRecipientField(OriginalRecipient.builder().originalRecipient(Text.fromRawText("originalRecipient")).build()) .build()) .isInstanceOf(IllegalStateException.class); }
@Test void generateMDNReportShouldThrowWhenMissingFinalField() { Disposition disposition = Disposition.builder() .actionMode(DispositionActionMode.Automatic) .sendingMode(DispositionSendingMode.Automatic) .type(DispositionType.Processed) .addModifier(DispositionModifier.Error) .addModifier(DispositionModifier.Failed) .build(); assertThatThrownBy(() -> MDNReport.builder() .reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build()) .originalRecipientField(OriginalRecipient.builder().originalRecipient(Text.fromRawText("originalRecipient")).build()) .originalMessageIdField(new OriginalMessageId("original_message_id")) .dispositionField(disposition) .build()) .isInstanceOf(IllegalStateException.class); }
@Test void shouldBuildWithMinimalSubset() { Disposition disposition = Disposition.builder() .actionMode(DispositionActionMode.Automatic) .sendingMode(DispositionSendingMode.Automatic) .type(DispositionType.Processed) .build(); FinalRecipient finalRecipientField = FinalRecipient.builder().finalRecipient(Text.fromRawText("any@domain.com")).build(); MDNReport mdnReport = MDNReport.builder() .finalRecipientField(finalRecipientField) .dispositionField(disposition) .build(); assertThat(mdnReport) .isEqualTo(new MDNReport( Optional.empty(), Optional.empty(), Optional.empty(), finalRecipientField, Optional.empty(), disposition, ImmutableList.of(), ImmutableList.of())); }
@Test void shouldBuildWithMaximalSubset() { Disposition disposition = Disposition.builder() .actionMode(DispositionActionMode.Automatic) .sendingMode(DispositionSendingMode.Automatic) .type(DispositionType.Processed) .build(); FinalRecipient finalRecipientField = FinalRecipient.builder().finalRecipient(Text.fromRawText("any@domain.com")).build(); ExtensionField extensionField1 = ExtensionField.builder().fieldName("name1").rawValue("value1").build(); ExtensionField extensionField2 = ExtensionField.builder().fieldName("name2").rawValue("value2").build();; Gateway gateway = Gateway.builder().name(Text.fromRawText("address")).build(); OriginalMessageId originalMessageIdField = new OriginalMessageId("msgId"); OriginalRecipient originalRecipientField = OriginalRecipient.builder().originalRecipient(Text.fromRawText("originalRecipient")).build(); ReportingUserAgent reportingUserAgentField = ReportingUserAgent.builder().userAgentName("name").build(); Error errorField1 = new Error(Text.fromRawText("error 1")); Error errorField2 = new Error(Text.fromRawText("error 2")); MDNReport mdnReport = MDNReport.builder() .withExtensionField(extensionField1) .withExtensionField(extensionField2) .finalRecipientField(finalRecipientField) .dispositionField(disposition) .gatewayField(gateway) .originalMessageIdField(originalMessageIdField) .originalRecipientField(originalRecipientField) .reportingUserAgentField(reportingUserAgentField) .addErrorField(errorField1) .addErrorField(errorField2) .build(); assertThat(mdnReport) .isEqualTo(new MDNReport( Optional.of(reportingUserAgentField), Optional.of(gateway), Optional.of(originalRecipientField), finalRecipientField, Optional.of(originalMessageIdField), disposition, ImmutableList.of(errorField1, errorField2), ImmutableList.of(extensionField1, extensionField2))); }