james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [05/12] james-project git commit: JAMES-2161 Fix Keywords.Factory construction
Date Tue, 27 Nov 2018 02:06:32 GMT
JAMES-2161 Fix Keywords.Factory construction

 - Building the factory was too complex and required a deep understanding of its logic

We propose in this pull request a simple (lenient/strict) model for the caller. Note that
this model
fill all caller needs.

 - The factory was mutable leading to some potential subtle bugs lurking in.


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

Branch: refs/heads/master
Commit: e9f48651416a306a01201e8786955cf03de0d235
Parents: 34aad5b
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Nov 23 10:35:54 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Tue Nov 27 09:01:54 2018 +0700

----------------------------------------------------------------------
 .../cucumber/SetMessagesMethodStepdefs.java     |  2 +-
 .../james/jmap/methods/GetMessagesMethod.java   |  3 +-
 .../james/jmap/methods/MessageAppender.java     |  2 +-
 .../methods/SetMessagesUpdateProcessor.java     |  2 +-
 .../james/jmap/model/CreationMessage.java       |  3 +-
 .../org/apache/james/jmap/model/Keywords.java   | 52 +++++++++++---------
 .../org/apache/james/jmap/model/OldKeyword.java |  2 +-
 .../james/jmap/model/UpdateMessagePatch.java    |  3 +-
 .../james/jmap/utils/KeywordsCombiner.java      |  3 +-
 .../james/jmap/json/ParsingWritingObjects.java  |  2 +-
 .../apache/james/jmap/model/KeywordsTest.java   | 33 ++++++-------
 .../james/jmap/model/MessageFactoryTest.java    | 50 +++++++++----------
 .../apache/james/jmap/model/MessageTest.java    |  2 +-
 .../apache/james/jmap/model/OldKeywordTest.java | 20 ++++----
 .../apache/james/jmap/send/MailFactoryTest.java |  2 +-
 .../james/jmap/utils/KeywordsCombinerTest.java  | 44 ++++++++---------
 16 files changed, 112 insertions(+), 113 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
