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

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

commit ad63b64927743c9a2e8217e97f4abd7e2d1e993e
Author: Rene Cordier <[email protected]>
AuthorDate: Fri Nov 22 11:34:33 2019 +0700

    JAMES-2987 Extract redundant constants to a MessageViewFixture interface
---
 .../message/view/MessageFullViewFactoryTest.java   | 39 ++++++------------
 .../message/view/MessageHeaderViewFactoryTest.java | 43 ++++++-------------
 .../view/MessageMetadataViewFactoryTest.java       |  5 +--
 .../model/message/view/MessageViewFixture.java     | 48 ++++++++++++++++++++++
 4 files changed, 75 insertions(+), 60 deletions(-)

diff --git 
a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
 
b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
index ad13156..da51cb7 100644
--- 
a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
+++ 
b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageFullViewFactoryTest.java
@@ -18,6 +18,12 @@
  ****************************************************************/
 package org.apache.james.jmap.draft.model.message.view;
 
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.ALICE_EMAIL;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.BOB;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.BOB_EMAIL;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.HEADERS_MAP;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.JACK_EMAIL;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.JACOB_EMAIL;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayInputStream;
@@ -29,7 +35,6 @@ import java.util.Optional;
 import javax.mail.Flags;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.james.core.Username;
 import org.apache.james.jmap.draft.model.Attachment;
 import org.apache.james.jmap.draft.model.BlobId;
 import org.apache.james.jmap.draft.model.Emailer;
