This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 0f4142ef954c39cbed61e2cb5c29514fc1f24f2c
Author: Benoit Tellier <btell...@linagora.com>
AuthorDate: Fri Jan 17 16:14:49 2020 +0700

    JAMES-2997 step #12 Attachment builder should require attachmentId
    
    It should not be set implicitly
---
 .../org/apache/james/mailbox/model/Attachment.java   | 20 ++++++--------------
 .../james/mailbox/model/MessageAttachmentTest.java   |  6 ++++++
 ...ElasticSearchListeningMessageSearchIndexTest.java |  2 ++
 .../james/vault/DeletedMessageConverterTest.java     |  2 ++
 .../mail/model/impl/SimpleMailboxMessageTest.java    |  2 ++
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git 
a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java 
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
index 934d044..6e36f8c 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
@@ -25,12 +25,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 
 public class Attachment {
-    public static Builder builder() {
-        return new Builder();
-    }
-
     public static class Builder {
-
         private AttachmentId attachmentId;
         private Long size;
         private String type;
@@ -56,19 +51,16 @@ public class Attachment {
         public Attachment build() {
             Preconditions.checkState(type != null, "'type' is mandatory");
             Preconditions.checkState(size != null, "'size' is mandatory");
-            AttachmentId builtAttachmentId = attachmentId();
-            Preconditions.checkState(builtAttachmentId != null, 
"'attachmentId' is mandatory");
-            return new Attachment(builtAttachmentId, type, size);
-        }
+            Preconditions.checkState(attachmentId != null, "'attachmentId' is 
mandatory");
 
-        private AttachmentId attachmentId() {
-            if (attachmentId != null) {
-                return attachmentId;
-            }
-            return AttachmentId.random();
+            return new Attachment(attachmentId, type, size);
         }
     }
 
+    public static Builder builder() {
+        return new Builder();
+    }
+
     private final AttachmentId attachmentId;
     private final String type;
     private final long size;
diff --git 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java
 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java
index d501c30..638985a 100644
--- 
a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java
+++ 
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java
@@ -45,6 +45,7 @@ class MessageAttachmentTest {
     @Test
     void buildShouldWorkWhenMandatoryAttributesAreGiven() {
         Attachment attachment = Attachment.builder()
+            .attachmentId(AttachmentId.from("1"))
             .size(36)
             .type("type")
             .build();
@@ -60,6 +61,7 @@ class MessageAttachmentTest {
     @Test
     void buildShouldAcceptIsInlineAndNoCid() {
         Attachment attachment = Attachment.builder()
+            .attachmentId(AttachmentId.from("1"))
             .size(36)
             .type("type")
             .build();
@@ -75,6 +77,7 @@ class MessageAttachmentTest {
     @Test
     void buildShouldSetAttributesWhenAllAreGiven() {
         Attachment attachment = Attachment.builder()
+            .attachmentId(AttachmentId.from("1"))
             .size(36)
             .type("type")
             .build();
@@ -93,6 +96,7 @@ class MessageAttachmentTest {
     @Test
     void isInlinedWithCidShouldReturnTrueWhenIsInlineAndHasCid() throws 
Exception {
         Attachment attachment = Attachment.builder()
+            .attachmentId(AttachmentId.from("1"))
             .size(36)
             .type("type")
             .build();
@@ -110,6 +114,7 @@ class MessageAttachmentTest {
     @Test
     void isInlinedWithCidShouldReturnFalseWhenIsNotInline() throws Exception {
         Attachment attachment = Attachment.builder()
+            .attachmentId(AttachmentId.from("1"))
             .size(36)
             .type("type")
             .build();
@@ -127,6 +132,7 @@ class MessageAttachmentTest {
     @Test
     void isInlinedWithCidShouldReturnFalseWhenIsInlineButNoCid() throws 
Exception {
         Attachment attachment = Attachment.builder()
+            .attachmentId(AttachmentId.from("1"))
             .size(36)
             .type("type")
             .build();
diff --git 
a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
 
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
index 73a6b0c..d01eb29 100644
--- 
a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
+++ 
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java
@@ -56,6 +56,7 @@ import 
org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
 import org.apache.james.mailbox.inmemory.InMemoryMessageId;
 import org.apache.james.mailbox.manager.ManagerTestProvisionner;
 import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
 import org.apache.james.mailbox.model.Mailbox;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageAttachment;
@@ -114,6 +115,7 @@ class ElasticSearchListeningMessageSearchIndexTest {
 
     static final MessageAttachment MESSAGE_ATTACHMENT = 
MessageAttachment.builder()
         .attachment(Attachment.builder()
+            .attachmentId(AttachmentId.from("1"))
             .type("type")
             .size(523)
             .build())
diff --git 
a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageConverterTest.java
 
b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageConverterTest.java
index eeb6a1c..57d5b5d 100644
--- 
a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageConverterTest.java
+++ 
b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageConverterTest.java
@@ -42,6 +42,7 @@ import java.util.List;
 import org.apache.james.core.MaybeSender;
 import org.apache.james.core.Username;
 import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.store.MessageBuilder;
@@ -72,6 +73,7 @@ class DeletedMessageConverterTest {
     private static final Collection<MessageAttachment> NO_ATTACHMENT = 
ImmutableList.of();
     private static final Collection<MessageAttachment> ATTACHMENTS = 
ImmutableList.of(MessageAttachment.builder()
         .attachment(Attachment.builder()
+            .attachmentId(AttachmentId.from("1"))
             .type("type")
             .size(48)
             .build())
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
index 0e13f97..c1f5d9e 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.ModSeq;
 import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
 import org.apache.james.mailbox.model.MessageAttachment;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.TestId;
@@ -177,6 +178,7 @@ class SimpleMailboxMessageTest {
         MessageUid uid = MessageUid.of(45);
         MessageAttachment messageAttachment = MessageAttachment.builder()
             .attachment(Attachment.builder()
+                .attachmentId(AttachmentId.from("1"))
                 .type("type")
                 .size(485)
                 .build())


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

Reply via email to