index cc4159a..831c99f 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMessagesMethodStepdefs.java
@@ -292,7 +292,7 @@ public class SetMessagesMethodStepdefs {
 
     @When("^message \"([^\"]*)\" has flags (.*) in mailbox \"([^\"]*)\" of user \"([^\"]*)\"$")
     public void setMessageFlagsInSpecifiedMailbox(String message, List<String> flags,
String mailbox, String mailboxOwner) throws Exception {
-        Flags newFlags = Keywords.factory().fromList(flags).asFlags();
+        Flags newFlags = Keywords.lenientFactory().fromList(flags).asFlags();
         String username = userStepdefs.getConnectedUser();
         MessageId messageId = messageIdStepdefs.getMessageId(message);
         MailboxId mailboxId = mainStepdefs.getMailboxId(mailboxOwner, mailbox);

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index d180934..1c97156 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -79,8 +79,7 @@ public class GetMessagesMethod implements Method {
         this.messageFactory = messageFactory;
         this.messageIdManager = messageIdManager;
         this.metricFactory = metricFactory;
-        this.keywordsFactory = Keywords.factory()
-            .filterImapNonExposedKeywords();
+        this.keywordsFactory = Keywords.lenientFactory();
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
index 42852a9..c915c3d 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
@@ -123,7 +123,7 @@ public class MessageAppender {
 
         return MessageFactory.MetaDataWithContent.builder()
             .uid(appendedMessage.getUid())
-            .keywords(Keywords.factory().fromFlags(flags))
+            .keywords(Keywords.lenientFactory().fromFlags(flags))
             .internalDate(internalDate.toInstant())
             .sharedContent(content)
             .size(messageContent.length)

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
index 3e75d30..fd7f17b 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
@@ -209,7 +209,7 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor
{
 
         boolean isDraft = messagesToBeUpdated.stream()
             .map(MessageResult::getFlags)
-            .map(Keywords.factory().filterImapNonExposedKeywords()::fromFlags)
+            .map(Keywords.lenientFactory()::fromFlags)
             .reduce(new KeywordsCombiner())
             .orElse(Keywords.DEFAULT_VALUE)
             .contains(Keyword.DRAFT);

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
index 364ca8e..aa151e7 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
@@ -227,8 +227,7 @@ public class CreationMessage {
         }
 
         private Optional<Keywords> creationKeywords() {
-            return keywords.map(map -> Keywords.factory()
-                    .throwOnImapNonExposedKeywords()
+            return keywords.map(map -> Keywords.strictFactory()
                     .fromMap(map));
         }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
index 5ef8091..9eeb9c6 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/Keywords.java
@@ -22,7 +22,6 @@ package org.apache.james.jmap.model;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import java.util.Set;
 import java.util.function.Predicate;
 import java.util.stream.Stream;
@@ -43,13 +42,9 @@ import com.google.common.collect.ImmutableSet;
 
 public class Keywords {
 
-    public static final Keywords DEFAULT_VALUE = factory().fromSet(ImmutableSet.of());
+    public static final Keywords DEFAULT_VALUE = new Keywords(ImmutableSet.of());
     private static final Logger LOGGER = LoggerFactory.getLogger(Keywords.class);
 
-    public interface KeywordsValidator {
-        void validate(Set<Keyword> keywords);
-    }
-
     private FlagsBuilder combiner(FlagsBuilder firstBuilder, FlagsBuilder secondBuilder)
{
         return firstBuilder.add(secondBuilder.build());
     }
@@ -59,31 +54,36 @@ public class Keywords {
     }
 
     public static class KeywordsFactory {
-        private Optional<KeywordsValidator> validator;
-        private Optional<Predicate<Keyword>> filter;
+        @FunctionalInterface
+        interface KeywordsValidator {
+            KeywordsValidator THROW_ON_IMAP_NON_EXPOSED_KEYWORDS = keywords -> Preconditions.checkArgument(
+                keywords.stream().allMatch(Keyword::isExposedImapKeyword),
+                "Does not allow to update 'Deleted' or 'Recent' flag");
+
+            KeywordsValidator IGNORE_NON_EXPOSED_IMAP_KEYWORDS = keywords -> { };
 
-        private KeywordsFactory() {
-            validator = Optional.empty();
-            filter = Optional.empty();
+            void validate(Set<Keyword> keywords);
         }
 
-        public KeywordsFactory throwOnImapNonExposedKeywords() {
-            validator = Optional.of(keywords -> Preconditions.checkArgument(
-                keywords.stream().allMatch(Keyword::isExposedImapKeyword), "Does not allow
to update 'Deleted' or 'Recent' flag"));
-            return this;
+        @FunctionalInterface
+        interface KeywordFilter extends Predicate<Keyword> {
+            KeywordFilter FILTER_IMAP_NON_EXPOSED_KEYWORDS = Keyword::isExposedImapKeyword;
+            KeywordFilter KEEP_ALL = keyword -> true;
         }
 
-        public KeywordsFactory filterImapNonExposedKeywords() {
-            filter = Optional.of(Keyword::isExposedImapKeyword);
-            return this;
+        private final KeywordsValidator validator;
+        private final Predicate<Keyword> filter;
+
+        public KeywordsFactory(KeywordsValidator validator, Predicate<Keyword> filter)
{
+            this.validator = validator;
+            this.filter = filter;
         }
 
         public Keywords fromSet(Set<Keyword> setKeywords) {
-            validator.orElse(keywords -> { })
-                .validate(setKeywords);
+            validator.validate(setKeywords);
 
             return new Keywords(setKeywords.stream()
-                    .filter(filter.orElse(keyword -> true))
+                    .filter(filter)
                     .collect(Guavate.toImmutableSet()));
         }
 
@@ -130,8 +130,14 @@ public class Keywords {
         }
     }
 
-    public static KeywordsFactory factory() {
-        return new KeywordsFactory();
+    public static KeywordsFactory strictFactory() {
+        return new KeywordsFactory(KeywordsFactory.KeywordsValidator.THROW_ON_IMAP_NON_EXPOSED_KEYWORDS,
+            KeywordsFactory.KeywordFilter.KEEP_ALL);
+    }
+
+    public static KeywordsFactory lenientFactory() {
+        return new KeywordsFactory(KeywordsFactory.KeywordsValidator.IGNORE_NON_EXPOSED_IMAP_KEYWORDS,
+            KeywordsFactory.KeywordFilter.FILTER_IMAP_NON_EXPOSED_KEYWORDS);
     }
 
     private final ImmutableSet<Keyword> keywords;

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
index 151a8f1..8296252 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/OldKeyword.java
@@ -173,7 +173,7 @@ public class OldKeyword {
     }
 
     public Keywords asKeywords() {
-        return Keywords.factory()
+        return Keywords.strictFactory()
             .fromSet(StreamUtils
                 .flatten(
                     OptionalUtils.toStream(isAnswered.filter(b -> b).map(b -> Keyword.ANSWERED)),

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
index 087eb30..6d172d9 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
@@ -108,8 +108,7 @@ public class UpdateMessagePatch {
         }
 
         private Optional<Keywords> creationKeywords() {
-            return keywords.map(map -> Keywords.factory()
-                    .throwOnImapNonExposedKeywords()
+            return keywords.map(map -> Keywords.strictFactory()
                     .fromMap(map));
         }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/KeywordsCombiner.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/KeywordsCombiner.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/KeywordsCombiner.java
index 185be02..2072446 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/KeywordsCombiner.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/KeywordsCombiner.java
@@ -37,8 +37,7 @@ public class KeywordsCombiner implements BinaryOperator<Keywords>
{
     private Keywords.KeywordsFactory keywordsFactory;
 
     public KeywordsCombiner() {
-        this.keywordsFactory = Keywords.factory()
-            .filterImapNonExposedKeywords();
+        this.keywordsFactory = Keywords.lenientFactory();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
index b81731a..cbd6d61 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/json/ParsingWritingObjects.java
@@ -77,7 +77,7 @@ public interface ParsingWritingObjects {
             .threadId(Common.THREAD_ID)
             .mailboxIds(Common.MAILBOX_IDS)
             .inReplyToMessageId(Common.IN_REPLY_TO_MESSAGE_ID)
-            .keywords(Keywords.factory().fromSet(Common.KEYWORDS))
+            .keywords(Keywords.strictFactory().fromSet(Common.KEYWORDS))
             .headers(Common.HEADERS)
             .from(Common.FROM)
             .to(Common.TO)

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
index 43b45a7..e48b9cf 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/KeywordsTest.java
@@ -51,13 +51,13 @@ public class KeywordsTest {
     public void fromMapShouldThrowWhenWrongKeywordValue() {
         expectedException.expect(IllegalArgumentException.class);
 
-        Keywords.factory()
+        Keywords.lenientFactory()
             .fromMap(ImmutableMap.of(ANY_KEYWORD, false));
     }
 
     @Test
     public void fromMapShouldReturnKeywordsFromMapStringAndBoolean() {
-        Keywords keywords = Keywords.factory()
+        Keywords keywords = Keywords.lenientFactory()
             .fromMap(ImmutableMap.of(ANY_KEYWORD, Keyword.FLAG_VALUE));
 
         assertThat(keywords.getKeywords())
@@ -66,7 +66,7 @@ public class KeywordsTest {
 
     @Test
     public void fromFlagsShouldReturnKeywordsFromAllFlag() {
-        Keywords keywords = Keywords.factory()
+        Keywords keywords = Keywords.lenientFactory()
             .fromFlags(new Flags(Flags.Flag.ANSWERED));
 
         assertThat(keywords.getKeywords())
@@ -75,7 +75,7 @@ public class KeywordsTest {
 
     @Test
     public void fromSetShouldReturnKeywordsFromSetOfKeywords() {
-        Keywords keywords = Keywords.factory()
+        Keywords keywords = Keywords.lenientFactory()
             .fromSet(ImmutableSet.of(Keyword.ANSWERED));
 
         assertThat(keywords.getKeywords())
@@ -84,7 +84,7 @@ public class KeywordsTest {
 
     @Test
     public void asFlagsShouldBuildFlagsFromKeywords() {
-        assertThat(Keywords.factory()
+        assertThat(Keywords.lenientFactory()
                 .fromSet(ImmutableSet.of(Keyword.ANSWERED))
                 .asFlags())
             .isEqualTo(new Flags(Flags.Flag.ANSWERED));
@@ -100,7 +100,7 @@ public class KeywordsTest {
             .add(Flag.ANSWERED, Flag.RECENT)
             .build();
 
-        assertThat(Keywords.factory()
+        assertThat(Keywords.lenientFactory()
                 .fromSet(ImmutableSet.of(Keyword.ANSWERED))
                 .asFlagsWithRecentAndDeletedFrom(originFlags))
             .isEqualTo(expectedFlags);
@@ -116,7 +116,7 @@ public class KeywordsTest {
             .add(Flag.ANSWERED, Flag.RECENT, Flag.DELETED)
             .build();
 
-        assertThat(Keywords.factory()
+        assertThat(Keywords.lenientFactory()
                 .fromSet(ImmutableSet.of(Keyword.ANSWERED))
                 .asFlagsWithRecentAndDeletedFrom(originFlags))
             .isEqualTo(expectedFlags);
@@ -124,7 +124,7 @@ public class KeywordsTest {
 
     @Test
     public void asMapShouldReturnEmptyWhenEmptyMapOfStringAndBoolean() {
-        assertThat(Keywords.factory()
+        assertThat(Keywords.lenientFactory()
                 .fromSet(ImmutableSet.of())
                 .asMap())
             .isEmpty();
@@ -133,7 +133,7 @@ public class KeywordsTest {
     @Test
     public void asMapShouldReturnMapOfStringAndBoolean() {
         Map<String, Boolean> expectedMap = ImmutableMap.of("$Answered", Keyword.FLAG_VALUE);
-        assertThat(Keywords.factory()
+        assertThat(Keywords.lenientFactory()
                 .fromSet(ImmutableSet.of(Keyword.ANSWERED))
                 .asMap())
             .isEqualTo(expectedMap);
@@ -143,15 +143,13 @@ public class KeywordsTest {
     public void throwWhenUnsupportedKeywordShouldThrowWhenHaveUnsupportedKeywords() {
         expectedException.expect(IllegalArgumentException.class);
 
-        Keywords.factory()
-            .throwOnImapNonExposedKeywords()
+        Keywords.strictFactory()
             .fromSet(ImmutableSet.of(Keyword.DRAFT, Keyword.DELETED));
     }
 
     @Test
     public void throwWhenUnsupportedKeywordShouldNotThrowWhenHaveDraft() {
-        Keywords keywords = Keywords.factory()
-            .throwOnImapNonExposedKeywords()
+        Keywords keywords = Keywords.strictFactory()
             .fromSet(ImmutableSet.of(Keyword.ANSWERED, Keyword.DRAFT));
 
         assertThat(keywords.getKeywords())
@@ -160,8 +158,7 @@ public class KeywordsTest {
 
     @Test
     public void filterUnsupportedShouldFilter() {
-        Keywords keywords = Keywords.factory()
-            .filterImapNonExposedKeywords()
+        Keywords keywords = Keywords.lenientFactory()
             .fromSet(ImmutableSet.of(Keyword.ANSWERED, Keyword.DELETED, Keyword.RECENT, Keyword.DRAFT));
 
         assertThat(keywords.getKeywords())
@@ -170,7 +167,7 @@ public class KeywordsTest {
 
     @Test
     public void containsShouldReturnTrueWhenKeywordsContainKeyword() {
-        Keywords keywords = Keywords.factory()
+        Keywords keywords = Keywords.lenientFactory()
             .fromSet(ImmutableSet.of(Keyword.SEEN));
 
         assertThat(keywords.contains(Keyword.SEEN)).isTrue();
@@ -178,7 +175,7 @@ public class KeywordsTest {
 
     @Test
     public void containsShouldReturnFalseWhenKeywordsDoNotContainKeyword() {
-        Keywords keywords = Keywords.factory()
+        Keywords keywords = Keywords.lenientFactory()
             .fromSet(ImmutableSet.of());
 
         assertThat(keywords.contains(Keyword.SEEN)).isFalse();
@@ -186,7 +183,7 @@ public class KeywordsTest {
 
     @Test
     public void fromListShouldReturnKeywordsFromListOfStrings() {
-        Keywords keywords = Keywords.factory()
+        Keywords keywords = Keywords.lenientFactory()
             .fromList(ImmutableList.of("$Answered", "$Flagged"));
 
         assertThat(keywords.getKeywords())

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
index dfe2c00..8c960af 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
@@ -70,7 +70,7 @@ public class MessageFactoryTest {
     public void emptyMailShouldBeLoadedIntoMessage() throws Exception {
         MetaDataWithContent testMail = MetaDataWithContent.builder()
                 .uid(MessageUid.of(2))
-                .keywords(Keywords.factory().from(Keyword.SEEN))
+                .keywords(Keywords.strictFactory().from(Keyword.SEEN))
                 .size(0)
                 .internalDate(INTERNAL_DATE)
                 .content(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)))
@@ -89,7 +89,7 @@ public class MessageFactoryTest {
     public void flagsShouldBeSetIntoMessage() throws Exception {
         MetaDataWithContent testMail = MetaDataWithContent.builder()
                 .uid(MessageUid.of(2))
-                .keywords(Keywords.factory().from(Keyword.ANSWERED, Keyword.FLAGGED, Keyword.DRAFT,
Keyword.FORWARDED))
+                .keywords(Keywords.strictFactory().from(Keyword.ANSWERED, Keyword.FLAGGED,
Keyword.DRAFT, Keyword.FORWARDED))
                 .size(0)
                 .internalDate(INTERNAL_DATE)
                 .content(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)))
@@ -105,7 +105,7 @@ public class MessageFactoryTest {
 
     @Test
     public void headersShouldBeSetIntoMessage() throws Exception {
-        Keywords keywords = Keywords.factory().from(Keyword.SEEN);
+        Keywords keywords = Keywords.strictFactory().from(Keyword.SEEN);
         String headers = "From: user <user@domain>\n"
                 + "Subject: test subject\n"
                 + "To: user1 <user1@domain>, user2 <user2@domain>\n"
@@ -171,7 +171,7 @@ public class MessageFactoryTest {
 
     @Test
     public void headersShouldBeUnfoldedAndDecoded() throws Exception {
-        Keywords keywords = Keywords.factory().from(Keyword.SEEN);
+        Keywords keywords = Keywords.strictFactory().from(Keyword.SEEN);
         String headers = "From: user <user@domain>\n"
             + "Subject: test subject\n"
             + "To: user1 <user1@domain>,\r\n"
@@ -223,7 +223,7 @@ public class MessageFactoryTest {
 
     @Test
     public void multivaluedHeadersShouldBeSeparatedByLineFeed() throws Exception {
-        Keywords keywords = Keywords.factory().from(Keyword.SEEN);
+        Keywords keywords = Keywords.strictFactory().from(Keyword.SEEN);
         String headers = "From: user <user@domain>\n"
             + "Subject: test subject\n"
             + "Multi-header: first value\n"
@@ -272,7 +272,7 @@ public class MessageFactoryTest {
 
     @Test
     public void textBodyShouldBeSetIntoMessage() throws Exception {
-        Keywords keywords = Keywords.factory().from(Keyword.SEEN);
+        Keywords keywords = Keywords.strictFactory().from(Keyword.SEEN);
         String headers = "Subject: test subject\n";
         String body = "Mail body";
         String mail = headers + "\n" + body;
@@ -311,7 +311,7 @@ public class MessageFactoryTest {
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .internalDate(INTERNAL_DATE)
             .size(1000)
             .content(messageContent)
@@ -340,7 +340,7 @@ public class MessageFactoryTest {
         String mail = headers + "\n" + body300;
         MetaDataWithContent testMail = MetaDataWithContent.builder()
                 .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
                 .size(mail.length())
                 .internalDate(INTERNAL_DATE)
                 .content(new ByteArrayInputStream(mail.getBytes(StandardCharsets.UTF_8)))
@@ -356,7 +356,7 @@ public class MessageFactoryTest {
     public void attachmentsShouldBeEmptyWhenNone() throws Exception {
         MetaDataWithContent testMail = MetaDataWithContent.builder()
                 .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
                 .size(0)
                 .internalDate(INTERNAL_DATE)
                 .content(ClassLoader.getSystemResourceAsStream("spamMail.eml"))
@@ -382,7 +382,7 @@ public class MessageFactoryTest {
                 .build();
         MetaDataWithContent testMail = MetaDataWithContent.builder()
                 .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
                 .size(0)
                 .internalDate(INTERNAL_DATE)
                 .content(ClassLoader.getSystemResourceAsStream("spamMail.eml"))
@@ -414,7 +414,7 @@ public class MessageFactoryTest {
             + "Subject: test subject\n";
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(headers.length())
             .internalDate(INTERNAL_DATE)
             .content(new ByteArrayInputStream(headers.getBytes(StandardCharsets.UTF_8)))
@@ -443,7 +443,7 @@ public class MessageFactoryTest {
             + "Subject: test subject\n";
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(headers.length())
             .internalDate(INTERNAL_DATE)
             .content(new ByteArrayInputStream(headers.getBytes(StandardCharsets.UTF_8)))
@@ -468,7 +468,7 @@ public class MessageFactoryTest {
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(headers.length())
             .internalDate(INTERNAL_DATE)
             .content(new ByteArrayInputStream(headers.getBytes(StandardCharsets.UTF_8)))
@@ -494,7 +494,7 @@ public class MessageFactoryTest {
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(headers.length())
             .internalDate(INTERNAL_DATE)
             .content(new ByteArrayInputStream(headers.getBytes(StandardCharsets.UTF_8)))
@@ -519,7 +519,7 @@ public class MessageFactoryTest {
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(headers.length())
             .internalDate(INTERNAL_DATE)
             .content(new ByteArrayInputStream(headers.getBytes(StandardCharsets.UTF_8)))
@@ -537,7 +537,7 @@ public class MessageFactoryTest {
     public void mailWithBigLinesShouldBeLoadedIntoMessage() throws Exception {
         MetaDataWithContent testMail = MetaDataWithContent.builder()
                 .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
                 .size(1010)
                 .internalDate(INTERNAL_DATE)
                 .content(new ByteArrayInputStream((StringUtils.repeat("0123456789", 101).getBytes(StandardCharsets.UTF_8))))
@@ -560,7 +560,7 @@ public class MessageFactoryTest {
             + "my <b>HTML</b> message").getBytes(StandardCharsets.UTF_8));
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(messageContent.read())
             .internalDate(INTERNAL_DATE)
             .content(messageContent)
@@ -581,7 +581,7 @@ public class MessageFactoryTest {
             + "Subject: message 1 subject\r\n").getBytes(StandardCharsets.UTF_8));
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(messageContent.read())
             .internalDate(INTERNAL_DATE)
             .content(messageContent)
@@ -613,7 +613,7 @@ public class MessageFactoryTest {
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(messageContent.read())
             .internalDate(INTERNAL_DATE)
             .content(messageContent)
@@ -635,7 +635,7 @@ public class MessageFactoryTest {
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(messageContent.read())
             .internalDate(INTERNAL_DATE)
             .content(messageContent)
@@ -654,7 +654,7 @@ public class MessageFactoryTest {
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(messageContent.read())
             .internalDate(INTERNAL_DATE)
             .content(messageContent)
@@ -678,7 +678,7 @@ public class MessageFactoryTest {
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(messageContent.read())
             .internalDate(INTERNAL_DATE)
             .content(messageContent)
@@ -714,7 +714,7 @@ public class MessageFactoryTest {
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
-            .keywords(Keywords.factory().from(Keyword.SEEN))
+            .keywords(Keywords.strictFactory().from(Keyword.SEEN))
             .size(messageContent.read())
             .internalDate(INTERNAL_DATE)
             .content(messageContent)
@@ -731,7 +731,7 @@ public class MessageFactoryTest {
 
     @Test
     public void keywordShouldBeSetIntoMessage() throws Exception {
-        Keywords keywords = Keywords.factory().from(Keyword.SEEN, Keyword.DRAFT);
+        Keywords keywords = Keywords.strictFactory().from(Keyword.SEEN, Keyword.DRAFT);
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))
@@ -749,7 +749,7 @@ public class MessageFactoryTest {
 
     @Test
     public void keywordWithUserFlagShouldBeSetIntoMessage() throws Exception {
-        Keywords keywords = Keywords.factory().from(Keyword.ANSWERED, Keyword.of(FORWARDED));
+        Keywords keywords = Keywords.strictFactory().from(Keyword.ANSWERED, Keyword.of(FORWARDED));
 
         MetaDataWithContent testMail = MetaDataWithContent.builder()
             .uid(MessageUid.of(2))

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
index 7c92a39..518788b 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
@@ -161,7 +161,7 @@ public class MessageTest {
                 .build();
         ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("blobId"),
simpleMessage);
 
-        Keywords keywords = Keywords.factory()
+        Keywords keywords = Keywords.strictFactory()
             .from(Keyword.DRAFT, Keyword.ANSWERED, Keyword.FLAGGED);
 
         Number messageSize = Number.fromLong(123);

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/OldKeywordTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/OldKeywordTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/OldKeywordTest.java
index 7ef8625..4294dec 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/OldKeywordTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/OldKeywordTest.java
@@ -44,7 +44,7 @@ public class OldKeywordTest {
             .computeOldKeyword();
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from(Keyword.FLAGGED));
+            .isEqualTo(Keywords.strictFactory().from(Keyword.FLAGGED));
     }
 
     @Test
@@ -54,7 +54,7 @@ public class OldKeywordTest {
             .computeOldKeyword();
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from());
+            .isEqualTo(Keywords.strictFactory().from());
     }
 
     @Test
@@ -64,7 +64,7 @@ public class OldKeywordTest {
             .computeOldKeyword();
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from());
+            .isEqualTo(Keywords.strictFactory().from());
     }
 
     @Test
@@ -75,7 +75,7 @@ public class OldKeywordTest {
 
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from(Keyword.SEEN));
+            .isEqualTo(Keywords.strictFactory().from(Keyword.SEEN));
     }
 
     @Test
@@ -85,7 +85,7 @@ public class OldKeywordTest {
             .computeOldKeyword();
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from(Keyword.ANSWERED));
+            .isEqualTo(Keywords.strictFactory().from(Keyword.ANSWERED));
     }
 
     @Test
@@ -95,7 +95,7 @@ public class OldKeywordTest {
             .computeOldKeyword();
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from());
+            .isEqualTo(Keywords.strictFactory().from());
     }
 
     @Test
@@ -105,7 +105,7 @@ public class OldKeywordTest {
             .computeOldKeyword();
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from(Keyword.DRAFT));
+            .isEqualTo(Keywords.strictFactory().from(Keyword.DRAFT));
     }
 
     @Test
@@ -115,7 +115,7 @@ public class OldKeywordTest {
             .computeOldKeyword();
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from());
+            .isEqualTo(Keywords.strictFactory().from());
     }
 
     @Test
@@ -125,7 +125,7 @@ public class OldKeywordTest {
             .computeOldKeyword();
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from(Keyword.FORWARDED));
+            .isEqualTo(Keywords.strictFactory().from(Keyword.FORWARDED));
     }
 
     @Test
@@ -135,7 +135,7 @@ public class OldKeywordTest {
             .computeOldKeyword();
 
         assertThat(testee.get().asKeywords())
-            .isEqualTo(Keywords.factory().from());
+            .isEqualTo(Keywords.strictFactory().from());
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
index 6c6b3db..c807711 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
@@ -74,7 +74,7 @@ public class MailFactoryTest {
         
         message = MetaDataWithContent.builder()
                 .uid(MessageUid.of(2))
-                .keywords(Keywords.factory().from(Keyword.SEEN))
+                .keywords(Keywords.strictFactory().from(Keyword.SEEN))
                 .size(content.length())
                 .internalDate(Instant.now())
                 .sharedContent(new SharedByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)))

http://git-wip-us.apache.org/repos/asf/james-project/blob/e9f48651/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/KeywordsCombinerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/KeywordsCombinerTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/KeywordsCombinerTest.java
index 5acb625..8113f91 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/KeywordsCombinerTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/KeywordsCombinerTest.java
@@ -30,7 +30,7 @@ import com.google.common.collect.ImmutableSet;
 
 public class KeywordsCombinerTest {
 
-    private static final Keywords.KeywordsFactory FACTORY = Keywords.factory();
+    public static final Keywords.KeywordsFactory KEYWORDS_FACTORY = Keywords.lenientFactory();
 
     @Test
     public void applyShouldUnionSeenKeyword() {
@@ -38,8 +38,8 @@ public class KeywordsCombinerTest {
 
         assertThat(keywordsCombiner.apply(
             Keywords.DEFAULT_VALUE,
-            Keywords.factory().from(Keyword.SEEN)))
-            .isEqualTo(Keywords.factory().from(Keyword.SEEN));
+            KEYWORDS_FACTORY.from(Keyword.SEEN)))
+            .isEqualTo(KEYWORDS_FACTORY.from(Keyword.SEEN));
     }
 
     @Test
@@ -48,8 +48,8 @@ public class KeywordsCombinerTest {
 
         assertThat(keywordsCombiner.apply(
             Keywords.DEFAULT_VALUE,
-            Keywords.factory().from(Keyword.ANSWERED)))
-            .isEqualTo(Keywords.factory().from(Keyword.ANSWERED));
+            KEYWORDS_FACTORY.from(Keyword.ANSWERED)))
+            .isEqualTo(KEYWORDS_FACTORY.from(Keyword.ANSWERED));
     }
 
     @Test
@@ -58,8 +58,8 @@ public class KeywordsCombinerTest {
 
         assertThat(keywordsCombiner.apply(
             Keywords.DEFAULT_VALUE,
-            Keywords.factory().from(Keyword.FLAGGED)))
-            .isEqualTo(Keywords.factory().from(Keyword.FLAGGED));
+            KEYWORDS_FACTORY.from(Keyword.FLAGGED)))
+            .isEqualTo(KEYWORDS_FACTORY.from(Keyword.FLAGGED));
     }
 
     @Test
@@ -68,7 +68,7 @@ public class KeywordsCombinerTest {
 
         assertThat(keywordsCombiner.apply(
             Keywords.DEFAULT_VALUE,
-            Keywords.factory().from(Keyword.DRAFT)))
+            KEYWORDS_FACTORY.from(Keyword.DRAFT)))
             .isEqualTo(Keywords.DEFAULT_VALUE);
     }
 
@@ -79,8 +79,8 @@ public class KeywordsCombinerTest {
         Keyword customKeyword = Keyword.of("$Any");
         assertThat(keywordsCombiner.apply(
             Keywords.DEFAULT_VALUE,
-            Keywords.factory().from(customKeyword)))
-            .isEqualTo(Keywords.factory().from(customKeyword));
+            KEYWORDS_FACTORY.from(customKeyword)))
+            .isEqualTo(KEYWORDS_FACTORY.from(customKeyword));
     }
 
     @Test
@@ -98,14 +98,14 @@ public class KeywordsCombinerTest {
         KeywordsCombiner keywordsCombiner = new KeywordsCombiner();
 
         assertThat(keywordsCombiner.apply(
-            Keywords.factory().from(Keyword.FLAGGED),
-            Keywords.factory().from(Keyword.ANSWERED)))
-            .isEqualTo(Keywords.factory().from(Keyword.FLAGGED, Keyword.ANSWERED));
+            KEYWORDS_FACTORY.from(Keyword.FLAGGED),
+            KEYWORDS_FACTORY.from(Keyword.ANSWERED)))
+            .isEqualTo(KEYWORDS_FACTORY.from(Keyword.FLAGGED, Keyword.ANSWERED));
     }
 
     @Test
     public void keywordsCombinerShouldBeCommutative() {
-        Keywords allKeyword = FACTORY.from(Keyword.ANSWERED,
+        Keywords allKeyword = KEYWORDS_FACTORY.from(Keyword.ANSWERED,
             Keyword.DELETED,
             Keyword.DRAFT,
             Keyword.FLAGGED,
@@ -114,14 +114,14 @@ public class KeywordsCombinerTest {
             Keyword.of("$Any"));
 
         ImmutableSet<Keywords> values = ImmutableSet.of(
-            FACTORY.from(Keyword.ANSWERED),
-            FACTORY.from(Keyword.DELETED),
-            FACTORY.from(Keyword.DRAFT),
-            FACTORY.from(Keyword.FLAGGED),
-            FACTORY.from(Keyword.SEEN),
-            FACTORY.from(),
-            FACTORY.from(Keyword.of("$Forwarded")),
-            FACTORY.from(Keyword.of("$Any")),
+            KEYWORDS_FACTORY.from(Keyword.ANSWERED),
+            KEYWORDS_FACTORY.from(Keyword.DELETED),
+            KEYWORDS_FACTORY.from(Keyword.DRAFT),
+            KEYWORDS_FACTORY.from(Keyword.FLAGGED),
+            KEYWORDS_FACTORY.from(Keyword.SEEN),
+            KEYWORDS_FACTORY.from(),
+            KEYWORDS_FACTORY.from(Keyword.of("$Forwarded")),
+            KEYWORDS_FACTORY.from(Keyword.of("$Any")),
             allKeyword);
 
         assertThat(


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