@@ -70,7 +75,6 @@ class MessageFullViewFactoryTest {
     private static final String FORWARDED = "forwarded";
     private static final InMemoryId MAILBOX_ID = InMemoryId.of(18L);
     private static final Instant INTERNAL_DATE = 
Instant.parse("2012-02-03T14:30:42Z");
-    private static final Username BOB = Username.of("bob@local");
 
     private MessageIdManager messageIdManager;
     private MailboxSession session;
@@ -110,25 +114,6 @@ class MessageFullViewFactoryTest {
         List<MessageResult> messages = messageIdManager
             .getMessages(ImmutableList.of(message1.getMessageId()), 
FetchGroupImpl.MINIMAL, session);
 
-        Emailer bobEmail = 
Emailer.builder().name(BOB.getLocalPart()).email(BOB.asString()).build();
-        Emailer aliceEmail = 
Emailer.builder().name("alice").email("alice@local").build();
-        Emailer jackEmail = 
Emailer.builder().name("jack").email("jack@local").build();
-        Emailer jacobEmail = 
Emailer.builder().name("jacob").email("jacob@local").build();
-
-        ImmutableMap<String, String> headersMap = ImmutableMap.<String, 
String>builder()
-            .put("Content-Type", "multipart/mixed; 
boundary=\"------------7AF1D14DE1DFA16229726B54\"")
-            .put("Date", "Tue, 7 Jun 2016 16:23:37 +0200")
-            .put("From", "alice <alice@local>")
-            .put("To", "bob <bob@local>")
-            .put("Subject", "Full message")
-            .put("Mime-Version", "1.0")
-            .put("Message-ID", 
"<[email protected]>")
-            .put("Cc", "jack <jack@local>, jacob <jacob@local>")
-            .put("Bcc", "alice <alice@local>")
-            .put("Reply-to", "alice <alice@local>")
-            .put("In-reply-to", "bob@local")
-            .build();
-
         MessageFullView actual = 
messageFullViewFactory.fromMessageResults(messages);
         SoftAssertions.assertSoftly(softly -> {
             
softly.assertThat(actual.getId()).isEqualTo(message1.getMessageId());
@@ -138,12 +123,12 @@ class MessageFullViewFactoryTest {
             
softly.assertThat(actual.getKeywords()).isEqualTo(Keywords.strictFactory().from(Keyword.SEEN).asMap());
             
softly.assertThat(actual.getBlobId()).isEqualTo(BlobId.of(message1.getMessageId().serialize()));
             
softly.assertThat(actual.getInReplyToMessageId()).isEqualTo(Optional.of(BOB.asString()));
-            softly.assertThat(actual.getHeaders()).isEqualTo(headersMap);
-            
softly.assertThat(actual.getFrom()).isEqualTo(Optional.of(aliceEmail));
-            
softly.assertThat(actual.getTo()).isEqualTo(ImmutableList.of(bobEmail));
-            
softly.assertThat(actual.getCc()).isEqualTo(ImmutableList.of(jackEmail, 
jacobEmail));
-            
softly.assertThat(actual.getBcc()).isEqualTo(ImmutableList.of(aliceEmail));
-            
softly.assertThat(actual.getReplyTo()).isEqualTo(ImmutableList.of(aliceEmail));
+            softly.assertThat(actual.getHeaders()).isEqualTo(HEADERS_MAP);
+            
softly.assertThat(actual.getFrom()).isEqualTo(Optional.of(ALICE_EMAIL));
+            
softly.assertThat(actual.getTo()).isEqualTo(ImmutableList.of(BOB_EMAIL));
+            
softly.assertThat(actual.getCc()).isEqualTo(ImmutableList.of(JACK_EMAIL, 
JACOB_EMAIL));
+            
softly.assertThat(actual.getBcc()).isEqualTo(ImmutableList.of(ALICE_EMAIL));
+            
softly.assertThat(actual.getReplyTo()).isEqualTo(ImmutableList.of(ALICE_EMAIL));
             softly.assertThat(actual.getSubject()).isEqualTo("Full message");
             
softly.assertThat(actual.getDate()).isEqualTo("2016-06-07T14:23:37Z");
             softly.assertThat(actual.isHasAttachment()).isEqualTo(true);
diff --git 
a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactoryTest.java
 
b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactoryTest.java
index a60c17f..ec7711c 100644
--- 
a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactoryTest.java
+++ 
b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageHeaderViewFactoryTest.java
@@ -19,14 +19,19 @@
 
 package org.apache.james.jmap.draft.model.message.view;
 
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.ALICE_EMAIL;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.BOB;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.BOB_EMAIL;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.HEADERS_MAP;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.JACK_EMAIL;
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.JACOB_EMAIL;
+
 import java.util.List;
 import java.util.Optional;
 
 import javax.mail.Flags;
 
-import org.apache.james.core.Username;
 import org.apache.james.jmap.draft.model.BlobId;
-import org.apache.james.jmap.draft.model.Emailer;
 import org.apache.james.jmap.draft.model.Keyword;
 import org.apache.james.jmap.draft.model.Keywords;
 import org.apache.james.jmap.draft.model.Number;
@@ -47,11 +52,8 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 
 class MessageHeaderViewFactoryTest {
-    private static final Username BOB = Username.of("bob@local");
-
     private MessageIdManager messageIdManager;
     private MessageHeaderViewFactory testee;
     private MailboxSession session;
@@ -85,25 +87,6 @@ class MessageHeaderViewFactoryTest {
         List<MessageResult> messages = messageIdManager
             .getMessages(ImmutableList.of(message1.getMessageId()), 
FetchGroupImpl.MINIMAL, session);
 
-        Emailer bobEmail = 
Emailer.builder().name(BOB.getLocalPart()).email(BOB.asString()).build();
-        Emailer aliceEmail = 
Emailer.builder().name("alice").email("alice@local").build();
-        Emailer jackEmail = 
Emailer.builder().name("jack").email("jack@local").build();
-        Emailer jacobEmail = 
Emailer.builder().name("jacob").email("jacob@local").build();
-
-        ImmutableMap<String, String> headersMap = ImmutableMap.<String, 
String>builder()
-            .put("Content-Type", "multipart/mixed; 
boundary=\"------------7AF1D14DE1DFA16229726B54\"")
-            .put("Date", "Tue, 7 Jun 2016 16:23:37 +0200")
-            .put("From", "alice <alice@local>")
-            .put("To", "bob <bob@local>")
-            .put("Subject", "Full message")
-            .put("Mime-Version", "1.0")
-            .put("Message-ID", 
"<[email protected]>")
-            .put("Cc", "jack <jack@local>, jacob <jacob@local>")
-            .put("Bcc", "alice <alice@local>")
-            .put("Reply-to", "alice <alice@local>")
-            .put("In-reply-to", "bob@local")
-            .build();
-
         MessageHeaderView actual = testee.fromMessageResults(messages);
         SoftAssertions.assertSoftly(softly -> {
             
softly.assertThat(actual.getId()).isEqualTo(message1.getMessageId());
@@ -113,12 +96,12 @@ class MessageHeaderViewFactoryTest {
             
softly.assertThat(actual.getKeywords()).isEqualTo(Keywords.strictFactory().from(Keyword.SEEN).asMap());
             
softly.assertThat(actual.getBlobId()).isEqualTo(BlobId.of(message1.getMessageId().serialize()));
             
softly.assertThat(actual.getInReplyToMessageId()).isEqualTo(Optional.of(BOB.asString()));
-            softly.assertThat(actual.getHeaders()).isEqualTo(headersMap);
-            
softly.assertThat(actual.getFrom()).isEqualTo(Optional.of(aliceEmail));
-            
softly.assertThat(actual.getTo()).isEqualTo(ImmutableList.of(bobEmail));
-            
softly.assertThat(actual.getCc()).isEqualTo(ImmutableList.of(jackEmail, 
jacobEmail));
-            
softly.assertThat(actual.getBcc()).isEqualTo(ImmutableList.of(aliceEmail));
-            
softly.assertThat(actual.getReplyTo()).isEqualTo(ImmutableList.of(aliceEmail));
+            softly.assertThat(actual.getHeaders()).isEqualTo(HEADERS_MAP);
+            
softly.assertThat(actual.getFrom()).isEqualTo(Optional.of(ALICE_EMAIL));
+            
softly.assertThat(actual.getTo()).isEqualTo(ImmutableList.of(BOB_EMAIL));
+            
softly.assertThat(actual.getCc()).isEqualTo(ImmutableList.of(JACK_EMAIL, 
JACOB_EMAIL));
+            
softly.assertThat(actual.getBcc()).isEqualTo(ImmutableList.of(ALICE_EMAIL));
+            
softly.assertThat(actual.getReplyTo()).isEqualTo(ImmutableList.of(ALICE_EMAIL));
             softly.assertThat(actual.getSubject()).isEqualTo("Full message");
             
softly.assertThat(actual.getDate()).isEqualTo("2016-06-07T14:23:37Z");
         });
diff --git 
a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactoryTest.java
 
b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactoryTest.java
index 36cac92..f4f82c0 100644
--- 
a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactoryTest.java
+++ 
b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageMetadataViewFactoryTest.java
@@ -19,11 +19,12 @@
 
 package org.apache.james.jmap.draft.model.message.view;
 
+import static 
org.apache.james.jmap.draft.model.message.view.MessageViewFixture.BOB;
+
 import java.util.List;
 
 import javax.mail.Flags;
 
-import org.apache.james.core.Username;
 import org.apache.james.jmap.draft.model.BlobId;
 import org.apache.james.jmap.draft.model.Keyword;
 import org.apache.james.jmap.draft.model.Keywords;
@@ -46,8 +47,6 @@ import org.junit.jupiter.api.Test;
 import com.google.common.collect.ImmutableList;
 
 class MessageMetadataViewFactoryTest {
-
-    public static final Username BOB = Username.of("bob");
     private MessageIdManager messageIdManager;
     private MessageMetadataViewFactory testee;
     private MailboxSession session;
diff --git 
a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageViewFixture.java
 
b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageViewFixture.java
new file mode 100644
index 0000000..cee2a51
--- /dev/null
+++ 
b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/model/message/view/MessageViewFixture.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.jmap.draft.model.message.view;
+
+import org.apache.james.core.Username;
+import org.apache.james.jmap.draft.model.Emailer;
+
+import com.google.common.collect.ImmutableMap;
+
+public interface MessageViewFixture {
+    Username BOB = Username.of("bob@local");
+
+    Emailer BOB_EMAIL = 
Emailer.builder().name(BOB.getLocalPart()).email(BOB.asString()).build();
+    Emailer ALICE_EMAIL = 
Emailer.builder().name("alice").email("alice@local").build();
+    Emailer JACK_EMAIL = 
Emailer.builder().name("jack").email("jack@local").build();
+    Emailer JACOB_EMAIL = 
Emailer.builder().name("jacob").email("jacob@local").build();
+
+    ImmutableMap<String, String> HEADERS_MAP = ImmutableMap.<String, 
String>builder()
+        .put("Content-Type", "multipart/mixed; 
boundary=\"------------7AF1D14DE1DFA16229726B54\"")
+        .put("Date", "Tue, 7 Jun 2016 16:23:37 +0200")
+        .put("From", "alice <alice@local>")
+        .put("To", "bob <bob@local>")
+        .put("Subject", "Full message")
+        .put("Mime-Version", "1.0")
+        .put("Message-ID", 
"<[email protected]>")
+        .put("Cc", "jack <jack@local>, jacob <jacob@local>")
+        .put("Bcc", "alice <alice@local>")
+        .put("Reply-to", "alice <alice@local>")
+        .put("In-reply-to", "bob@local")
+        .build();
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to