james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [06/16] james-project git commit: JAMES-2134 Builder for Gateway
Date Thu, 05 Apr 2018 12:51:56 GMT
JAMES-2134 Builder for Gateway


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/93352f62
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/93352f62
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/93352f62

Branch: refs/heads/master
Commit: 93352f62f27954daa07f8d2bb369731c88a81eeb
Parents: b7ea0fe
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Tue Apr 3 16:48:31 2018 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Thu Apr 5 14:48:41 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/james/mdn/MDNReport.java    | 10 -----
 .../org/apache/james/mdn/fields/Gateway.java    | 39 ++++++++++++++++----
 .../james/mdn/MDNReportFormattingTest.java      |  6 +--
 .../org/apache/james/mdn/MDNReportTest.java     |  2 +-
 .../apache/james/mdn/fields/GatewayTest.java    | 29 +++++++++------
 5 files changed, 52 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/93352f62/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/MDNReport.java b/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
index 82030a1..317d3c5 100644
--- a/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
+++ b/mdn/src/main/java/org/apache/james/mdn/MDNReport.java
@@ -79,16 +79,6 @@ public class MDNReport {
             return this;
         }
 
-        public Builder gatewayField(String gatewayDns) {
-            this.gatewayField = Optional.of(new Gateway(Text.fromRawText(gatewayDns)));
-            return this;
-        }
-
-        public Builder gatewayField(Optional<Gateway> gatewayField) {
-            this.gatewayField = gatewayField;
-            return this;
-        }
-
         public Builder gatewayField(Gateway gatewayField) {
             this.gatewayField = Optional.of(gatewayField);
             return this;

http://git-wip-us.apache.org/repos/asf/james-project/blob/93352f62/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java b/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java
index c988b37..9699fc6 100644
--- a/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java
+++ b/mdn/src/main/java/org/apache/james/mdn/fields/Gateway.java
@@ -20,6 +20,7 @@
 package org.apache.james.mdn.fields;
 
 import java.util.Objects;
+import java.util.Optional;
 
 import com.google.common.base.Preconditions;
 
@@ -29,21 +30,43 @@ import com.google.common.base.Preconditions;
 public class Gateway implements Field {
     public static final String FIELD_NAME = "MDN-Gateway";
 
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static class Builder {
+        private Optional<AddressType> nameType;
+        private Text name;
+
+        private Builder() {
+            this.nameType = Optional.empty();
+        }
+
+        public Builder nameType(AddressType nameType) {
+            this.nameType = Optional.of(nameType);
+            return this;
+        }
+
+        public Builder name(Text name) {
+            this.name = name;
+            return this;
+        }
+
+        public Gateway build() {
+            Preconditions.checkNotNull(name);
+
+            return new Gateway(nameType.orElse(AddressType.DNS), name);
+        }
+    }
+
     private final AddressType nameType;
     private final Text name;
 
-    public Gateway(AddressType nameType, Text name) {
-        Preconditions.checkNotNull(nameType);
-        Preconditions.checkNotNull(name);
-
+    private Gateway(AddressType nameType, Text name) {
         this.nameType = nameType;
         this.name = name;
     }
 
-    public Gateway(Text name) {
-        this(AddressType.DNS, name);
-    }
-
     @Override
     public String formattedValue() {
         return FIELD_NAME + ": " + nameType.getType() + ";" + name.formatted();

http://git-wip-us.apache.org/repos/asf/james-project/blob/93352f62/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java b/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
index 8ccf42f..011108b 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
@@ -367,7 +367,7 @@ public class MDNReportFormattingTest {
 
         String report = MDNReport.builder()
             .reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
-            .gatewayField(new Gateway(Text.fromRawText("host.com")))
+            .gatewayField(Gateway.builder().name(Text.fromRawText("host.com")).build())
             .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
@@ -396,7 +396,7 @@ public class MDNReportFormattingTest {
 
         String report = MDNReport.builder()
             .reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
-            .gatewayField(new Gateway(new AddressType("postal"), Text.fromRawText("5 rue
Charles mercier")))
+            .gatewayField(Gateway.builder().nameType(new AddressType("postal")).name(Text.fromRawText("5
rue Charles mercier")).build())
             .finalRecipientField(new FinalRecipient(Text.fromRawText("final_recipient")))
             .originalRecipientField(new OriginalRecipient(Text.fromRawText("originalRecipient")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
@@ -452,7 +452,7 @@ public class MDNReportFormattingTest {
 
         String report = MDNReport.builder()
             .reportingUserAgentField(ReportingUserAgent.builder().userAgentName("UA_name").userAgentProduct("UA_product").build())
-            .gatewayField(new Gateway(new AddressType("postal"), Text.fromRawText("8 rue
Charles mercier\n 36555 Saint Coincoin\n France")))
+            .gatewayField(Gateway.builder().nameType(new AddressType("postal")).name(Text.fromRawText("8
rue Charles mercier\n 36555 Saint Coincoin\n France")).build())
             .finalRecipientField(new FinalRecipient(new AddressType("postal"), Text.fromRawText("5
rue Mercier\n 36555 Saint Coincoin\n France")))
             .originalRecipientField(new OriginalRecipient(new AddressType("postal"), Text.fromRawText("3
rue Mercier\n 36555 Saint Coincoin\n France")))
             .originalMessageIdField(new OriginalMessageId("original_message_id"))

http://git-wip-us.apache.org/repos/asf/james-project/blob/93352f62/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java b/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
index 6ee9d7e..b378522 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
@@ -117,7 +117,7 @@ public class MDNReportTest {
         FinalRecipient finalRecipientField = new FinalRecipient(Text.fromRawText("any@domain.com"));
         ExtensionField extensionField1 = new ExtensionField("name1", "value1");
         ExtensionField extensionField2 = new ExtensionField("name2", "value2");
-        Gateway gateway = new Gateway(Text.fromRawText("address"));
+        Gateway gateway = Gateway.builder().name(Text.fromRawText("address")).build();
         OriginalMessageId originalMessageIdField = new OriginalMessageId("msgId");
         OriginalRecipient originalRecipientField = new OriginalRecipient(Text.fromRawText("address"));
         ReportingUserAgent reportingUserAgentField = ReportingUserAgent.builder().userAgentName("name").build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/93352f62/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java
index 3d69440..a276d19 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/GatewayTest.java
@@ -43,43 +43,48 @@ public class GatewayTest {
     public void shouldThrowOnNullName() {
         expectedException.expect(NullPointerException.class);
 
-        Text name = null;
-        new Gateway(name);
+        Gateway.builder()
+            .name(null)
+            .build();
     }
 
     @Test
     public void shouldThrowOnNullNameWhenType() {
         expectedException.expect(NullPointerException.class);
 
-        Text name = null;
-        new Gateway(new AddressType("type"), name);
+        Gateway.builder()
+            .nameType(new AddressType("type"))
+            .name(null)
+            .build();
     }
 
     @Test
     public void shouldThrowOnNullType() {
         expectedException.expect(NullPointerException.class);
 
-        AddressType nameType = null;
-        new Gateway(nameType, Text.fromRawText("name"));
+        Gateway.builder()
+            .nameType(null)
+            .name(Text.fromRawText("name"))
+            .build();
     }
 
     @Test
-    public void addressTypeSHouldDefaultToDNS() {
+    public void addressTypeShouldDefaultToDNS() {
         Text address = Text.fromRawText("address");
-        assertThat(new Gateway(address))
-            .isEqualTo(new Gateway(AddressType.DNS, address));
+        assertThat(Gateway.builder().name(Text.fromRawText("address")).build())
+            .isEqualTo(Gateway.builder().nameType(AddressType.DNS).name(address).build());
     }
 
     @Test
     public void formattedValueShouldDisplayAddress() {
-        assertThat(new Gateway(Text.fromRawText("address"))
+        assertThat(Gateway.builder().name(Text.fromRawText("address")).build()
             .formattedValue())
             .isEqualTo("MDN-Gateway: dns;address");
     }
 
     @Test
     public void formattedValueShouldDisplayMultilineAddress() {
-        assertThat(new Gateway(Text.fromRawText("address\nmultiline"))
+        assertThat(Gateway.builder().name(Text.fromRawText("address\nmultiline")).build()
             .formattedValue())
             .isEqualTo("MDN-Gateway: dns;address\r\n" +
                 " multiline");
@@ -87,7 +92,7 @@ public class GatewayTest {
 
     @Test
     public void formattedValueShouldDisplayCustomAddress() {
-        assertThat(new Gateway(new AddressType("custom"), Text.fromRawText("address"))
+        assertThat(Gateway.builder().nameType(new AddressType("custom")).name(Text.fromRawText("address")).build()
             .formattedValue())
             .isEqualTo("MDN-Gateway: custom;address");
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message