james-server-dev mailing list archives

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


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

Branch: refs/heads/master
Commit: f92070e4de066cc60e9d523a4353335a561257f1
Parents: 6528e34
Author: Raphael Ouazana <raphael.ouazana@linagora.com>
Authored: Wed Apr 4 12:25:07 2018 +0200
Committer: Raphael Ouazana <raphael.ouazana@linagora.com>
Committed: Thu Apr 5 14:48:43 2018 +0200

----------------------------------------------------------------------
 .../apache/james/mdn/fields/ExtensionField.java | 34 +++++++++++++++++---
 .../james/mdn/MDNReportFormattingTest.java      |  6 ++--
 .../org/apache/james/mdn/MDNReportTest.java     |  4 +--
 .../james/mdn/fields/ExtensionFieldTest.java    | 12 +++----
 4 files changed, 39 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f92070e4/mdn/src/main/java/org/apache/james/mdn/fields/ExtensionField.java
----------------------------------------------------------------------
diff --git a/mdn/src/main/java/org/apache/james/mdn/fields/ExtensionField.java b/mdn/src/main/java/org/apache/james/mdn/fields/ExtensionField.java
index a750f62..9f102d2 100644
--- a/mdn/src/main/java/org/apache/james/mdn/fields/ExtensionField.java
+++ b/mdn/src/main/java/org/apache/james/mdn/fields/ExtensionField.java
@@ -29,14 +29,38 @@ import com.google.common.base.Preconditions;
  * https://tools.ietf.org/html/rfc8098#section-3.3
  */
 public class ExtensionField implements Field {
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static class Builder {
+        private String fieldName;
+        private String rawValue;
+
+        public Builder fieldName(String fieldName) {
+            this.fieldName = fieldName;
+            return this;
+        }
+
+        public Builder rawValue(String rawValue) {
+            this.rawValue = rawValue;
+            return this;
+        }
+
+        public ExtensionField build() {
+            Preconditions.checkNotNull(fieldName);
+            Preconditions.checkNotNull(rawValue);
+            Preconditions.checkState(!fieldName.contains("\n"), "Field name can not be multiline");
+
+            return new ExtensionField(fieldName, rawValue);
+        }
+    }
+
     private final String fieldName;
     private final String rawValue;
 
-    public ExtensionField(String fieldName, String rawValue) {
-        Preconditions.checkNotNull(fieldName);
-        Preconditions.checkNotNull(rawValue);
-        Preconditions.checkArgument(!fieldName.contains("\n"), "Field name can not be multiline");
-
+    private ExtensionField(String fieldName, String rawValue) {
         this.fieldName = fieldName;
         this.rawValue = rawValue;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f92070e4/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 063be54..11a6532 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportFormattingTest.java
@@ -636,7 +636,7 @@ public class MDNReportFormattingTest {
             .originalRecipientField(OriginalRecipient.builder().originalRecipient(Text.fromRawText("originalRecipient")).build())
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
-         .withExtensionField(new ExtensionField("X-OPENPAAS-IP", "177.177.177.77"))
+         .withExtensionField(ExtensionField.builder().fieldName("X-OPENPAAS-IP").rawValue("177.177.177.77").build())
             .build()
             .formattedValue();
 
@@ -667,8 +667,8 @@ public class MDNReportFormattingTest {
             .originalMessageIdField(new OriginalMessageId("original_message_id"))
             .dispositionField(disposition)
             .withExtensionFields(
-                new ExtensionField("X-OPENPAAS-IP", "177.177.177.77"),
-                new ExtensionField("X-OPENPAAS-PORT", "8000"))
+                ExtensionField.builder().fieldName("X-OPENPAAS-IP").rawValue("177.177.177.77").build(),
+                ExtensionField.builder().fieldName("X-OPENPAAS-PORT").rawValue("8000").build())
             .build()
             .formattedValue();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f92070e4/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 526511c..5c65916 100644
--- a/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/MDNReportTest.java
@@ -115,8 +115,8 @@ public class MDNReportTest {
             .type(DispositionType.Processed)
             .build();
         FinalRecipient finalRecipientField = FinalRecipient.builder().finalRecipient(Text.fromRawText("any@domain.com")).build();
-        ExtensionField extensionField1 = new ExtensionField("name1", "value1");
-        ExtensionField extensionField2 = new ExtensionField("name2", "value2");
+        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();

http://git-wip-us.apache.org/repos/asf/james-project/blob/f92070e4/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java
----------------------------------------------------------------------
diff --git a/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java b/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java
index 7c9e877..5d9ff6b 100644
--- a/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java
+++ b/mdn/src/test/java/org/apache/james/mdn/fields/ExtensionFieldTest.java
@@ -43,28 +43,26 @@ public class ExtensionFieldTest {
     public void shouldThrowOnNullFieldName() {
         expectedException.expect(NullPointerException.class);
 
-        String fieldName = null;
-        new ExtensionField(fieldName, "rawValue");
+        ExtensionField.builder().fieldName(null).rawValue("rawValue").build();
     }
 
     @Test
     public void shouldThrowOnNullRawValue() {
         expectedException.expect(NullPointerException.class);
 
-        String rawValue = null;
-        new ExtensionField("name", rawValue);
+        ExtensionField.builder().fieldName("name").rawValue(null).build();
     }
 
     @Test
     public void shouldThrowOnMultilineName() {
-        expectedException.expect(IllegalArgumentException.class);
+        expectedException.expect(IllegalStateException.class);
 
-        new ExtensionField("name\nmultiline", "rawValue");
+        ExtensionField.builder().fieldName("name\nmultiline").rawValue("rawValue").build();
     }
 
     @Test
     public void formattedValueShouldDisplayNameAndRawValue() {
-        assertThat(new ExtensionField("name", "rawValue")
+        assertThat(ExtensionField.builder().fieldName("name").rawValue("rawValue").build()
             .formattedValue())
             .isEqualTo("name: rawValue");
     }


---------------------------------------------------------------------
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