You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/12/12 02:18:44 UTC

[james-project] branch master updated (067e123 -> c2d2a86)

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

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


    from 067e123  JAMES-2717 Avoid restarting ElasticSearch container for each test class
     new 2eb8000  [Refactoring] Logout processor never uses its logger
     new 7c86c9b  [Refactoring] Get rid of ImapSessionUtils
     new 528c0f0  [Refactoring] Stop mocking ImapSession
     new 7c5c883  [Refactoring] Strong typing for IMAP capabilities
     new eb53f49  [Refactoring] Remove unused IMAP constants
     new 4f6b295  [Refactoring] CapabilityResponse: standardize equals and hashCode
     new 8ba4123  [Refactoring] Create a Tika extension for JUnit 5 in mailbox-tika package
     new 44b46e9  [Refactoring] TikaExtension should hold a singleton Docker TikaContainer
     new dbeb318  [Refactoring] Move AbstractMessageSearchIndexTest to JUnit 5
     new 8352f34  [Refactoring] Move MessageToElasticSearchJsonTest to JUnit 5
     new 50d7bc7  [Refactoring] Move IndexableMessageTest to JUnit 5
     new 2d633aa  [Refactoring] Remove TikaContainerSingletonRule
     new 5930a3b  [Refactoring] Move ContentTypeFilteringTextExtractorTest to JUnit 5
     new c35858b  [Refactoring] Move TikaConfigurationTest to JUnit 5
     new c2d2a86  [Refactoring] Move TikaTextExtractorTest to JUnit 5

The 15 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../ElasticSearchIntegrationTest.java              |  68 +++--
 .../elasticsearch/json/IndexableMessageTest.java   |  60 ++--
 .../json/MessageToElasticSearchJsonTest.java       |  75 ++---
 .../search/LuceneMessageSearchIndexTest.java       |  75 +++--
 .../store/search/SimpleMessageSearchIndexTest.java | 161 +++++------
 .../search/AbstractMessageSearchIndexTest.java     | 315 +++++++++++----------
 .../ContentTypeFilteringTextExtractorTest.java     |  14 +-
 .../james/mailbox/tika/TikaConfigurationTest.java  |   6 +-
 .../james/mailbox/tika/TikaContainerSingleton.java |   9 +-
 .../mailbox/tika/TikaContainerSingletonRule.java   |  56 ----
 .../apache/james/mailbox/tika/TikaExtension.java   |  22 +-
 .../james/mailbox/tika/TikaTextExtractorTest.java  |  62 ++--
 .../apache/james/imap/api/ImapConfiguration.java   |  10 +-
 .../org/apache/james/imap/api/ImapConstants.java   |  64 ++---
 .../apache/james/imap/api/ImapSessionUtils.java    |  46 ---
 .../apache/james/imap/api/message/Capability.java  |  26 +-
 .../apache/james/imap/api/process/ImapSession.java |  18 ++
 .../parser/AbstractSelectionCommandParser.java     |   7 +-
 .../imap/decode/parser/CreateCommandParser.java    |   3 +-
 .../imap/decode/parser/EnableCommandParser.java    |  10 +-
 .../imap/encode/CapabilityResponseEncoder.java     |   5 +-
 .../james/imap/encode/EnableResponseEncoder.java   |   7 +-
 .../org/apache/james/imap/main/PathConverter.java  |   7 +-
 .../james/imap/message/request/EnableRequest.java  |   7 +-
 .../imap/message/response/CapabilityResponse.java  |  42 +--
 .../imap/message/response/EnableResponse.java      |   4 +-
 .../imap/processor/AbstractAuthProcessor.java      |   5 +-
 .../imap/processor/AbstractMailboxProcessor.java   |  14 +-
 .../processor/AbstractMessageRangeProcessor.java   |   3 +-
 .../imap/processor/AbstractSelectionProcessor.java |  20 +-
 .../processor/AbstractSubscriptionProcessor.java   |   3 +-
 .../james/imap/processor/AppendProcessor.java      |   5 +-
 .../imap/processor/AuthenticateProcessor.java      |   9 +-
 .../processor/CapabilityImplementingProcessor.java |   3 +-
 .../james/imap/processor/CapabilityProcessor.java  |  15 +-
 .../james/imap/processor/CloseProcessor.java       |   3 +-
 .../james/imap/processor/CompressProcessor.java    |   5 +-
 .../james/imap/processor/CreateProcessor.java      |   3 +-
 .../james/imap/processor/DeleteACLProcessor.java   |   8 +-
 .../james/imap/processor/DeleteProcessor.java      |   3 +-
 .../james/imap/processor/EnableProcessor.java      |  19 +-
 .../james/imap/processor/ExpungeProcessor.java     |  10 +-
 .../james/imap/processor/GetACLProcessor.java      |   8 +-
 .../imap/processor/GetAnnotationProcessor.java     |   8 +-
 .../james/imap/processor/GetQuotaProcessor.java    |   8 +-
 .../imap/processor/GetQuotaRootProcessor.java      |   8 +-
 .../apache/james/imap/processor/IdleProcessor.java |   5 +-
 .../apache/james/imap/processor/LSubProcessor.java |   3 +-
 .../apache/james/imap/processor/ListProcessor.java |   5 +-
 .../james/imap/processor/ListRightsProcessor.java  |   8 +-
 .../james/imap/processor/LoginProcessor.java       |   5 +-
 .../james/imap/processor/LogoutProcessor.java      |   7 +-
 .../apache/james/imap/processor/MoveProcessor.java |   5 +-
 .../james/imap/processor/MyRightsProcessor.java    |   8 +-
 .../james/imap/processor/NamespaceProcessor.java   |  13 +-
 .../processor/PermitEnableCapabilityProcessor.java |   5 +-
 .../james/imap/processor/RenameProcessor.java      |   3 +-
 .../james/imap/processor/SearchProcessor.java      |   8 +-
 .../james/imap/processor/SetACLProcessor.java      |  11 +-
 .../imap/processor/SetAnnotationProcessor.java     |   6 +-
 .../james/imap/processor/SetQuotaProcessor.java    |  16 +-
 .../james/imap/processor/StartTLSProcessor.java    |   5 +-
 .../james/imap/processor/StatusProcessor.java      |   3 +-
 .../james/imap/processor/StoreProcessor.java       |   6 +-
 .../james/imap/processor/SubscribeProcessor.java   |   3 +-
 .../imap/processor/SystemMessageProcessor.java     |   3 +-
 .../james/imap/processor/UnselectProcessor.java    |  12 +-
 .../james/imap/processor/UnsubscribeProcessor.java |   3 +-
 .../james/imap/processor/XListProcessor.java       |   5 +-
 .../imap/processor/base/SelectedMailboxImpl.java   |   5 +-
 .../james/imap/processor/fetch/FetchProcessor.java |   3 +-
 .../imap/processor/fetch/FetchResponseBuilder.java |   3 +-
 .../james/imap/api/ImapConfigurationTest.java      |  11 +-
 ...pSessionUtilsTest.java => ImapSessionTest.java} |  16 +-
 .../james/imap/api/message/CapabilityTest.java     |  23 +-
 .../decode/parser/CreateCommandParserTest.java     |  21 +-
 .../parser/FetchCommandParserPartialFetchTest.java |   4 +-
 .../parser/GetAnnotationCommandParserTest.java     |   3 +-
 .../parser/SearchCommandParserCharsetTest.java     |   7 +-
 .../SearchCommandParserQuotedCharsetTest.java      |   3 +-
 .../imap/encode/NamespaceResponseEncoderTest.java  |   2 +-
 .../ImapRequestHandlerAdandonConnectionTest.java   |   6 +-
 .../apache/james/imap/main/PathConverterTest.java  |  11 +-
 .../imap/processor/CapabilityProcessorTest.java    |   5 +-
 .../james/imap/processor/CopyProcessorTest.java    |  39 ++-
 .../imap/processor/DeleteACLProcessorTest.java     |  14 +-
 .../james/imap/processor/GetACLProcessorTest.java  |  14 +-
 .../imap/processor/GetAnnotationProcessorTest.java |  35 ++-
 .../imap/processor/GetQuotaProcessorTest.java      |  25 +-
 .../imap/processor/GetQuotaRootProcessorTest.java  |  26 +-
 .../james/imap/processor/LSubProcessorTest.java    |   6 +-
 .../imap/processor/ListRightsProcessorTest.java    |  14 +-
 .../james/imap/processor/MoveProcessorTest.java    |  45 ++-
 .../imap/processor/NamespaceProcessorTest.java     |  25 +-
 .../james/imap/processor/SearchProcessorTest.java  |  16 +-
 .../james/imap/processor/SetACLProcessorTest.java  |  14 +-
 .../imap/processor/SetAnnotationProcessorTest.java |  19 +-
 .../imap/processor/SetQuotaProcessorTest.java      |  24 +-
 .../processor/base/MailboxEventAnalyserTest.java   |  11 +-
 .../processor/base/SelectedMailboxImplTest.java    |   9 +-
 .../james/imapserver/netty/IMAPMDCContext.java     |   6 +-
 101 files changed, 868 insertions(+), 1084 deletions(-)
 copy backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/DockerRabbitMQSingleton.java => mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaContainerSingleton.java (86%)
 delete mode 100644 mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaContainerSingletonRule.java
 copy event-sourcing/event-store-memory/src/test/java/org/apache/james/eventsourcing/eventstore/memory/InMemoryEventStoreExtension.java => mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaExtension.java (78%)
 delete mode 100644 protocols/imap/src/main/java/org/apache/james/imap/api/ImapSessionUtils.java
 copy server/blob/blob-api/src/main/java/org/apache/james/blob/api/BucketName.java => protocols/imap/src/main/java/org/apache/james/imap/api/message/Capability.java (77%)
 rename protocols/imap/src/test/java/org/apache/james/imap/api/{ImapSessionUtilsTest.java => ImapSessionTest.java} (78%)
 copy server/blob/blob-api/src/test/java/org/apache/james/blob/api/BucketNameTest.java => protocols/imap/src/test/java/org/apache/james/imap/api/message/CapabilityTest.java (76%)


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


[james-project] 08/15: [Refactoring] TikaExtension should hold a singleton Docker TikaContainer

Posted by bt...@apache.org.
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 44b46e9992fd3ee35ba0e726fae304f7e2440038
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Tue Dec 10 10:27:56 2019 +0700

    [Refactoring] TikaExtension should hold a singleton Docker TikaContainer
---
 .../james/mailbox/tika/TikaContainerSingleton.java | 30 ++++++++++++++++++++++
 .../apache/james/mailbox/tika/TikaExtension.java   | 20 ++-------------
 2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaContainerSingleton.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaContainerSingleton.java
new file mode 100644
index 0000000..6df0e5b
--- /dev/null
+++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaContainerSingleton.java
@@ -0,0 +1,30 @@
+/****************************************************************
+ * 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.mailbox.tika;
+
+public class TikaContainerSingleton {
+    public static final TikaContainer INSTANCE = new TikaContainer();
+
+    static {
+        INSTANCE.start();
+    }
+
+    // Cleanup will be performed by test container resource reaper
+}
diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaExtension.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaExtension.java
index 82f924d..be5809a 100644
--- a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaExtension.java
+++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaExtension.java
@@ -19,29 +19,13 @@
 
 package org.apache.james.mailbox.tika;
 
-import org.junit.jupiter.api.extension.AfterAllCallback;
-import org.junit.jupiter.api.extension.BeforeAllCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 import org.junit.jupiter.api.extension.ParameterContext;
 import org.junit.jupiter.api.extension.ParameterResolutionException;
 import org.junit.jupiter.api.extension.ParameterResolver;
 
-public class TikaExtension implements AfterAllCallback, BeforeAllCallback, ParameterResolver {
-    private final TikaContainer tika;
-
-    public TikaExtension() {
-        this.tika = new TikaContainer();
-    }
-
-    @Override
-    public void beforeAll(ExtensionContext extensionContext) {
-        tika.start();
-    }
-
-    @Override
-    public void afterAll(ExtensionContext extensionContext) {
-        tika.stop();
-    }
+public class TikaExtension implements ParameterResolver {
+    private final TikaContainer tika = TikaContainerSingleton.INSTANCE;
 
     @Override
     public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {


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


[james-project] 13/15: [Refactoring] Move ContentTypeFilteringTextExtractorTest to JUnit 5

Posted by bt...@apache.org.
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 5930a3ba008f2a39169b09770c030cb4db8817c4
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Tue Dec 10 10:41:30 2019 +0700

    [Refactoring] Move ContentTypeFilteringTextExtractorTest to JUnit 5
---
 .../tika/ContentTypeFilteringTextExtractorTest.java        | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/ContentTypeFilteringTextExtractorTest.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/ContentTypeFilteringTextExtractorTest.java
index 95e838f..ebea68c 100644
--- a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/ContentTypeFilteringTextExtractorTest.java
+++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/ContentTypeFilteringTextExtractorTest.java
@@ -31,25 +31,25 @@ import java.nio.charset.StandardCharsets;
 import org.apache.commons.io.IOUtils;
 import org.apache.james.mailbox.extractor.ParsedContent;
 import org.apache.james.mailbox.extractor.TextExtractor;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
 import com.google.common.collect.ImmutableSet;
 
-public class ContentTypeFilteringTextExtractorTest {
+class ContentTypeFilteringTextExtractorTest {
 
     @Mock
     TextExtractor textExtractor;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         MockitoAnnotations.initMocks(this);
     }
 
     @Test
-    public void extractContentReturnEmptyWithContentTypeInBlacklist() throws Exception {
+    void extractContentReturnEmptyWithContentTypeInBlacklist() throws Exception {
         ContentTypeFilteringTextExtractor contentTypeFilteringTextExtractor =
             new ContentTypeFilteringTextExtractor(textExtractor,
                 ImmutableSet.of("application/ics", "application/zip"));
@@ -61,7 +61,7 @@ public class ContentTypeFilteringTextExtractorTest {
     }
 
     @Test
-    public void extractContentCallUnderlyingWithContentTypeNotInBlacklist() throws Exception {
+    void extractContentCallUnderlyingWithContentTypeNotInBlacklist() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/Text.txt");
         ContentTypeFilteringTextExtractor contentTypeFilteringTextExtractor =
             new ContentTypeFilteringTextExtractor(textExtractor,


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


[james-project] 12/15: [Refactoring] Remove TikaContainerSingletonRule

Posted by bt...@apache.org.
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 2d633aa96aff4935691647e6ef4daed9d854110a
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Tue Dec 10 10:38:38 2019 +0700

    [Refactoring] Remove TikaContainerSingletonRule
    
    As we wrote a new Tika extension with a new singleton instance of a Tika container,
    and moved all test classes using the singleton rule to the new extension with JUnit 5,
    we don't need the old singleton rule anymore.
---
 .../mailbox/tika/TikaContainerSingletonRule.java   | 56 ----------------------
 1 file changed, 56 deletions(-)

diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaContainerSingletonRule.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaContainerSingletonRule.java
deleted file mode 100644
index 1fefb78..0000000
--- a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaContainerSingletonRule.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/****************************************************************
- * 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.mailbox.tika;
-
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-public class TikaContainerSingletonRule implements TestRule {
-
-    public static final TikaContainerSingletonRule rule = new TikaContainerSingletonRule(new TikaContainer());
-
-    private final TikaContainer tikaContainer;
-
-    private TikaContainerSingletonRule(TikaContainer tikaContainer) {
-        this.tikaContainer = tikaContainer;
-        this.tikaContainer.start();
-    }
-
-    @Override
-    public Statement apply(Statement statement, Description description) {
-        return statement;
-    }
-
-    public String getIp() {
-        return tikaContainer.getIp();
-    }
-
-    public int getPort() {
-        return tikaContainer.getPort();
-    }
-
-    public int getTimeoutInMillis() {
-        return tikaContainer.getTimeoutInMillis();
-    }
-    
-    // Cleanup will be performed by test container resource reaper
-
-}


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


[james-project] 01/15: [Refactoring] Logout processor never uses its logger

Posted by bt...@apache.org.
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 2eb800079c3b6fb4679e9ac62b3dd2713dd167f2
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Dec 11 10:38:22 2019 +0700

    [Refactoring] Logout processor never uses its logger
---
 .../main/java/org/apache/james/imap/processor/LogoutProcessor.java    | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/LogoutProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/LogoutProcessor.java
index 338f8f3..c0c099a 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/LogoutProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/LogoutProcessor.java
@@ -30,12 +30,8 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class LogoutProcessor extends AbstractMailboxProcessor<LogoutRequest> {
-    private static final Logger LOGGER = LoggerFactory.getLogger(LogoutProcessor.class);
-
     public LogoutProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
         super(LogoutRequest.class, next, mailboxManager, factory, metricFactory);


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


[james-project] 09/15: [Refactoring] Move AbstractMessageSearchIndexTest to JUnit 5

Posted by bt...@apache.org.
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 dbeb318af5616a1a85fa979609447d7a0c24681f
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Dec 6 14:06:17 2019 +0700

    [Refactoring] Move AbstractMessageSearchIndexTest to JUnit 5
    
    With the new Tika extension...
---
 .../ElasticSearchIntegrationTest.java              |  68 +++--
 .../search/LuceneMessageSearchIndexTest.java       |  75 +++--
 .../store/search/SimpleMessageSearchIndexTest.java | 161 +++++------
 .../search/AbstractMessageSearchIndexTest.java     | 315 +++++++++++----------
 4 files changed, 306 insertions(+), 313 deletions(-)

diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index 8643f1b..468f21d 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -25,7 +25,7 @@ import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.time.ZoneId;
 
-import org.apache.james.backends.es.DockerElasticSearchRule;
+import org.apache.james.backends.es.DockerElasticSearchExtension;
 import org.apache.james.backends.es.ElasticSearchIndexer;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
@@ -43,45 +43,34 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.store.search.AbstractMessageSearchIndexTest;
 import org.apache.james.mailbox.tika.TikaConfiguration;
-import org.apache.james.mailbox.tika.TikaContainerSingletonRule;
+import org.apache.james.mailbox.tika.TikaExtension;
 import org.apache.james.mailbox.tika.TikaHttpClientImpl;
 import org.apache.james.mailbox.tika.TikaTextExtractor;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.apache.james.mime4j.dom.Message;
 import org.elasticsearch.client.RestHighLevelClient;
-import org.junit.After;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.google.common.base.Strings;
 
-public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest {
+class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest {
 
-    private static final int BATCH_SIZE = 1;
-    private static final int SEARCH_SIZE = 1;
+    static final int BATCH_SIZE = 1;
+    static final int SEARCH_SIZE = 1;
 
-    @ClassRule
-    public static TikaContainerSingletonRule tika = TikaContainerSingletonRule.rule;
+    @RegisterExtension
+    static TikaExtension tika = new TikaExtension();
 
-    @Rule
-    public DockerElasticSearchRule elasticSearch = new DockerElasticSearchRule();
-    private TikaTextExtractor textExtractor;
-    private RestHighLevelClient client;
+    @RegisterExtension
+    DockerElasticSearchExtension elasticSearch = new DockerElasticSearchExtension();
 
-    @Override
-    public void setUp() throws Exception {
-        textExtractor = new TikaTextExtractor(new NoopMetricFactory(),
-            new TikaHttpClientImpl(TikaConfiguration.builder()
-                .host(tika.getIp())
-                .port(tika.getPort())
-                .timeoutInMillis(tika.getTimeoutInMillis())
-                .build()));
-        super.setUp();
-    }
+    TikaTextExtractor textExtractor;
+    RestHighLevelClient client;
 
-    @After
-    public void tearDown() throws IOException {
+    @AfterEach
+    void tearDown() throws IOException {
         client.close();
     }
 
@@ -91,9 +80,16 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     }
 
     @Override
-    protected void initializeMailboxManager() throws IOException {
+    protected void initializeMailboxManager() throws Exception {
+        textExtractor = new TikaTextExtractor(new NoopMetricFactory(),
+            new TikaHttpClientImpl(TikaConfiguration.builder()
+                .host(tika.getIp())
+                .port(tika.getPort())
+                .timeoutInMillis(tika.getTimeoutInMillis())
+                .build()));
+
         client = MailboxIndexCreationUtil.prepareDefaultClient(
-            elasticSearch.clientProvider().get(),
+            elasticSearch.getDockerElasticSearch().clientProvider().get(),
             elasticSearch.getDockerElasticSearch().configuration());
 
         InMemoryMessageId.Factory messageIdFactory = new InMemoryMessageId.Factory();
@@ -125,7 +121,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     }
 
     @Test
-    public void termsBetweenElasticSearchAndLuceneLimitDueTuNonAsciiCharsShouldBeTruncated() throws Exception {
+    void termsBetweenElasticSearchAndLuceneLimitDueTuNonAsciiCharsShouldBeTruncated() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
         MailboxSession session = MailboxSessionUtil.create(USERNAME);
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
@@ -144,7 +140,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     }
 
     @Test
-    public void tooLongTermsShouldNotMakeIndexingFail() throws Exception {
+    void tooLongTermsShouldNotMakeIndexingFail() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
         MailboxSession session = MailboxSessionUtil.create(USERNAME);
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
@@ -163,7 +159,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     }
 
     @Test
-    public void fieldsExceedingLuceneLimitShouldNotBeIgnored() throws Exception {
+    void fieldsExceedingLuceneLimitShouldNotBeIgnored() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
         MailboxSession session = MailboxSessionUtil.create(USERNAME);
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
@@ -182,7 +178,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     }
 
     @Test
-    public void fieldsWithTooLongTermShouldStillBeIndexed() throws Exception {
+    void fieldsWithTooLongTermShouldStillBeIndexed() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
         MailboxSession session = MailboxSessionUtil.create(USERNAME);
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
@@ -201,7 +197,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     }
 
     @Test
-    public void reasonableLongTermShouldNotBeIgnored() throws Exception {
+    void reasonableLongTermShouldNotBeIgnored() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
         MailboxSession session = MailboxSessionUtil.create(USERNAME);
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
@@ -221,7 +217,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     }
 
     @Test
-    public void headerSearchShouldIncludeMessageWhenDifferentTypesOnAnIndexedField() throws Exception {
+    void headerSearchShouldIncludeMessageWhenDifferentTypesOnAnIndexedField() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
         MailboxSession session = MailboxSessionUtil.create(USERNAME);
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
@@ -245,7 +241,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
     }
 
     @Test
-    public void messageShouldStillBeIndexedEvenAfterOneFieldFailsIndexation() throws Exception {
+    void messageShouldStillBeIndexedEvenAfterOneFieldFailsIndexation() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, INBOX);
         MailboxSession session = MailboxSessionUtil.create(USERNAME);
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
diff --git a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
index 959965f..8e7b4fe 100644
--- a/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
+++ b/mailbox/lucene/src/test/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndexTest.java
@@ -19,17 +19,16 @@
 
 package org.apache.james.mailbox.lucene.search;
 
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.inmemory.InMemoryId;
 import org.apache.james.mailbox.inmemory.InMemoryMessageId;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.store.search.AbstractMessageSearchIndexTest;
 import org.apache.lucene.store.RAMDirectory;
-import org.junit.Ignore;
+import org.junit.jupiter.api.Disabled;
 
 import com.github.fge.lambdas.Throwing;
 
-public class LuceneMessageSearchIndexTest extends AbstractMessageSearchIndexTest {
+class LuceneMessageSearchIndexTest extends AbstractMessageSearchIndexTest {
 
     @Override
     protected void await() {
@@ -56,92 +55,92 @@ public class LuceneMessageSearchIndexTest extends AbstractMessageSearchIndexTest
         messageSearchIndex = resources.getSearchIndex();
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void uidShouldreturnEveryThing() throws Exception {
+    public void uidShouldreturnEveryThing() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnCcShouldWork() throws Exception {
+    public void sortOnCcShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnFromShouldWork() throws Exception {
+    public void sortOnFromShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void orShouldReturnResultsMatchinganyRequests() throws Exception {
+    public void orShouldReturnResultsMatchinganyRequests() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void internalDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
+    public void internalDateBeforeShouldReturnMessagesBeforeAGivenDate() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void internalDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
+    public void internalDateAfterShouldReturnMessagesAfterAGivenDate() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void youShouldBeAbleToSpecifySeveralCriterionOnASingleQuery() throws Exception {
+    public void youShouldBeAbleToSpecifySeveralCriterionOnASingleQuery() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void modSeqLessThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
+    public void modSeqLessThanShouldReturnUidsOfMessageHavingAGreaterModSeq() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void andShouldReturnResultsMatchingBothRequests() throws Exception {
+    public void andShouldReturnResultsMatchingBothRequests() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecified() throws Exception {
+    public void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecified() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void bodyContainsShouldReturnUidOfMessageContainingTheApproximativeText() throws MailboxException {
+    public void bodyContainsShouldReturnUidOfMessageContainingTheApproximativeText() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnDisplayFromShouldWork() throws Exception {
+    public void sortOnDisplayFromShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void mailsContainsShouldIncludeMailHavingAttachmentsMatchingTheRequest() throws Exception {
+    public void mailsContainsShouldIncludeMailHavingAttachmentsMatchingTheRequest() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void modSeqGreaterThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
+    public void modSeqGreaterThanShouldReturnUidsOfMessageHavingAGreaterModSeq() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void modSeqEqualsShouldReturnUidsOfMessageHavingAGivenModSeq() throws Exception {
+    public void modSeqEqualsShouldReturnUidsOfMessageHavingAGivenModSeq() {
     }
 
-    @Ignore
+    @Disabled("MAILBOX-273: failing test on Lucene (intended for ES)")
     @Override
-    public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInTwoMailboxes() throws MailboxException {
+    public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInTwoMailboxes() {
     }
 
-    @Ignore
+    @Disabled("MAILBOX-273: failing test on Lucene (intended for ES)")
     @Override
-    public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInAllMailboxes() throws MailboxException {
+    public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInAllMailboxes() {
     }
 
-    @Ignore("Lucene implementation is not handling mail addresses with names")
+    @Disabled("JAMES-2590: Lucene implementation is not handling mail addresses with names")
     @Override
     public void sortOnToShouldWork() {
     }
diff --git a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
index e44dac6..81dc1de 100644
--- a/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
+++ b/mailbox/scanning-search/src/test/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndexTest.java
@@ -19,11 +19,10 @@
 
 package org.apache.james.mailbox.store.search;
 
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
-import org.junit.Ignore;
+import org.junit.jupiter.api.Disabled;
 
-public class SimpleMessageSearchIndexTest extends AbstractMessageSearchIndexTest {
+class SimpleMessageSearchIndexTest extends AbstractMessageSearchIndexTest {
 
     @Override
     protected void await() {
@@ -50,197 +49,193 @@ public class SimpleMessageSearchIndexTest extends AbstractMessageSearchIndexTest
         messageSearchIndex = resources.getSearchIndex();
     }
 
-    /**
-     * 32 tests out of 54 are failing
-     */
-
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void flagIsSetShouldReturnUidOfMessageMarkedAsRecentWhenUsedWithFlagRecent() throws MailboxException {
+    public void flagIsSetShouldReturnUidOfMessageMarkedAsRecentWhenUsedWithFlagRecent() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void uidShouldreturnEveryThing() throws Exception {
+    public void uidShouldreturnEveryThing() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnCcShouldWork() throws Exception {
+    public void sortOnCcShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnFromShouldWork() throws Exception {
+    public void sortOnFromShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecified() throws Exception {
+    public void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecified() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void orShouldReturnResultsMatchinganyRequests() throws Exception {
+    public void orShouldReturnResultsMatchinganyRequests() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void internalDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
+    public void internalDateBeforeShouldReturnMessagesBeforeAGivenDate() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void headerContainsShouldReturnUidsOfMessageHavingThisHeaderWithTheSpecifiedValue() throws Exception {
+    public void headerContainsShouldReturnUidsOfMessageHavingThisHeaderWithTheSpecifiedValue() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void internalDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
+    public void internalDateAfterShouldReturnMessagesAfterAGivenDate() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void youShouldBeAbleToSpecifySeveralCriterionOnASingleQuery() throws Exception {
+    public void youShouldBeAbleToSpecifySeveralCriterionOnASingleQuery() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void headerExistsShouldReturnUidsOfMessageHavingThisHeader() throws Exception {
+    public void headerExistsShouldReturnUidsOfMessageHavingThisHeader() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void modSeqLessThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
+    public void modSeqLessThanShouldReturnUidsOfMessageHavingAGreaterModSeq() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecified() throws Exception {
+    public void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecified() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void andShouldReturnResultsMatchingBothRequests() throws Exception {
+    public void andShouldReturnResultsMatchingBothRequests() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecified() throws Exception {
+    public void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecified() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnDisplayToShouldWork() throws Exception {
+    public void sortOnDisplayToShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsRecentWhenUsedWithFlagRecent() throws MailboxException {
+    public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsRecentWhenUsedWithFlagRecent() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void bodyContainsShouldReturnUidOfMessageContainingTheApproximativeText() throws MailboxException {
+    public void bodyContainsShouldReturnUidOfMessageContainingTheApproximativeText() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void headerDateBeforeShouldWork() throws Exception {
+    public void headerDateBeforeShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnSentDateShouldWork() throws Exception {
+    public void sortOnSentDateShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void addressShouldReturnUidHavingRightRecipientWhenToIsSpecified() throws Exception {
+    public void addressShouldReturnUidHavingRightRecipientWhenToIsSpecified() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnToShouldWork() throws Exception {
+    public void sortOnToShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnDisplayFromShouldWork() throws Exception {
+    public void sortOnDisplayFromShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void revertSortingShouldReturnElementsInAReversedOrder() throws Exception {
+    public void revertSortingShouldReturnElementsInAReversedOrder() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void headerDateAfterShouldWork() throws Exception {
+    public void headerDateAfterShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void mailsContainsShouldIncludeMailHavingAttachmentsMatchingTheRequest() throws Exception {
+    public void mailsContainsShouldIncludeMailHavingAttachmentsMatchingTheRequest() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnSubjectShouldWork() throws Exception {
+    public void sortOnSubjectShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void modSeqGreaterThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
+    public void modSeqGreaterThanShouldReturnUidsOfMessageHavingAGreaterModSeq() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void notShouldReturnResultsThatDoNotMatchAQuery() throws Exception {
+    public void notShouldReturnResultsThatDoNotMatchAQuery() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void headerDateOnShouldWork() throws Exception {
+    public void headerDateOnShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortOnSizeShouldWork() throws Exception {
+    public void sortOnSizeShouldWork() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1799: ignoring failing test after generalizing ElasticSearch test suite to other mailbox search backends")
     @Override
-    public void sortShouldOrderMessages() throws Exception {
+    public void sortShouldOrderMessages() {
     }
 
-    @Ignore
+    @Disabled("MAILBOX-273: failing test on memory (intended for ES)")
     @Override
-    public void multimailboxSearchShouldReturnUidOfMessageWithExpectedFromInTwoMailboxes() throws MailboxException {
+    public void multimailboxSearchShouldReturnUidOfMessageWithExpectedFromInTwoMailboxes() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1804: failing jmap text search test on memory (intended for ES)")
     @Override
-    public void searchWithTextShouldReturnMailsWhenTextBodyMatchesAndNonContinuousWords() throws Exception {
+    public void searchWithTextShouldReturnMailsWhenTextBodyMatchesAndNonContinuousWords() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1804: failing jmap text search test on memory (intended for ES)")
     @Override
-    public void searchWithTextShouldReturnMailsWhenHtmlBodyMatchesAndNonContinuousWords() throws Exception {
+    public void searchWithTextShouldReturnMailsWhenHtmlBodyMatchesAndNonContinuousWords() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1804: failing jmap text search test on memory (intended for ES)")
     @Override
-    public void searchWithTextShouldReturnMailsWhenTextBodyWithExtraUnindexedWords() throws Exception {
+    public void searchWithTextShouldReturnMailsWhenTextBodyWithExtraUnindexedWords() {
     }
 
-    @Ignore
+    @Disabled("JAMES-1804: failing jmap text search test on memory (intended for ES)")
     @Override
-    public void searchWithTextShouldReturnMailsWhenHtmlBodyMatchesWithStemming() throws Exception {
+    public void searchWithTextShouldReturnMailsWhenHtmlBodyMatchesWithStemming() {
     }
 
-    @Ignore
+    @Disabled("JAMES-2241: memory does not handle header with dots indexation (intended for ES)")
     @Override
-    public void headerWithDotsShouldBeIndexed() throws MailboxException {
+    public void headerWithDotsShouldBeIndexed() {
     }
 }
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
index bf7d4e1..8271602 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
@@ -21,6 +21,8 @@
 package org.apache.james.mailbox.store.search;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
 
 import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
@@ -60,22 +62,21 @@ import org.apache.james.mime4j.message.SingleBodyBuilder;
 import org.apache.james.util.ClassLoaderUtils;
 import org.awaitility.Awaitility;
 import org.awaitility.Duration;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import com.google.common.collect.ImmutableList;
 
 public abstract class AbstractMessageSearchIndexTest {
 
+    private static final long LIMIT = 100L;
+    private static final boolean RECENT = true;
+    private static final boolean NOT_RECENT = false;
+
     protected static final String INBOX = "INBOX";
     protected static final Username OTHERUSER = Username.of("otheruser");
     protected static final Username USERNAME = Username.of("benwa");
 
-    public static final long LIMIT = 100L;
-    public static final boolean RECENT = true;
-    public static final boolean NOT_RECENT = false;
-
     protected MessageSearchIndex messageSearchIndex;
     protected StoreMailboxManager storeMailboxManager;
     protected MessageIdManager messageIdManager;
@@ -104,8 +105,8 @@ public abstract class AbstractMessageSearchIndexTest {
     private StoreMessageManager inboxMessageManager;
 
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    protected void setUp() throws Exception {
         initializeMailboxManager();
 
         session = storeMailboxManager.createSystemSession(USERNAME);
@@ -233,8 +234,8 @@ public abstract class AbstractMessageSearchIndexTest {
     protected abstract void initializeMailboxManager() throws Exception;
 
     @Test
-    public void searchingMessageInMultipleMailboxShouldNotReturnTwiceTheSameMessage() throws MailboxException {
-        Assume.assumeTrue(messageIdManager != null);
+    void searchingMessageInMultipleMailboxShouldNotReturnTwiceTheSameMessage() throws MailboxException {
+        assumeTrue(messageIdManager != null);
 
         messageIdManager.setInMailboxes(m4.getMessageId(),
             ImmutableList.of(mailbox.getMailboxId(), mailbox2.getMailboxId()),
@@ -266,8 +267,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchingMessageInMultipleMailboxShouldUnionOfTheTwoMailbox() throws MailboxException {
-        Assume.assumeTrue(messageIdManager != null);
+    void searchingMessageInMultipleMailboxShouldUnionOfTheTwoMailbox() throws MailboxException {
+        assumeTrue(messageIdManager != null);
         messageIdManager.setInMailboxes(m4.getMessageId(),
             ImmutableList.of(mailbox2.getMailboxId()),
             session);
@@ -297,8 +298,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchingMessageInMultipleMailboxShouldNotReturnLessMessageThanLimitArgument() throws MailboxException {
-        Assume.assumeTrue(messageIdManager != null);
+    void searchingMessageInMultipleMailboxShouldNotReturnLessMessageThanLimitArgument() throws MailboxException {
+        assumeTrue(messageIdManager != null);
         messageIdManager.setInMailboxes(m1.getMessageId(), ImmutableList.of(mailbox.getMailboxId(), mailbox2.getMailboxId()), session);
         messageIdManager.setInMailboxes(m2.getMessageId(), ImmutableList.of(mailbox.getMailboxId(), mailbox2.getMailboxId()), session);
         messageIdManager.setInMailboxes(m3.getMessageId(), ImmutableList.of(mailbox.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -322,7 +323,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void whenEmptyListOfMailboxGivenSearchShouldReturnEmpty() throws MailboxException {
+    void whenEmptyListOfMailboxGivenSearchShouldReturnEmpty() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery();
 
         List<MessageId> result = messageSearchIndex.search(session,
@@ -335,8 +336,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchingMessageInMultipleMailboxShouldNotReturnLessMessageThanLimitArgumentEvenIfDuplicatedMessageAreBeforeLegitimeMessage() throws MailboxException {
-        Assume.assumeTrue(messageIdManager != null);
+    void searchingMessageInMultipleMailboxShouldNotReturnLessMessageThanLimitArgumentEvenIfDuplicatedMessageAreBeforeLegitimeMessage() throws MailboxException {
+        assumeTrue(messageIdManager != null);
         messageIdManager.setInMailboxes(m1.getMessageId(), ImmutableList.of(mailbox.getMailboxId(), mailbox2.getMailboxId()), session);
 
         SearchQuery searchQuery = new SearchQuery();
@@ -358,23 +359,25 @@ public abstract class AbstractMessageSearchIndexTest {
                 .hasSize(limit);
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void searchShouldThrowWhenSessionIsNull() throws MailboxException {
+    @Test
+    void searchShouldThrowWhenSessionIsNull() {
         SearchQuery searchQuery = new SearchQuery();
         MailboxSession session = null;
-        assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
-            .isEmpty();
+        
+        assertThatThrownBy(() -> messageSearchIndex.search(session, mailbox, searchQuery))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void emptySearchQueryShouldReturnAllUids() throws MailboxException {
+    void emptySearchQueryShouldReturnAllUids() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery();
+        
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
             .containsOnly(m1.getUid(), m2.getUid(), m3.getUid(), m4.getUid(), m5.getUid(), m6.getUid(), m7.getUid(), m8.getUid(), m9.getUid());
     }
 
     @Test
-    public void allShouldReturnAllUids() throws MailboxException {
+    void allShouldReturnAllUids() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -382,7 +385,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void bodyContainsShouldReturnUidOfMessageContainingTheGivenText() throws MailboxException {
+    void bodyContainsShouldReturnUidOfMessageContainingTheGivenText() throws MailboxException {
         /* Only mail4.eml contains word MAILET-94 */
         SearchQuery searchQuery = new SearchQuery(SearchQuery.bodyContains("MAILET-94"));
 
@@ -391,7 +394,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void bodyContainsShouldReturnUidOfMessageContainingTheApproximativeText() throws MailboxException {
+    protected void bodyContainsShouldReturnUidOfMessageContainingTheApproximativeText() throws MailboxException {
         /* mail1.eml contains words created AND summary
            mail.eml contains created and thus matches the query with a low score */
         SearchQuery searchQuery = new SearchQuery(SearchQuery.bodyContains("created summary"));
@@ -401,7 +404,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void hasAttachmentShouldOnlyReturnMessageThatHasAttachmentWhichAreNotInline() throws MailboxException {
+    void hasAttachmentShouldOnlyReturnMessageThatHasAttachmentWhichAreNotInline() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.hasAttachment());
 
         assertThat(messageSearchIndex.search(session, mailbox2, searchQuery))
@@ -409,7 +412,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void messageWithDotsInHeaderShouldBeIndexed() throws MailboxException {
+    void messageWithDotsInHeaderShouldBeIndexed() throws MailboxException {
 
         ComposedMessageId mailWithDotsInHeader = myFolderMessageManager.appendMessage(
             MessageManager.AppendCommand.builder()
@@ -424,7 +427,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void headerWithDotsShouldBeIndexed() throws MailboxException {
+    void headerWithDotsShouldBeIndexed() throws MailboxException {
 
         ComposedMessageId mailWithDotsInHeader = myFolderMessageManager.appendMessage(
             MessageManager.AppendCommand.builder()
@@ -439,8 +442,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchShouldBeExactOnEmailAddresses() throws MailboxException {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchShouldBeExactOnEmailAddresses() throws MailboxException {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
 
         ComposedMessageId m11 = inboxMessageManager.appendMessage(
             MessageManager.AppendCommand.builder()
@@ -465,7 +468,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void hasNoAttachmenShouldOnlyReturnMessageThatHasNoAttachmentWhichAreNotInline() throws MailboxException {
+    void hasNoAttachmenShouldOnlyReturnMessageThatHasNoAttachmentWhichAreNotInline() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.hasNoAttachment());
 
         assertThat(messageSearchIndex.search(session, mailbox2, searchQuery))
@@ -473,7 +476,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsSetShouldReturnUidOfMessageMarkedAsDeletedWhenUsedWithFlagDeleted() throws MailboxException {
+    void flagIsSetShouldReturnUidOfMessageMarkedAsDeletedWhenUsedWithFlagDeleted() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.DELETED));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -481,7 +484,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsSetShouldReturnUidOfMessageMarkedAsAnsweredWhenUsedWithFlagAnswered() throws MailboxException {
+    void flagIsSetShouldReturnUidOfMessageMarkedAsAnsweredWhenUsedWithFlagAnswered() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.ANSWERED));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -489,7 +492,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsSetShouldReturnUidOfMessageMarkedAsDraftWhenUsedWithFlagDraft() throws MailboxException {
+    void flagIsSetShouldReturnUidOfMessageMarkedAsDraftWhenUsedWithFlagDraft() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.DRAFT));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -497,7 +500,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsSetShouldReturnUidOfMessageMarkedAsRecentWhenUsedWithFlagRecent() throws MailboxException {
+    void flagIsSetShouldReturnUidOfMessageMarkedAsRecentWhenUsedWithFlagRecent() throws MailboxException {
         // Only message 7 is not marked as RECENT
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.RECENT));
 
@@ -506,7 +509,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsSetShouldReturnUidOfMessageMarkedAsFlaggedWhenUsedWithFlagFlagged() throws MailboxException {
+    void flagIsSetShouldReturnUidOfMessageMarkedAsFlaggedWhenUsedWithFlagFlagged() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.FLAGGED));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -514,7 +517,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsSetShouldReturnUidOfMessageMarkedAsSeenWhenUsedWithFlagSeen() throws MailboxException {
+    void flagIsSetShouldReturnUidOfMessageMarkedAsSeenWhenUsedWithFlagSeen() throws MailboxException {
         // Only message 6 is marked as read.
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
 
@@ -523,7 +526,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchShouldReturnSeenMessagesWhenFlagsGotUpdated() throws MailboxException {
+    void searchShouldReturnSeenMessagesWhenFlagsGotUpdated() throws MailboxException {
         inboxMessageManager.setFlags(
             new Flags(Flags.Flag.SEEN),
             MessageManager.FlagsUpdateMode.ADD,
@@ -539,7 +542,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
     
     @Test
-    public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInAllMailboxes() throws MailboxException {
+    protected void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInAllMailboxes() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
 
         List<MessageId> actual = messageSearchIndex.search(
@@ -552,7 +555,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInOneMailbox() throws MailboxException {
+    void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInOneMailbox() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
 
         List<MessageId> actual = messageSearchIndex.search(session, ImmutableList.of(mailbox.getMailboxId()), searchQuery, LIMIT);
@@ -561,7 +564,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void multimailboxSearchShouldReturnUidOfMessageWithExpectedFromInTwoMailboxes() throws MailboxException {
+    void multimailboxSearchShouldReturnUidOfMessageWithExpectedFromInTwoMailboxes() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.address(AddressType.From, "murari"));
 
         List<MessageId> actual = messageSearchIndex.search(
@@ -574,7 +577,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInTwoMailboxes() throws MailboxException {
+    protected void multimailboxSearchShouldReturnUidOfMessageMarkedAsSeenInTwoMailboxes() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
 
         List<MessageId> actual = messageSearchIndex.search(
@@ -587,7 +590,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void multimailboxSearchShouldLimitTheSize() throws MailboxException {
+    void multimailboxSearchShouldLimitTheSize() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet(Flags.Flag.SEEN));
 
         long limit = 1;
@@ -602,8 +605,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void multimailboxSearchShouldWorkWithOtherUserMailbox() throws  MailboxException {
-        Assume.assumeTrue(storeMailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL));
+    void multimailboxSearchShouldWorkWithOtherUserMailbox() throws  MailboxException {
+        assumeTrue(storeMailboxManager.hasCapability(MailboxManager.MailboxCapabilities.ACL));
         SearchQuery searchQuery = new SearchQuery();
 
         long limit = 256;
@@ -618,7 +621,7 @@ public abstract class AbstractMessageSearchIndexTest {
 
 
     @Test
-    public void flagIsSetShouldReturnUidsOfMessageContainingAGivenUserFlag() throws MailboxException {
+    void flagIsSetShouldReturnUidsOfMessageContainingAGivenUserFlag() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet("Hello"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -626,7 +629,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void userFlagsShouldBeMatchedExactly() throws MailboxException {
+    void userFlagsShouldBeMatchedExactly() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsSet("Hello bonjour"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -634,7 +637,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsDeletedWhenUsedWithFlagDeleted() throws MailboxException {
+    void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsDeletedWhenUsedWithFlagDeleted() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.DELETED));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -642,7 +645,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsAnsweredWhenUsedWithFlagAnswered() throws MailboxException {
+    void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsAnsweredWhenUsedWithFlagAnswered() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.ANSWERED));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -650,7 +653,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsDraftWhenUsedWithFlagDraft() throws MailboxException {
+    void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsDraftWhenUsedWithFlagDraft() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.DRAFT));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -658,7 +661,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsRecentWhenUsedWithFlagRecent() throws MailboxException {
+    void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsRecentWhenUsedWithFlagRecent() throws MailboxException {
         // Only message 7 is not marked as RECENT
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.RECENT));
 
@@ -667,7 +670,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsFlaggedWhenUsedWithFlagFlagged() throws MailboxException {
+    void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsFlaggedWhenUsedWithFlagFlagged() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.FLAGGED));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -675,7 +678,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsSeenWhenUsedWithFlagSeen() throws MailboxException {
+    void flagIsUnSetShouldReturnUidOfMessageNotMarkedAsSeenWhenUsedWithFlagSeen() throws MailboxException {
         // Only message 6 is marked as read.
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet(Flags.Flag.SEEN));
 
@@ -684,7 +687,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void flagIsUnSetShouldReturnUidsOfMessageNotContainingAGivenUserFlag() throws MailboxException {
+    void flagIsUnSetShouldReturnUidsOfMessageNotContainingAGivenUserFlag() throws MailboxException {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.flagIsUnSet("Hello"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -692,7 +695,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void internalDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
+    protected void internalDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.internalDateAfter(
             new Date(1404252000000L),
             DateResolution.Day));
@@ -703,7 +706,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void internalDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
+    protected void internalDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.internalDateBefore(
             new Date(1391295600000L),
             DateResolution.Day));
@@ -714,7 +717,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void internalDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
+    void internalDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.internalDateOn(
             new Date(1393714800000L),
             DateResolution.Day));
@@ -725,7 +728,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sentDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
+    void sentDateAfterShouldReturnMessagesAfterAGivenDate() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.sentDateAfter(
             new Date(1433408400000L),
             DateResolution.Second));
@@ -737,7 +740,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sentDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
+    void sentDateBeforeShouldReturnMessagesBeforeAGivenDate() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.sentDateBefore(
             new Date(1433109600000L),
             DateResolution.Day));
@@ -749,7 +752,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sentDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
+    void sentDateOnShouldReturnMessagesOfTheGivenDate() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.sentDateOn(
             new Date(1433224800000L),
             DateResolution.Day));
@@ -761,7 +764,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void modSeqEqualsShouldReturnUidsOfMessageHavingAGivenModSeq() throws Exception {
+    protected void modSeqEqualsShouldReturnUidsOfMessageHavingAGivenModSeq() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.modSeqEquals(2L));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -769,7 +772,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void modSeqGreaterThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
+    protected void modSeqGreaterThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.modSeqGreaterThan(7L));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -777,7 +780,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void modSeqLessThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
+    protected void modSeqLessThanShouldReturnUidsOfMessageHavingAGreaterModSeq() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.modSeqLessThan(3L));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -785,7 +788,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sizeGreaterThanShouldReturnUidsOfMessageExceedingTheSpecifiedSize() throws Exception {
+    void sizeGreaterThanShouldReturnUidsOfMessageExceedingTheSpecifiedSize() throws Exception {
         // Only message 6 is over 6.8 KB
         SearchQuery searchQuery = new SearchQuery(SearchQuery.sizeGreaterThan(6800L));
 
@@ -794,7 +797,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sizeLessThanShouldReturnUidsOfMessageNotExceedingTheSpecifiedSize() throws Exception {
+    void sizeLessThanShouldReturnUidsOfMessageNotExceedingTheSpecifiedSize() throws Exception {
         // Only message 2 3 4 5 7 9 are under 5 KB
         SearchQuery searchQuery = new SearchQuery(SearchQuery.sizeLessThan(5000L));
 
@@ -803,7 +806,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void headerContainsShouldReturnUidsOfMessageHavingThisHeaderWithTheSpecifiedValue() throws Exception {
+    void headerContainsShouldReturnUidsOfMessageHavingThisHeaderWithTheSpecifiedValue() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.headerContains("Precedence", "list"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -811,7 +814,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void headerExistsShouldReturnUidsOfMessageHavingThisHeader() throws Exception {
+    void headerExistsShouldReturnUidsOfMessageHavingThisHeader() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.headerExists("Precedence"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -819,7 +822,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecified() throws Exception {
+    protected void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecified() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.address(AddressType.From, "murari.ksr@gmail.com"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -827,8 +830,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecifiedWithOnlyUserPartOfEmail() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecifiedWithOnlyUserPartOfEmail() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -839,8 +842,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecifiedWithDomainPartOfEmail() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightExpeditorWhenFromIsSpecifiedWithDomainPartOfEmail() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -851,8 +854,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnTheRightUidOfTheMessageContainingUTF8EncodingToHeaderName() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnTheRightUidOfTheMessageContainingUTF8EncodingToHeaderName() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -863,7 +866,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightRecipientWhenToIsSpecified() throws Exception {
+    void addressShouldReturnUidHavingRightRecipientWhenToIsSpecified() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.address(AddressType.To, "root@listes.minet.net"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -871,8 +874,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightRecipientWhenToIsSpecifiedWithOnlyEmailUserPart() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightRecipientWhenToIsSpecifiedWithOnlyEmailUserPart() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -883,8 +886,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightRecipientWhenToIsSpecifiedWithOnlyDomainPartSpecified() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightRecipientWhenToIsSpecifiedWithOnlyDomainPartSpecified() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -895,8 +898,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecified() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecified() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -906,8 +909,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecifiedWithOnlyUserPartOfTheEmail() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecifiedWithOnlyUserPartOfTheEmail() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -917,8 +920,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecifiedWithOnlyDomainPartOfTheEmail() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightRecipientWhenCcIsSpecifiedWithOnlyDomainPartOfTheEmail() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -928,8 +931,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecifiedWithOnlyUserPartOfTheEmail() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecifiedWithOnlyUserPartOfTheEmail() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -940,8 +943,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecifiedWithOnlyDomainPartOfTheEmail() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecifiedWithOnlyDomainPartOfTheEmail() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -951,8 +954,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecified() throws Exception {
-        Assume.assumeTrue(storeMailboxManager
+    void addressShouldReturnUidHavingRightRecipientWhenBccIsSpecified() throws Exception {
+        assumeTrue(storeMailboxManager
             .getSupportedSearchCapabilities()
             .contains(MailboxManager.SearchCapabilities.PartialEmailMatch));
 
@@ -963,7 +966,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void uidShouldreturnExistingUidsOnTheGivenRanges() throws Exception {
+    void uidShouldreturnExistingUidsOnTheGivenRanges() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m4.getUid()), new SearchQuery.UidRange(m6.getUid(), m7.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
 
@@ -972,7 +975,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void uidShouldreturnEveryThing() throws Exception {
+    protected void uidShouldreturnEveryThing() throws Exception {
         SearchQuery.UidRange[] numericRanges = {};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
 
@@ -981,7 +984,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void youShouldBeAbleToSpecifySeveralCriterionOnASingleQuery() throws Exception {
+    protected void youShouldBeAbleToSpecifySeveralCriterionOnASingleQuery() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.headerExists("Precedence"));
         searchQuery.andCriteria(SearchQuery.modSeqGreaterThan(6L));
@@ -991,7 +994,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void andShouldReturnResultsMatchingBothRequests() throws Exception {
+    protected void andShouldReturnResultsMatchingBothRequests() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.and(
             SearchQuery.headerExists("Precedence"),
             SearchQuery.modSeqGreaterThan(6L)));
@@ -1001,7 +1004,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void orShouldReturnResultsMatchinganyRequests() throws Exception {
+    protected void orShouldReturnResultsMatchinganyRequests() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m4.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.or(
             SearchQuery.uid(numericRanges),
@@ -1012,7 +1015,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void notShouldReturnResultsThatDoNotMatchAQuery() throws Exception {
+    void notShouldReturnResultsThatDoNotMatchAQuery() throws Exception {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.not(SearchQuery.headerExists("Precedence")));
 
@@ -1021,7 +1024,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortShouldOrderMessages() throws Exception {
+    void sortShouldOrderMessages() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival)));
 
@@ -1030,7 +1033,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void revertSortingShouldReturnElementsInAReversedOrder() throws Exception {
+    void revertSortingShouldReturnElementsInAReversedOrder() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival, Order.REVERSE)));
 
@@ -1039,7 +1042,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void headerDateAfterShouldWork() throws Exception {
+    void headerDateAfterShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.headerDateAfter("sentDate", new Date(1433408400000L), DateResolution.Second));
         // Date : 2015/06/04 11:00:00.000 ( Paris time zone )
@@ -1050,7 +1053,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void headerDateBeforeShouldWork() throws Exception {
+    void headerDateBeforeShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.headerDateBefore("sentDate", new Date(1433109600000L), DateResolution.Day));
         // Date : 2015/06/01 00:00:00.000 ( Paris time zone )
@@ -1061,7 +1064,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void headerDateOnShouldWork() throws Exception {
+    void headerDateOnShouldWork() throws Exception {
         SearchQuery searchQuery = new SearchQuery(
             SearchQuery.headerDateOn("sentDate", new Date(1433224800000L), DateResolution.Day));
         // Date : 2015/06/02 08:00:00.000 ( Paris time zone )
@@ -1072,7 +1075,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void mailsContainsShouldIncludeMailHavingAttachmentsMatchingTheRequest() throws Exception {
+    protected void mailsContainsShouldIncludeMailHavingAttachmentsMatchingTheRequest() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.mailContains("root mailing list"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1080,7 +1083,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortOnCcShouldWork() throws Exception {
+    protected void sortOnCcShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.MailboxCc)));
@@ -1094,7 +1097,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortOnFromShouldWork() throws Exception {
+    protected void sortOnFromShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.MailboxFrom)));
@@ -1108,7 +1111,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortOnToShouldWork() throws Exception {
+    protected void sortOnToShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.MailboxTo)));
@@ -1122,7 +1125,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortOnSubjectShouldWork() throws Exception {
+    void sortOnSubjectShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.BaseSubject)));
@@ -1136,7 +1139,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortOnSizeShouldWork() throws Exception {
+    void sortOnSizeShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Size)));
@@ -1150,7 +1153,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortOnDisplayFromShouldWork() throws Exception {
+    protected void sortOnDisplayFromShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.DisplayFrom)));
@@ -1164,7 +1167,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortOnDisplayToShouldWork() throws Exception {
+    void sortOnDisplayToShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.DisplayTo)));
@@ -1178,7 +1181,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortOnSentDateShouldWork() throws Exception {
+    void sortOnSentDateShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.SentDate)));
@@ -1192,7 +1195,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortOnIdShouldWork() throws Exception {
+    void sortOnIdShouldWork() throws Exception {
         SearchQuery.UidRange[] numericRanges = {new SearchQuery.UidRange(m2.getUid(), m5.getUid())};
         SearchQuery searchQuery = new SearchQuery(SearchQuery.uid(numericRanges));
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Uid)));
@@ -1202,8 +1205,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnNoMailWhenNotMatching() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnNoMailWhenNotMatching() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("unmatching"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1211,8 +1214,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenFromMatches() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenFromMatches() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("spam.minet.net"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1220,8 +1223,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenMatches() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenMatches() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("root@listes.minet.net"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1229,8 +1232,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenToIsNotAnExactMatches() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenToIsNotAnExactMatches() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("root"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1238,8 +1241,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenCcMatches() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenCcMatches() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("abc@abc.org"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1247,8 +1250,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenCcIsNotAExactMatch() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenCcIsNotAExactMatch() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("monkey"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1256,8 +1259,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenBccMatches() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenBccMatches() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("monkey@any.com"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1265,8 +1268,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenBccIsNotAExactMatch() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenBccIsNotAExactMatch() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("monkey"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1274,8 +1277,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenTextBodyMatches() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenTextBodyMatches() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("reviewing work"));
 
         // text/plain contains: "We are reviewing work I did for this feature."
@@ -1284,8 +1287,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenTextBodyMatchesAndNonContinuousWords() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenTextBodyMatchesAndNonContinuousWords() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("reviewing feature"));
         // 2: text/plain contains: "Issue Type: New Feature"
         // 3: text/plain contains: "We are reviewing work I did for this feature."
@@ -1295,8 +1298,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenTextBodyMatchesInsensitiveWords() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenTextBodyMatchesInsensitiveWords() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("reVieWing"));
         // text/plain contains: "We are reviewing work I did for this feature."
 
@@ -1305,8 +1308,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenTextBodyWithExtraUnindexedWords() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenTextBodyWithExtraUnindexedWords() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("a reviewing of the work"));
         // text/plain contains: "We are reviewing work I did for this feature."
 
@@ -1315,8 +1318,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenHtmlBodyMatches() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenHtmlBodyMatches() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("contains a banana"));
         // text/html contains: "This is a mail with beautifull html content which contains a banana."
 
@@ -1325,8 +1328,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenHtmlBodyMatchesWithStemming() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenHtmlBodyMatchesWithStemming() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("contain banana"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1334,8 +1337,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextShouldReturnMailsWhenHtmlBodyMatchesAndNonContinuousWords() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
+    void searchWithTextShouldReturnMailsWhenHtmlBodyMatchesAndNonContinuousWords() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
         SearchQuery searchQuery = new SearchQuery(SearchQuery.textContains("beautifull banana"));
 
         assertThat(messageSearchIndex.search(session, mailbox, searchQuery))
@@ -1343,8 +1346,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithFullTextShouldReturnMailsWhenNotAPerfectMatch() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.FullText));
+    void searchWithFullTextShouldReturnMailsWhenNotAPerfectMatch() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.FullText));
         ComposedMessageId messageWithBeautifulBananaAsTextAttachment = myFolderMessageManager.appendMessage(
             MessageManager.AppendCommand.builder()
             .build(ClassLoader.getSystemResourceAsStream("eml/emailWithTextAttachment.eml")),
@@ -1358,8 +1361,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithTextAttachmentShouldReturnMailsWhenAttachmentContentMatches() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Attachment));
+    void searchWithTextAttachmentShouldReturnMailsWhenAttachmentContentMatches() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Attachment));
         ComposedMessageId messageWithBeautifulBananaAsTextAttachment = myFolderMessageManager.appendMessage(
             MessageManager.AppendCommand.builder()
                 .build(ClassLoader.getSystemResourceAsStream("eml/emailWithTextAttachment.eml")),
@@ -1373,8 +1376,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchWithPDFAttachmentShouldReturnMailsWhenAttachmentContentMatches() throws Exception {
-        Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Attachment));
+    void searchWithPDFAttachmentShouldReturnMailsWhenAttachmentContentMatches() throws Exception {
+        assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Attachment));
         byte[] attachmentContent = ClassLoaderUtils.getSystemResourceAsByteArray("eml/attachment.pdf");
         Multipart multipart = MultipartBuilder.create("mixed")
                 .addBodyPart(BodyPartBuilder.create()
@@ -1397,7 +1400,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void sortShouldNotDiscardResultWhenSearchingFieldIsIdentical() throws Exception {
+    void sortShouldNotDiscardResultWhenSearchingFieldIsIdentical() throws Exception {
         SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
         searchQuery.setSorts(ImmutableList.of(new Sort(SortClause.Arrival)));
 
@@ -1412,7 +1415,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchShouldOrderByInternalDateWhenSortOnSentDateAndNoCorrespondingHeader() throws Exception {
+    void searchShouldOrderByInternalDateWhenSortOnSentDateAndNoCorrespondingHeader() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "sentDate");
         storeMailboxManager.createMailbox(mailboxPath, session);
 
@@ -1452,7 +1455,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchShouldOrderBySentDateThenInternalDateWhenSortOnSentDateAndNonHomogeneousCorrespondingHeader() throws Exception {
+    void searchShouldOrderBySentDateThenInternalDateWhenSortOnSentDateAndNonHomogeneousCorrespondingHeader() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "sentDate");
         storeMailboxManager.createMailbox(mailboxPath, session);
 
@@ -1492,7 +1495,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchShouldRetrieveExactlyMatchingMimeMessageID() throws Exception {
+    void searchShouldRetrieveExactlyMatchingMimeMessageID() throws Exception {
         SearchQuery searchQuery = new SearchQuery();
         searchQuery.andCriteria(SearchQuery.mimeMessageID("<JI...@Atlassian.JIRA>"));
         // Correspond to mail.eml
@@ -1502,7 +1505,7 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void copiedMessageShouldAllBeIndexed() throws Exception {
+    void copiedMessageShouldAllBeIndexed() throws Exception {
         MailboxPath newBoxPath = MailboxPath.forUser(USERNAME, "newBox");
         MailboxId newBoxId = storeMailboxManager.createMailbox(newBoxPath, session).get();
 
@@ -1523,8 +1526,8 @@ public abstract class AbstractMessageSearchIndexTest {
     }
 
     @Test
-    public void searchShouldRetrieveMailByAttachmentFileName() throws Exception {
-        Assume.assumeTrue(messageSearchIndex.getSupportedCapabilities(storeMailboxManager.getSupportedMessageCapabilities())
+    void searchShouldRetrieveMailByAttachmentFileName() throws Exception {
+        assumeTrue(messageSearchIndex.getSupportedCapabilities(storeMailboxManager.getSupportedMessageCapabilities())
             .contains(MailboxManager.SearchCapabilities.AttachmentFileName));
 
         String fileName = "matchme.txt";


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


[james-project] 10/15: [Refactoring] Move MessageToElasticSearchJsonTest to JUnit 5

Posted by bt...@apache.org.
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 8352f34096e46f21b4112f43ee23f94ae98131a5
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Mon Dec 9 11:36:12 2019 +0700

    [Refactoring] Move MessageToElasticSearchJsonTest to JUnit 5
    
    With the new Tika extension...
---
 .../json/MessageToElasticSearchJsonTest.java       | 75 +++++++++++-----------
 1 file changed, 38 insertions(+), 37 deletions(-)

diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java
index 81f3d20..ed214bf 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java
@@ -46,36 +46,35 @@ import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.apache.james.mailbox.tika.TikaConfiguration;
-import org.apache.james.mailbox.tika.TikaContainerSingletonRule;
+import org.apache.james.mailbox.tika.TikaExtension;
 import org.apache.james.mailbox.tika.TikaHttpClientImpl;
 import org.apache.james.mailbox.tika.TikaTextExtractor;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.apache.james.util.ClassLoaderUtils;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.google.common.collect.ImmutableList;
 
-public class MessageToElasticSearchJsonTest {
-    private static final int SIZE = 25;
-    private static final int BODY_START_OCTET = 100;
-    private static final TestId MAILBOX_ID = TestId.of(18L);
-    private static final MessageId MESSAGE_ID = TestMessageId.of(184L);
-    private static final ModSeq MOD_SEQ = ModSeq.of(42L);
-    private static final MessageUid UID = MessageUid.of(25);
-    private static final Username USERNAME = Username.of("username");
+class MessageToElasticSearchJsonTest {
+    static final int SIZE = 25;
+    static final int BODY_START_OCTET = 100;
+    static final TestId MAILBOX_ID = TestId.of(18L);
+    static final MessageId MESSAGE_ID = TestMessageId.of(184L);
+    static final ModSeq MOD_SEQ = ModSeq.of(42L);
+    static final MessageUid UID = MessageUid.of(25);
+    static final Username USERNAME = Username.of("username");
 
-    private TextExtractor textExtractor;
+    TextExtractor textExtractor;
+    Date date;
+    PropertyBuilder propertyBuilder;
 
-    private Date date;
-    private PropertyBuilder propertyBuilder;
+    @RegisterExtension
+    static TikaExtension tika = new TikaExtension();
 
-    @ClassRule
-    public static TikaContainerSingletonRule tika = TikaContainerSingletonRule.rule;
-
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         textExtractor = new TikaTextExtractor(new NoopMetricFactory(), new TikaHttpClientImpl(TikaConfiguration.builder()
                 .host(tika.getIp())
                 .port(tika.getPort())
@@ -91,7 +90,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void spamEmailShouldBeWellConvertedToJson() throws IOException {
+    void spamEmailShouldBeWellConvertedToJson() throws IOException {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"), IndexAttachments.YES);
@@ -111,7 +110,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void htmlEmailShouldBeWellConvertedToJson() throws IOException {
+    void htmlEmailShouldBeWellConvertedToJson() throws IOException {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"), IndexAttachments.YES);
@@ -131,7 +130,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void pgpSignedEmailShouldBeWellConvertedToJson() throws IOException {
+    void pgpSignedEmailShouldBeWellConvertedToJson() throws IOException {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"), IndexAttachments.YES);
@@ -151,7 +150,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void simpleEmailShouldBeWellConvertedToJson() throws IOException {
+    void simpleEmailShouldBeWellConvertedToJson() throws IOException {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"), IndexAttachments.YES);
@@ -172,7 +171,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void recursiveEmailShouldBeWellConvertedToJson() throws IOException {
+    void recursiveEmailShouldBeWellConvertedToJson() throws IOException {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"), IndexAttachments.YES);
@@ -192,7 +191,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void emailWithNoInternalDateShouldUseNowDate() throws IOException {
+    void emailWithNoInternalDateShouldUseNowDate() throws IOException {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"), IndexAttachments.YES);
@@ -213,7 +212,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void emailWithAttachmentsShouldConvertAttachmentsWhenIndexAttachmentsIsTrue() throws IOException {
+    void emailWithAttachmentsShouldConvertAttachmentsWhenIndexAttachmentsIsTrue() throws IOException {
         // Given
         MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID,
                 null,
@@ -241,7 +240,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void emailWithAttachmentsShouldNotConvertAttachmentsWhenIndexAttachmentsIsFalse() throws IOException {
+    void emailWithAttachmentsShouldNotConvertAttachmentsWhenIndexAttachmentsIsFalse() throws IOException {
         // Given
         MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID,
                 null,
@@ -269,7 +268,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void emailWithNoMailboxIdShouldThrow() {
+    void emailWithNoMailboxIdShouldThrow() {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"), IndexAttachments.YES);
@@ -289,7 +288,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void getUpdatedJsonMessagePartShouldBehaveWellOnEmptyFlags() throws Exception {
+    void getUpdatedJsonMessagePartShouldBehaveWellOnEmptyFlags() throws Exception {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"),
@@ -299,7 +298,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void getUpdatedJsonMessagePartShouldBehaveWellOnNonEmptyFlags() throws Exception {
+    void getUpdatedJsonMessagePartShouldBehaveWellOnNonEmptyFlags() throws Exception {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"),
@@ -308,17 +307,19 @@ public class MessageToElasticSearchJsonTest {
             .isEqualTo("{\"modSeq\":42,\"isAnswered\":false,\"isDeleted\":true,\"isDraft\":false,\"isFlagged\":true,\"isRecent\":false,\"userFlags\":[\"user\"],\"isUnread\":true}");
     }
 
-    @Test(expected = NullPointerException.class)
-    public void getUpdatedJsonMessagePartShouldThrowIfFlagsIsNull() throws Exception {
+    @Test
+    void getUpdatedJsonMessagePartShouldThrowIfFlagsIsNull() {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             new DefaultTextExtractor(),
             ZoneId.of("Europe/Paris"),
             IndexAttachments.YES);
-        messageToElasticSearchJson.getUpdatedJsonMessagePart(null, MOD_SEQ);
+
+        assertThatThrownBy(() -> messageToElasticSearchJson.getUpdatedJsonMessagePart(null, MOD_SEQ))
+            .isInstanceOf(NullPointerException.class);
     }
 
     @Test
-    public void spamEmailShouldBeWellConvertedToJsonWithApacheTika() throws IOException {
+    void spamEmailShouldBeWellConvertedToJsonWithApacheTika() throws IOException {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
             textExtractor,
             ZoneId.of("Europe/Paris"),
@@ -340,7 +341,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void convertToJsonWithoutAttachmentShouldConvertEmailBoby() throws IOException {
+    void convertToJsonWithoutAttachmentShouldConvertEmailBoby() throws IOException {
         // Given
         MailboxMessage message = new SimpleMailboxMessage(MESSAGE_ID,
             null,
@@ -368,7 +369,7 @@ public class MessageToElasticSearchJsonTest {
     }
 
     @Test
-    public void convertToJsonShouldExtractHtmlText() throws IOException {
+    void convertToJsonShouldExtractHtmlText() throws IOException {
         // Given
         MailboxMessage message = new SimpleMailboxMessage(MESSAGE_ID,
             date,


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


[james-project] 11/15: [Refactoring] Move IndexableMessageTest to JUnit 5

Posted by bt...@apache.org.
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 50d7bc7e687404fe23826e013c347d89054ba14c
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Mon Dec 9 11:42:31 2019 +0700

    [Refactoring] Move IndexableMessageTest to JUnit 5
    
    With the new Tika extension...
---
 .../elasticsearch/json/IndexableMessageTest.java   | 60 +++++++++++-----------
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
index bcfaaa48..fecf8c6 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
@@ -44,28 +44,28 @@ import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.Property;
 import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
 import org.apache.james.mailbox.tika.TikaConfiguration;
-import org.apache.james.mailbox.tika.TikaContainerSingletonRule;
+import org.apache.james.mailbox.tika.TikaExtension;
 import org.apache.james.mailbox.tika.TikaHttpClientImpl;
 import org.apache.james.mailbox.tika.TikaTextExtractor;
 import org.apache.james.metrics.api.NoopMetricFactory;
 import org.assertj.core.api.iterable.Extractor;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 
-public class IndexableMessageTest {
-    private static final MessageUid MESSAGE_UID = MessageUid.of(154);
+class IndexableMessageTest {
+    static final MessageUid MESSAGE_UID = MessageUid.of(154);
 
-    @ClassRule
-    public static TikaContainerSingletonRule tika = TikaContainerSingletonRule.rule;
+    @RegisterExtension
+    static TikaExtension tika = new TikaExtension();
 
-    private TikaTextExtractor textExtractor;
+    TikaTextExtractor textExtractor;
 
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         textExtractor = new TikaTextExtractor(new NoopMetricFactory(), new TikaHttpClientImpl(TikaConfiguration.builder()
                 .host(tika.getIp())
                 .port(tika.getPort())
@@ -74,7 +74,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void textShouldBeEmptyWhenNoMatchingHeaders() throws Exception {
+    void textShouldBeEmptyWhenNoMatchingHeaders() throws Exception {
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
@@ -101,7 +101,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void textShouldContainsFromWhenFrom() throws Exception {
+    void textShouldContainsFromWhenFrom() throws Exception {
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
@@ -130,7 +130,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void textShouldContainsToWhenTo() throws Exception {
+    void textShouldContainsToWhenTo() throws Exception {
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
@@ -159,7 +159,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void textShouldContainsCcWhenCc() throws Exception {
+    void textShouldContainsCcWhenCc() throws Exception {
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
@@ -188,7 +188,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void textShouldContainsBccWhenBcc() throws Exception {
+    void textShouldContainsBccWhenBcc() throws Exception {
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
@@ -217,7 +217,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void textShouldContainsSubjectsWhenSubjects() throws Exception {
+    void textShouldContainsSubjectsWhenSubjects() throws Exception {
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
@@ -244,7 +244,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void textShouldContainsBodyWhenBody() throws Exception {
+    void textShouldContainsBodyWhenBody() throws Exception {
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
@@ -271,7 +271,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void textShouldContainsAllFieldsWhenAllSet() throws Exception {
+    void textShouldContainsAllFieldsWhenAllSet() throws Exception {
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
@@ -306,7 +306,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void hasAttachmentsShouldReturnTrueWhenPropertyIsPresentAndTrue() throws IOException {
+    void hasAttachmentsShouldReturnTrueWhenPropertyIsPresentAndTrue() throws IOException {
         //Given
         MailboxMessage  mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
@@ -337,7 +337,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void hasAttachmentsShouldReturnFalseWhenPropertyIsPresentButFalse() throws IOException {
+    void hasAttachmentsShouldReturnFalseWhenPropertyIsPresentButFalse() throws IOException {
         //Given
         MailboxMessage  mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
@@ -369,7 +369,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void hasAttachmentsShouldReturnFalseWhenPropertyIsAbsent() throws IOException {
+    void hasAttachmentsShouldReturnFalseWhenPropertyIsAbsent() throws IOException {
         //Given
         MailboxMessage  mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
@@ -401,7 +401,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void attachmentsShouldNotBeenIndexedWhenAsked() throws Exception {
+    void attachmentsShouldNotBeenIndexedWhenAsked() throws Exception {
         //Given
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
@@ -431,7 +431,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void attachmentsShouldBeenIndexedWhenAsked() throws Exception {
+    void attachmentsShouldBeenIndexedWhenAsked() throws Exception {
         //Given
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
@@ -461,7 +461,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void otherAttachmentsShouldBeenIndexedWhenOneOfThemCannotBeParsed() throws Exception {
+    void otherAttachmentsShouldBeenIndexedWhenOneOfThemCannotBeParsed() throws Exception {
         //Given
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
@@ -498,9 +498,9 @@ public class IndexableMessageTest {
             .contains("first attachment content", TextualBodyExtractor.NO_TEXTUAL_BODY, "third attachment content");
     }
 
-    private static class TextualBodyExtractor implements Extractor<MimePart, String> {
+    static class TextualBodyExtractor implements Extractor<MimePart, String> {
 
-        public static final String NO_TEXTUAL_BODY = "The textual body is not present";
+        static final String NO_TEXTUAL_BODY = "The textual body is not present";
 
         @Override
         public String extract(MimePart input) {
@@ -509,7 +509,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void messageShouldBeIndexedEvenIfTikaParserThrowsAnError() throws Exception {
+    void messageShouldBeIndexedEvenIfTikaParserThrowsAnError() throws Exception {
         //Given
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);
         TestId mailboxId = TestId.of(1);
@@ -539,7 +539,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void shouldHandleCorrectlyMessageIdHavingSerializeMethodThatReturnNull() throws Exception {
+    void shouldHandleCorrectlyMessageIdHavingSerializeMethodThatReturnNull() throws Exception {
        MessageId invalidMessageIdThatReturnNull = mock(MessageId.class);
        when(invalidMessageIdThatReturnNull.serialize())
            .thenReturn(null);
@@ -572,7 +572,7 @@ public class IndexableMessageTest {
     }
 
     @Test
-    public void shouldHandleCorrectlyNullMessageId() throws Exception {
+    void shouldHandleCorrectlyNullMessageId() throws Exception {
        
         // When
         MailboxMessage mailboxMessage = mock(MailboxMessage.class);


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


[james-project] 02/15: [Refactoring] Get rid of ImapSessionUtils

Posted by bt...@apache.org.
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 7c86c9b33b8463c27ab8f554209f7dce98b0b121
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Dec 11 10:53:24 2019 +0700

    [Refactoring] Get rid of ImapSessionUtils
    
    This class was used to help retrieving MailboxSession and Username which
    is a very common operation.
    
    Having a separeted utility makes the API not straightforward to work with.
    
    I propose leveraging default methods to enhance the developer experience
    and allow an ImapSession::getMailboxSession and a ImapSession::getUsernames
    methods.
    
    Note that fixing mocked tests was non trivial hence I replaced mocking by
    usage of FakeMailboxSession.
---
 .../apache/james/imap/api/ImapSessionUtils.java    | 46 ----------------------
 .../apache/james/imap/api/process/ImapSession.java | 18 +++++++++
 .../imap/decode/parser/CreateCommandParser.java    |  3 +-
 .../org/apache/james/imap/main/PathConverter.java  |  7 ++--
 .../imap/processor/AbstractAuthProcessor.java      |  5 +--
 .../imap/processor/AbstractMailboxProcessor.java   | 11 +++---
 .../processor/AbstractMessageRangeProcessor.java   |  3 +-
 .../imap/processor/AbstractSelectionProcessor.java |  7 ++--
 .../processor/AbstractSubscriptionProcessor.java   |  3 +-
 .../james/imap/processor/AppendProcessor.java      |  5 +--
 .../james/imap/processor/CloseProcessor.java       |  3 +-
 .../james/imap/processor/CreateProcessor.java      |  3 +-
 .../james/imap/processor/DeleteACLProcessor.java   |  3 +-
 .../james/imap/processor/DeleteProcessor.java      |  3 +-
 .../james/imap/processor/ExpungeProcessor.java     |  3 +-
 .../james/imap/processor/GetACLProcessor.java      |  3 +-
 .../imap/processor/GetAnnotationProcessor.java     |  5 +--
 .../james/imap/processor/GetQuotaProcessor.java    |  3 +-
 .../imap/processor/GetQuotaRootProcessor.java      |  3 +-
 .../apache/james/imap/processor/LSubProcessor.java |  3 +-
 .../apache/james/imap/processor/ListProcessor.java |  5 +--
 .../james/imap/processor/ListRightsProcessor.java  |  3 +-
 .../james/imap/processor/LogoutProcessor.java      |  3 +-
 .../james/imap/processor/MyRightsProcessor.java    |  3 +-
 .../james/imap/processor/NamespaceProcessor.java   |  3 +-
 .../james/imap/processor/RenameProcessor.java      |  3 +-
 .../james/imap/processor/SearchProcessor.java      |  3 +-
 .../james/imap/processor/SetACLProcessor.java      |  3 +-
 .../imap/processor/SetAnnotationProcessor.java     |  3 +-
 .../james/imap/processor/StatusProcessor.java      |  3 +-
 .../james/imap/processor/StoreProcessor.java       |  3 +-
 .../james/imap/processor/SubscribeProcessor.java   |  3 +-
 .../imap/processor/SystemMessageProcessor.java     |  3 +-
 .../james/imap/processor/UnsubscribeProcessor.java |  3 +-
 .../imap/processor/base/SelectedMailboxImpl.java   |  5 +--
 .../james/imap/processor/fetch/FetchProcessor.java |  3 +-
 .../imap/processor/fetch/FetchResponseBuilder.java |  3 +-
 ...pSessionUtilsTest.java => ImapSessionTest.java} | 16 ++------
 .../decode/parser/CreateCommandParserTest.java     |  3 +-
 .../apache/james/imap/main/PathConverterTest.java  | 11 ++----
 .../james/imap/processor/CopyProcessorTest.java    | 39 ++++++++----------
 .../imap/processor/DeleteACLProcessorTest.java     | 14 +++----
 .../james/imap/processor/GetACLProcessorTest.java  | 14 +++----
 .../imap/processor/GetAnnotationProcessorTest.java | 35 ++++++++--------
 .../imap/processor/GetQuotaProcessorTest.java      |  9 ++---
 .../imap/processor/GetQuotaRootProcessorTest.java  | 26 ++++++------
 .../james/imap/processor/LSubProcessorTest.java    |  3 +-
 .../imap/processor/ListRightsProcessorTest.java    | 14 +++----
 .../james/imap/processor/MoveProcessorTest.java    | 43 ++++++++------------
 .../imap/processor/NamespaceProcessorTest.java     |  5 +--
 .../james/imap/processor/SearchProcessorTest.java  |  6 +--
 .../james/imap/processor/SetACLProcessorTest.java  | 14 +++----
 .../imap/processor/SetAnnotationProcessorTest.java | 19 ++++-----
 .../imap/processor/SetQuotaProcessorTest.java      |  3 +-
 .../processor/base/MailboxEventAnalyserTest.java   |  3 +-
 .../processor/base/SelectedMailboxImplTest.java    |  3 +-
 .../james/imapserver/netty/IMAPMDCContext.java     |  6 +--
 57 files changed, 175 insertions(+), 306 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/ImapSessionUtils.java b/protocols/imap/src/main/java/org/apache/james/imap/api/ImapSessionUtils.java
deleted file mode 100644
index 532eb49..0000000
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/ImapSessionUtils.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/****************************************************************
- * 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.imap.api;
-
-import java.util.Optional;
-
-import org.apache.james.core.Username;
-import org.apache.james.imap.api.process.ImapSession;
-import org.apache.james.mailbox.MailboxSession;
-
-import com.google.common.base.Preconditions;
-
-public class ImapSessionUtils {
-
-    public static final String MAILBOX_USER_ATTRIBUTE_SESSION_KEY = "org.apache.james.api.imap.MAILBOX_USER_ATTRIBUTE_SESSION_KEY";
-
-    public static final String MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY = "org.apache.james.api.imap.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY";
-
-    public static MailboxSession getMailboxSession(ImapSession session) {
-        return (MailboxSession) session.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY);
-    }
-
-    public static Username getUserName(ImapSession imapSession) {
-        Preconditions.checkNotNull(imapSession);
-        return Optional.ofNullable(getMailboxSession(imapSession))
-            .map(mailboxSession -> mailboxSession.getUser())
-            .orElse(null);
-    }
-}
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/process/ImapSession.java b/protocols/imap/src/main/java/org/apache/james/imap/api/process/ImapSession.java
index 9bbf27a..e8769f9 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/process/ImapSession.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/process/ImapSession.java
@@ -19,7 +19,11 @@
 
 package org.apache.james.imap.api.process;
 
+import java.util.Optional;
+
+import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapSessionState;
+import org.apache.james.mailbox.MailboxSession;
 
 /**
  * Encapsulates all state held for an ongoing Imap session, which commences when
@@ -29,6 +33,7 @@ import org.apache.james.imap.api.ImapSessionState;
  * @version $Revision: 109034 $
  */
 public interface ImapSession {
+    String MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY = "org.apache.james.api.imap.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY";
 
     /**
      * Logs out the session. Marks the connection for closure;
@@ -158,4 +163,17 @@ public interface ImapSession {
      */
     boolean isPlainAuthDisallowed();
 
+    default void setMailboxSession(MailboxSession mailboxSession) {
+        setAttribute(MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY, mailboxSession);
+    }
+
+    default MailboxSession getMailboxSession() {
+        return (MailboxSession) getAttribute(MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY);
+    }
+
+    default Username getUserName() {
+        return Optional.ofNullable(getMailboxSession())
+            .map(MailboxSession::getUser)
+            .orElse(null);
+    }
 }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/CreateCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/CreateCommandParser.java
index 89c679a..350f65f 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/CreateCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/CreateCommandParser.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.decode.parser;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.ImapMessage;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.Tag;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.process.ImapSession;
@@ -47,7 +46,7 @@ public class CreateCommandParser extends AbstractImapCommandParser {
     protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, Tag tag, ImapSession session) throws DecodingException {
         String mailboxName = request.mailbox();
 
-        MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        MailboxSession mailboxSession = session.getMailboxSession();
 
         // Check if we have an mailboxsession. This is a workaround for
         // IMAP-240:
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/main/PathConverter.java b/protocols/imap/src/main/java/org/apache/james/imap/main/PathConverter.java
index 8f97bd7..ca5a7cb 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/main/PathConverter.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/main/PathConverter.java
@@ -22,7 +22,6 @@ package org.apache.james.imap.main;
 import java.util.List;
 
 import org.apache.james.core.Username;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -64,11 +63,11 @@ public class PathConverter {
     }
 
     private MailboxPath buildRelativePath(String mailboxName) {
-        return buildMailboxPath(MailboxConstants.USER_NAMESPACE, ImapSessionUtils.getUserName(session), mailboxName);
+        return buildMailboxPath(MailboxConstants.USER_NAMESPACE, session.getUserName(), mailboxName);
     }
 
     private MailboxPath buildAbsolutePath(String absolutePath) {
-        char pathDelimiter = ImapSessionUtils.getMailboxSession(session).getPathDelimiter();
+        char pathDelimiter = session.getMailboxSession().getPathDelimiter();
         List<String> mailboxPathParts = Splitter.on(pathDelimiter).splitToList(absolutePath);
         String namespace = mailboxPathParts.get(NAMESPACE);
         String mailboxName = Joiner.on(pathDelimiter).join(Iterables.skip(mailboxPathParts, 1));
@@ -77,7 +76,7 @@ public class PathConverter {
 
     private Username retrieveUserName(String namespace) {
         if (namespace.equals(MailboxConstants.USER_NAMESPACE)) {
-            return ImapSessionUtils.getUserName(session);
+            return session.getUserName();
         }
         throw new DeniedAccessOnSharedMailboxException();
     }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractAuthProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractAuthProcessor.java
index d7ef19e..35eac0b 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractAuthProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractAuthProcessor.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor;
 import java.util.Optional;
 
 import org.apache.james.core.Username;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.request.ImapRequest;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
@@ -71,7 +70,7 @@ public abstract class AbstractAuthProcessor<R extends ImapRequest> extends Abstr
                     final MailboxSession mailboxSession = mailboxManager.login(authenticationAttempt.getAuthenticationId(),
                         authenticationAttempt.getPassword());
                     session.authenticated();
-                    session.setAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY, mailboxSession);
+                    session.setMailboxSession(mailboxSession);
                     provisionInbox(session, mailboxManager, mailboxSession);
                     okComplete(request, responder);
                 } catch (BadCredentialsException e) {
@@ -101,7 +100,7 @@ public abstract class AbstractAuthProcessor<R extends ImapRequest> extends Abstr
                         authenticationAttempt.getPassword(),
                         authenticationAttempt.getDelegateUserName().get());
                     session.authenticated();
-                    session.setAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY, mailboxSession);
+                    session.setMailboxSession(mailboxSession);
                     provisionInbox(session, mailboxManager, mailboxSession);
                     okComplete(request, responder);
                 } catch (BadCredentialsException e) {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
index 0073028..7eff975 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
@@ -29,7 +29,6 @@ import java.util.stream.Stream;
 import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
@@ -94,11 +93,11 @@ public abstract class AbstractMailboxProcessor<R extends ImapRequest> extends Ab
                 responder.respond(response);
 
             } else {
-                getMailboxManager().startProcessingRequest(ImapSessionUtils.getMailboxSession(session));
+                getMailboxManager().startProcessingRequest(session.getMailboxSession());
 
                 processRequest(acceptableMessage, session, responder);
 
-                getMailboxManager().endProcessingRequest(ImapSessionUtils.getMailboxSession(session));
+                getMailboxManager().endProcessingRequest(session.getMailboxSession());
             }
         } catch (DeniedAccessOnSharedMailboxException e) {
             no(acceptableMessage, responder, HumanReadableText.DENIED_SHARED_MAILBOX);
@@ -196,7 +195,7 @@ public abstract class AbstractMailboxProcessor<R extends ImapRequest> extends Ab
             // To be lazily initialized only if needed, which is in minority of cases.
             MessageManager messageManager = null;
             MetaData metaData = null;
-            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+            final MailboxSession mailboxSession = session.getMailboxSession();
 
             // Check if we need to send a FLAGS and PERMANENTFLAGS response before the FETCH response
             // This is the case if some new flag/keyword was used
@@ -295,7 +294,7 @@ public abstract class AbstractMailboxProcessor<R extends ImapRequest> extends Ab
     
     private MessageManager getMailbox(ImapSession session, SelectedMailbox selected) throws MailboxException {
         final MailboxManager mailboxManager = getMailboxManager();
-        return mailboxManager.getMailbox(selected.getMailboxId(), ImapSessionUtils.getMailboxSession(session));
+        return mailboxManager.getMailbox(selected.getMailboxId(), session.getMailboxSession());
     }
 
     private void addRecentResponses(SelectedMailbox selected, ImapProcessor.Responder responder) {
@@ -401,7 +400,7 @@ public abstract class AbstractMailboxProcessor<R extends ImapRequest> extends Ab
             result = null;
         } else {
             final MailboxManager mailboxManager = getMailboxManager();
-            result = mailboxManager.getMailbox(selectedMailbox.getMailboxId(), ImapSessionUtils.getMailboxSession(session));
+            result = mailboxManager.getMailbox(selectedMailbox.getMailboxId(), session.getMailboxSession());
         }
         return result;
     }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
index ac31374..8860c1a 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMessageRangeProcessor.java
@@ -24,7 +24,6 @@ import java.util.List;
 import java.util.Objects;
 import java.util.stream.Stream;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.response.StatusResponse;
@@ -68,7 +67,7 @@ public abstract class AbstractMessageRangeProcessor<R extends AbstractMessageRan
         MailboxPath targetMailbox = PathConverter.forSession(session).buildFullPath(request.getMailboxName());
 
         try {
-            MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+            MailboxSession mailboxSession = session.getMailboxSession();
 
             if (!getMailboxManager().mailboxExists(targetMailbox, mailboxSession)) {
                 no(request, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX, StatusResponse.ResponseCode.tryCreate());
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
index 9ceb8a5..a532b9e 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
@@ -24,7 +24,6 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.ImapMessage;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
@@ -157,7 +156,7 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
             if (lastKnownUidValidity == metaData.getUidValidity()) {
                 
                 final MailboxManager mailboxManager = getMailboxManager();
-                final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+                final MailboxSession mailboxSession = session.getMailboxSession();
                 final MessageManager mailbox = mailboxManager.getMailbox(fullMailboxPath, mailboxSession);
 
                 //  If the provided UIDVALIDITY matches that of the selected mailbox, the
@@ -382,7 +381,7 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
 
     private MessageManager.MetaData selectMailbox(MailboxPath mailboxPath, ImapSession session) throws MailboxException {
         final MailboxManager mailboxManager = getMailboxManager();
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         final MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession);
 
         final SelectedMailbox sessionMailbox;
@@ -443,7 +442,7 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
                     boolean send = false;
                     if (sm != null) {
                         MessageManager mailbox = getSelectedMailbox(session);
-                        metaData = mailbox.getMetaData(false, ImapSessionUtils.getMailboxSession(session), FetchGroup.NO_COUNT);
+                        metaData = mailbox.getMetaData(false, session.getMailboxSession(), FetchGroup.NO_COUNT);
                         send = true;
                     }
                     condstoreEnablingCommand(session, responder, metaData, send);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSubscriptionProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSubscriptionProcessor.java
index ec3c4f2..4204cae 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSubscriptionProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSubscriptionProcessor.java
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.james.imap.processor;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.request.ImapRequest;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -55,7 +54,7 @@ public abstract class AbstractSubscriptionProcessor<R extends ImapRequest> exten
     protected final void processRequest(R request, ImapSession session, Responder responder) {
 
         // take care of calling the start/end processing
-        MailboxSession mSession = ImapSessionUtils.getMailboxSession(session);
+        MailboxSession mSession = session.getMailboxSession();
         getSubscriptionManager().startProcessingRequest(mSession);
         doProcessRequest(request, session, responder);
         getSubscriptionManager().endProcessingRequest(mSession);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AppendProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
index 5bbb43d..114281b 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AppendProcessor.java
@@ -29,7 +29,6 @@ import java.util.Date;
 import javax.mail.Flags;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.UidRange;
 import org.apache.james.imap.api.message.response.StatusResponse;
@@ -71,7 +70,7 @@ public class AppendProcessor extends AbstractMailboxProcessor<AppendRequest> {
         try {
 
             final MailboxManager mailboxManager = getMailboxManager();
-            final MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, ImapSessionUtils.getMailboxSession(session));
+            final MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, session.getMailboxSession());
             appendToMailbox(messageIn, datetime, flags, session, request, mailbox, responder, mailboxPath);
         } catch (MailboxNotFoundException e) {
             // consume message on exception
@@ -124,7 +123,7 @@ public class AppendProcessor extends AbstractMailboxProcessor<AppendRequest> {
 
     private void appendToMailbox(InputStream message, Date datetime, Flags flagsToBeSet, ImapSession session, AppendRequest request, MessageManager mailbox, Responder responder, MailboxPath mailboxPath) {
         try {
-            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+            final MailboxSession mailboxSession = session.getMailboxSession();
             final SelectedMailbox selectedMailbox = session.getSelected();
             final MailboxManager mailboxManager = getMailboxManager();
             final boolean isSelectedMailbox = selectedMailbox != null && selectedMailbox.getPath().equals(mailboxPath);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
index cc0f6b6..61436ca 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/CloseProcessor.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor;
 
 import java.io.Closeable;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -50,7 +49,7 @@ public class CloseProcessor extends AbstractMailboxProcessor<CloseRequest> {
     protected void processRequest(CloseRequest request, ImapSession session, Responder responder) {
         try {
             MessageManager mailbox = getSelectedMailbox(session);
-            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+            final MailboxSession mailboxSession = session.getMailboxSession();
             if (mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT).isWriteable()) {
                 mailbox.expunge(MessageRange.all(), mailboxSession);
                 session.deselect();
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/CreateProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/CreateProcessor.java
index ecbfc8b..b5646f9 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/CreateProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/CreateProcessor.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor;
 
 import java.io.Closeable;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -51,7 +50,7 @@ public class CreateProcessor extends AbstractMailboxProcessor<CreateRequest> {
         final MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(request.getMailboxName());
         try {
             final MailboxManager mailboxManager = getMailboxManager();
-            mailboxManager.createMailbox(mailboxPath, ImapSessionUtils.getMailboxSession(session));
+            mailboxManager.createMailbox(mailboxPath, session.getMailboxSession());
             unsolicitedResponses(session, responder, false);
             okComplete(request, responder);
         } catch (MailboxExistsException e) {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java
index 44a9658..722eb09 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java
@@ -23,7 +23,6 @@ import java.io.Closeable;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -62,7 +61,7 @@ public class DeleteACLProcessor extends AbstractMailboxProcessor<DeleteACLReques
     protected void processRequest(DeleteACLRequest request, ImapSession session, Responder responder) {
 
         final MailboxManager mailboxManager = getMailboxManager();
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         final String mailboxName = request.getMailboxName();
         final String identifier = request.getIdentifier();
         try {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteProcessor.java
index dc7958b..edc86ce 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteProcessor.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor;
 
 import java.io.Closeable;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -57,7 +56,7 @@ public class DeleteProcessor extends AbstractMailboxProcessor<DeleteRequest> {
                 session.deselect();
             }
             final MailboxManager mailboxManager = getMailboxManager();
-            mailboxManager.deleteMailbox(mailboxPath, ImapSessionUtils.getMailboxSession(session));
+            mailboxManager.deleteMailbox(mailboxPath, session.getMailboxSession());
             unsolicitedResponses(session, responder, false);
             okComplete(request, responder);
         } catch (MailboxNotFoundException e) {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
index 6646faa..431aad7 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
@@ -24,7 +24,6 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.response.StatusResponse.ResponseCode;
@@ -63,7 +62,7 @@ public class ExpungeProcessor extends AbstractMailboxProcessor<ExpungeRequest> i
     protected void processRequest(ExpungeRequest request, ImapSession session, Responder responder) {
         try {
             final MessageManager mailbox = getSelectedMailbox(session);
-            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+            final MailboxSession mailboxSession = session.getMailboxSession();
 
             int expunged = 0;
             MetaData mdata = mailbox.getMetaData(false, mailboxSession, FetchGroup.NO_COUNT);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java
index bd7e884..06148c1 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java
@@ -23,7 +23,6 @@ import java.io.Closeable;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -64,7 +63,7 @@ public class GetACLProcessor extends AbstractMailboxProcessor<GetACLRequest> imp
     protected void processRequest(GetACLRequest request, ImapSession session, Responder responder) {
 
         final MailboxManager mailboxManager = getMailboxManager();
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         final String mailboxName = request.getMailboxName();
         try {
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java
index f8a3abd..14f697e 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java
@@ -28,7 +28,6 @@ import java.util.function.Predicate;
 
 import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.request.ImapRequest;
 import org.apache.james.imap.api.message.response.StatusResponse.ResponseCode;
@@ -75,7 +74,7 @@ public class GetAnnotationProcessor extends AbstractMailboxProcessor<GetAnnotati
             LOGGER.info("The command: {} is failed because not found mailbox {}", request.getCommand().getName(), request.getMailboxName());
             no(request, responder, HumanReadableText.FAILURE_NO_SUCH_MAILBOX, ResponseCode.tryCreate());
         } catch (MailboxException e) {
-            LOGGER.error("GetAnnotation on mailbox {} failed for user {}", request.getMailboxName(), ImapSessionUtils.getUserName(session), e);
+            LOGGER.error("GetAnnotation on mailbox {} failed for user {}", request.getMailboxName(), session.getUserName(), e);
             no(request, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
         }
     }
@@ -120,7 +119,7 @@ public class GetAnnotationProcessor extends AbstractMailboxProcessor<GetAnnotati
     }
 
     private List<MailboxAnnotation> getMailboxAnnotations(ImapSession session, Set<MailboxAnnotationKey> keys, GetAnnotationRequest.Depth depth, MailboxPath mailboxPath) throws MailboxException {
-        MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        MailboxSession mailboxSession = session.getMailboxSession();
         switch (depth) {
             case ZERO:
                 return getMailboxAnnotationsWithDepthZero(keys, mailboxPath, mailboxSession);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java
index 3b86940..20976cf 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java
@@ -27,7 +27,6 @@ import org.apache.james.core.quota.QuotaCountUsage;
 import org.apache.james.core.quota.QuotaSizeLimit;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -100,7 +99,7 @@ public class GetQuotaProcessor extends AbstractMailboxProcessor<GetQuotaRequest>
 
     private boolean hasRight(QuotaRoot quotaRoot, ImapSession session) throws MailboxException {
         // If any of the mailboxes owned by quotaRoot user can be read by the current user, then we should respond to him.
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         List<Mailbox> mailboxList = quotaRootResolver.retrieveAssociatedMailboxes(quotaRoot, mailboxSession);
         for (Mailbox mailbox : mailboxList) {
             if (getMailboxManager().hasRight(mailbox.generateAssociatedPath(), MailboxACL.Right.Read, mailboxSession)) {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
index 8d70dcc..c9a4db3 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
@@ -27,7 +27,6 @@ import org.apache.james.core.quota.QuotaCountUsage;
 import org.apache.james.core.quota.QuotaSizeLimit;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -73,7 +72,7 @@ public class GetQuotaRootProcessor extends AbstractMailboxProcessor<GetQuotaRoot
 
     @Override
     protected void processRequest(GetQuotaRootRequest request, ImapSession session, Responder responder) {
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         final MailboxManager mailboxManager = getMailboxManager();
 
         final MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(request.getMailboxName());
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
index 1842c7a..de43684 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/LSubProcessor.java
@@ -23,7 +23,6 @@ import java.io.Closeable;
 import java.util.ArrayList;
 import java.util.Collection;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.display.ModifiedUtf7;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
@@ -67,7 +66,7 @@ public class LSubProcessor extends AbstractSubscriptionProcessor<LsubRequest> {
     }
 
     private void listSubscriptions(ImapSession session, Responder responder, String referenceName, String mailboxName) throws SubscriptionException, MailboxException {
-        MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        MailboxSession mailboxSession = session.getMailboxSession();
         Collection<String> mailboxes = getSubscriptionManager().subscriptions(mailboxSession);
 
         String decodedMailName = ModifiedUtf7.decodeModifiedUTF7(referenceName);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
index 1768917..bf96dc9 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
@@ -23,7 +23,6 @@ import java.io.Closeable;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapMessage;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.display.ModifiedUtf7;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
@@ -71,7 +70,7 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
     protected void processRequest(ListRequest request, ImapSession session, Responder responder) {
         String baseReferenceName = request.getBaseReferenceName();
         String mailboxPatternString = request.getMailboxPattern();
-        MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        MailboxSession mailboxSession = session.getMailboxSession();
 
         try {
             if (mailboxPatternString.length() == 0) {
@@ -149,7 +148,7 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
     private MailboxPath computeBasePath(ImapSession session, String finalReferencename, boolean isRelative) {
         String decodedName = ModifiedUtf7.decodeModifiedUTF7(finalReferencename);
         if (isRelative) {
-            return MailboxPath.forUser(ImapSessionUtils.getUserName(session), decodedName);
+            return MailboxPath.forUser(session.getUserName(), decodedName);
         } else {
             return PathConverter.forSession(session).buildFullPath(decodedName);
         }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java
index 38b69e8..850d800 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java
@@ -23,7 +23,6 @@ import java.io.Closeable;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -63,7 +62,7 @@ public class ListRightsProcessor extends AbstractMailboxProcessor<ListRightsRequ
     protected void processRequest(ListRightsRequest request, ImapSession session, Responder responder) {
 
         final MailboxManager mailboxManager = getMailboxManager();
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         final String mailboxName = request.getMailboxName();
         final String identifier = request.getIdentifier();
         try {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/LogoutProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/LogoutProcessor.java
index c0c099a..390ea77 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/LogoutProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/LogoutProcessor.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor;
 
 import java.io.Closeable;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -39,7 +38,7 @@ public class LogoutProcessor extends AbstractMailboxProcessor<LogoutRequest> {
 
     @Override
     protected void processRequest(LogoutRequest request, ImapSession session, Responder responder) {
-        MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        MailboxSession mailboxSession = session.getMailboxSession();
         getMailboxManager().logout(mailboxSession);
         session.logout();
         bye(responder);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/MyRightsProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/MyRightsProcessor.java
index 3d88813..5e9ac7e 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/MyRightsProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/MyRightsProcessor.java
@@ -24,7 +24,6 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -61,7 +60,7 @@ public class MyRightsProcessor extends AbstractMailboxProcessor<MyRightsRequest>
     protected void processRequest(MyRightsRequest request, ImapSession session, Responder responder) {
 
         final MailboxManager mailboxManager = getMailboxManager();
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         final String mailboxName = request.getMailboxName();
         try {
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
index b0b5a04..afbd533 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
@@ -27,7 +27,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -52,7 +51,7 @@ public class NamespaceProcessor extends AbstractMailboxProcessor<NamespaceReques
 
     @Override
     protected void processRequest(NamespaceRequest request, ImapSession session, Responder responder) {
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         final List<NamespaceResponse.Namespace> personalNamespaces = buildPersonalNamespaces(mailboxSession, session);
         final List<NamespaceResponse.Namespace> otherUsersNamespaces = buildOtherUsersSpaces(mailboxSession, session);
         final List<NamespaceResponse.Namespace> sharedNamespaces = buildSharedNamespaces(mailboxSession, session);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/RenameProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/RenameProcessor.java
index 8d464fc..27de839 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/RenameProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/RenameProcessor.java
@@ -22,7 +22,6 @@ package org.apache.james.imap.processor;
 import java.io.Closeable;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -56,7 +55,7 @@ public class RenameProcessor extends AbstractMailboxProcessor<RenameRequest> {
         MailboxPath newPath = pathConverter.buildFullPath(request.getNewName());
         try {
             final MailboxManager mailboxManager = getMailboxManager();
-            MailboxSession mailboxsession = ImapSessionUtils.getMailboxSession(session);
+            MailboxSession mailboxsession = session.getMailboxSession();
             mailboxManager.renameMailbox(existingPath, newPath, mailboxsession);
 
             if (existingPath.getName().equalsIgnoreCase(ImapConstants.INBOX_NAME) && !mailboxManager.mailboxExists(existingPath, mailboxsession)) {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
index ce1920a..c124234 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
@@ -30,7 +30,6 @@ import java.util.stream.Stream;
 import javax.mail.Flags.Flag;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
@@ -93,7 +92,7 @@ public class SearchProcessor extends AbstractMailboxProcessor<SearchRequest> imp
             final MessageManager mailbox = getSelectedMailbox(session);
 
             final SearchQuery query = toQuery(searchKey, session);
-            MailboxSession msession = ImapSessionUtils.getMailboxSession(session);
+            MailboxSession msession = session.getMailboxSession();
 
             final Collection<MessageUid> uids = performUidSearch(mailbox, query, msession);
             final Collection<Long> results = asResults(session, useUids, uids);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java
index 25d2ead..708ae15 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java
@@ -24,7 +24,6 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -63,7 +62,7 @@ public class SetACLProcessor extends AbstractMailboxProcessor<SetACLRequest> imp
     protected void processRequest(SetACLRequest request, ImapSession session, Responder responder) {
 
         final MailboxManager mailboxManager = getMailboxManager();
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         final String mailboxName = request.getMailboxName();
         final String identifier = request.getIdentifier();
         try {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetAnnotationProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetAnnotationProcessor.java
index 630799f..94e84e3 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetAnnotationProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetAnnotationProcessor.java
@@ -23,7 +23,6 @@ import java.io.Closeable;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
@@ -60,7 +59,7 @@ public class SetAnnotationProcessor extends AbstractMailboxProcessor<SetAnnotati
     @Override
     protected void processRequest(SetAnnotationRequest request, ImapSession session, Responder responder) {
         final MailboxManager mailboxManager = getMailboxManager();
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         final String mailboxName = request.getMailboxName();
         try {
             MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(mailboxName);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/StatusProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
index 4303e58..cf2aade 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/StatusProcessor.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor;
 
 import java.io.Closeable;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.StatusDataItems;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
@@ -54,7 +53,7 @@ public class StatusProcessor extends AbstractMailboxProcessor<StatusRequest> {
     protected void processRequest(StatusRequest request, ImapSession session, Responder responder) {
         MailboxPath mailboxPath = PathConverter.forSession(session).buildFullPath(request.getMailboxName());
         StatusDataItems statusDataItems = request.getStatusDataItems();
-        MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        MailboxSession mailboxSession = session.getMailboxSession();
 
         try {
             LOGGER.debug("Status called on mailbox named {}", mailboxPath);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
index b8ac0bd..4f6695d 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
@@ -31,7 +31,6 @@ import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
@@ -83,7 +82,7 @@ public class StoreProcessor extends AbstractMailboxProcessor<StoreRequest> {
         
         try {
             final MessageManager mailbox = getSelectedMailbox(session);
-            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+            final MailboxSession mailboxSession = session.getMailboxSession();
             final Flags flags = request.getFlags();
             
             if (unchangedSince != -1) {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SubscribeProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SubscribeProcessor.java
index 02c2c0f..4683879 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SubscribeProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SubscribeProcessor.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor;
 
 import java.io.Closeable;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -47,7 +46,7 @@ public class SubscribeProcessor extends AbstractSubscriptionProcessor<SubscribeR
     @Override
     protected void doProcessRequest(SubscribeRequest request, ImapSession session, Responder responder) {
         final String mailboxName = request.getMailboxName();
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         try {
             getSubscriptionManager().subscribe(mailboxSession, mailboxName);
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SystemMessageProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SystemMessageProcessor.java
index 1584d3c..71b9112 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SystemMessageProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SystemMessageProcessor.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor;
 
 import java.io.Closeable;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.message.request.SystemMessage;
@@ -64,7 +63,7 @@ public class SystemMessageProcessor extends AbstractChainedProcessor<SystemMessa
      *            not null
      */
     private void forceLogout(ImapSession imapSession) {
-        final MailboxSession session = ImapSessionUtils.getMailboxSession(imapSession);
+        final MailboxSession session = imapSession.getMailboxSession();
         if (session == null) {
             LOGGER.trace("No mailbox session so no force logout needed");
         } else {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/UnsubscribeProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/UnsubscribeProcessor.java
index d251607..e90bbc7 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/UnsubscribeProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/UnsubscribeProcessor.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.processor;
 
 import java.io.Closeable;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -47,7 +46,7 @@ public class UnsubscribeProcessor extends AbstractSubscriptionProcessor<Unsubscr
     @Override
     protected void doProcessRequest(UnsubscribeRequest request, ImapSession session, Responder responder) {
         final String mailboxName = request.getMailboxName();
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         try {
             getSubscriptionManager().unsubscribe(mailboxSession, mailboxName);
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
index 63a4c77..741cdb5 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxImpl.java
@@ -32,7 +32,6 @@ import java.util.stream.Stream;
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.api.process.SelectedMailbox;
 import org.apache.james.mailbox.MailboxManager;
@@ -77,13 +76,13 @@ public class SelectedMailboxImpl implements SelectedMailbox, MailboxListener {
 
     public SelectedMailboxImpl(MailboxManager mailboxManager, EventBus eventBus, ImapSession session, MailboxPath path) throws MailboxException {
         this.session = session;
-        this.sessionId = ImapSessionUtils.getMailboxSession(session).getSessionId();
+        this.sessionId = session.getMailboxSession().getSessionId();
         this.mailboxManager = mailboxManager;
         
         // Ignore events from our session
         setSilentFlagChanges(true);
 
-        mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        mailboxSession = session.getMailboxSession();
 
         uidMsnConverter = new UidMsnConverter();
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
index 1ee1a24..668128e 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchProcessor.java
@@ -24,7 +24,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.FetchData;
 import org.apache.james.imap.api.message.IdRange;
@@ -83,7 +82,7 @@ public class FetchProcessor extends AbstractMailboxProcessor<FetchRequest> {
                 taggedBad(request, responder, HumanReadableText.QRESYNC_VANISHED_WITHOUT_CHANGEDSINCE);
                 return;
             }
-            final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+            final MailboxSession mailboxSession = session.getMailboxSession();
 
             MetaData metaData = mailbox.getMetaData(false, mailboxSession, org.apache.james.mailbox.MessageManager.MetaData.FetchGroup.NO_COUNT);
             if (fetch.getChangedSince() != -1 || fetch.isModSeq()) {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
index 0b2e938..16de9b3 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/fetch/FetchResponseBuilder.java
@@ -31,7 +31,6 @@ import java.util.List;
 
 import javax.mail.Flags;
 
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.BodyFetchElement;
 import org.apache.james.imap.api.message.FetchData;
 import org.apache.james.imap.api.message.SectionType;
@@ -123,7 +122,7 @@ public final class FetchResponseBuilder {
         // Check if this fetch will cause the "SEEN" flag to be set on this
         // message. If so, update the flags, and ensure that a flags response is
         // included in the response.
-        final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
+        final MailboxSession mailboxSession = session.getMailboxSession();
         boolean ensureFlagsResponse = false;
         final Flags resultFlags = result.getFlags();
         if (fetch.isSetSeen() && !resultFlags.contains(Flags.Flag.SEEN)) {
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionUtilsTest.java b/protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionTest.java
similarity index 78%
rename from protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionUtilsTest.java
rename to protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionTest.java
index 57a82eb..84687cd 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionUtilsTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/api/ImapSessionTest.java
@@ -20,7 +20,6 @@
 package org.apache.james.imap.api;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.james.core.Username;
 import org.apache.james.imap.encode.FakeImapSession;
@@ -29,7 +28,7 @@ import org.apache.james.mailbox.MailboxSessionUtil;
 import org.junit.Before;
 import org.junit.Test;
 
-public class ImapSessionUtilsTest {
+public class ImapSessionTest {
     private static final Username USERNAME = Username.of("username");
     private static final MailboxSession MAILBOX_SESSION = MailboxSessionUtil.create(USERNAME);
     private FakeImapSession fakeImapSession;
@@ -41,21 +40,14 @@ public class ImapSessionUtilsTest {
 
     @Test
     public void getUserNameShouldReturnNullWhenNoMailboxSession() {
-        assertThat(ImapSessionUtils.getUserName(fakeImapSession))
+        assertThat(fakeImapSession.getUserName())
             .isNull();
     }
 
     @Test
     public void getUserNameShouldReturnUserWhenMailboxSession() {
-        fakeImapSession.setAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY, MAILBOX_SESSION);
-        assertThat(ImapSessionUtils.getUserName(fakeImapSession))
+        fakeImapSession.setMailboxSession(MAILBOX_SESSION);
+        assertThat(fakeImapSession.getUserName())
             .isEqualTo(USERNAME);
     }
-
-    @Test
-    public void getUserNameShouldThrowOnNullImapSession() {
-        assertThatThrownBy(() -> ImapSessionUtils.getUserName(null))
-            .isInstanceOf(NullPointerException.class);
-    }
-
 }
\ No newline at end of file
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CreateCommandParserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CreateCommandParserTest.java
index a7a8e04..c2bbd10 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CreateCommandParserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CreateCommandParserTest.java
@@ -32,7 +32,6 @@ import java.nio.charset.StandardCharsets;
 
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.ImapRequestStreamLineReader;
@@ -55,7 +54,7 @@ public class CreateCommandParserTest {
         mockImapSession = mock(ImapSession.class);
         mailboxSession = MailboxSessionUtil.create(Username.of("userName"));
 
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        when(mockImapSession.getMailboxSession()).thenReturn(mailboxSession);
 
         parser = new CreateCommandParser();
     }
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java b/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java
index 657722f..e7796a8 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java
@@ -20,12 +20,9 @@
 package org.apache.james.imap.main;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import org.apache.james.core.Username;
-import org.apache.james.imap.api.ImapSessionUtils;
-import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
 import org.apache.james.mailbox.model.MailboxConstants;
@@ -40,17 +37,17 @@ public class PathConverterTest {
     private static final Username USERNAME = Username.of("username");
     private static final char PATH_DELIMITER = '.';
 
-    private ImapSession imapSession;
+    private FakeImapSession imapSession;
     private MailboxSession mailboxSession;
     private PathConverter pathConverter;
     @Rule public ExpectedException expectedException = ExpectedException.none();
 
     @Before
     public void setUp() {
-        imapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mailboxSession = MailboxSessionUtil.create(USERNAME);
         pathConverter = PathConverter.forSession(imapSession);
-        when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        imapSession.setMailboxSession(mailboxSession);
     }
 
     @Test
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
index 60db808..af62fa8 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
@@ -31,16 +31,14 @@ import java.util.Optional;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.Tag;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.api.process.SelectedMailbox;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.CopyRequest;
 import org.apache.james.imap.message.request.MoveRequest;
 import org.apache.james.mailbox.MailboxManager;
@@ -67,7 +65,7 @@ public class CopyProcessorTest {
     private MailboxManager mockMailboxManager;
     private StatusResponseFactory mockStatusResponseFactory;
     private ImapProcessor.Responder mockResponder;
-    private ImapSession mockImapSession;
+    private FakeImapSession imapSession;
     private MailboxSession mailboxSession;
 
     @Before
@@ -76,24 +74,25 @@ public class CopyProcessorTest {
         mockMailboxManager = mock(MailboxManager.class);
         mockStatusResponseFactory = mock(StatusResponseFactory.class);
         mockResponder = mock(ImapProcessor.Responder.class);
-        mockImapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mailboxSession = MailboxSessionUtil.create(USERNAME);
 
         testee = new CopyProcessor(mockNextProcessor, mockMailboxManager, mockStatusResponseFactory, new NoopMetricFactory());
+
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
     }
 
     @Test
     public void processShouldWork() throws Exception {
         CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
 
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         MailboxPath selected = new MailboxPath(INBOX, "selected");
         SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
         when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8)));
         when(selectedMailbox.existsCount()).thenReturn(8L);
         when(selectedMailbox.getPath()).thenReturn(selected);
-        when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+        imapSession.selected(selectedMailbox);
         when(mockMailboxManager.mailboxExists(INBOX, mailboxSession)).thenReturn(true);
         MessageManager targetMessageManager = mock(MessageManager.class);
         when(mockMailboxManager.getMailbox(INBOX, mailboxSession)).thenReturn(targetMessageManager);
@@ -104,7 +103,7 @@ public class CopyProcessorTest {
         when(mockStatusResponseFactory.taggedOk(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(okResponse);
         when(mockMailboxManager.moveMessages(MessageRange.range(MessageUid.of(4), MessageUid.of(6)), selected, INBOX, mailboxSession)).thenReturn(Lists.<MessageRange>newArrayList(MessageRange.range(MessageUid.of(4), MessageUid.of(6))));
 
-        testee.process(copyRequest, mockResponder, mockImapSession);
+        testee.process(copyRequest, mockResponder, imapSession);
 
         verify(mockMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockMailboxManager).endProcessingRequest(mailboxSession);
@@ -121,14 +120,12 @@ public class CopyProcessorTest {
     public void processShouldWorkWithMultipleRanges() throws Exception {
         CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(5, 6), new IdRange(1, 3)}, ImapConstants.INBOX_NAME, true, TAG);
 
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         MailboxPath selected = new MailboxPath(INBOX, "selected");
         SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
         when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8)));
         when(selectedMailbox.existsCount()).thenReturn(8L);
         when(selectedMailbox.getPath()).thenReturn(selected);
-        when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+        imapSession.selected(selectedMailbox);
         when(mockMailboxManager.mailboxExists(INBOX, mailboxSession)).thenReturn(true);
         MessageManager targetMessageManager = mock(MessageManager.class);
         when(mockMailboxManager.getMailbox(INBOX, mailboxSession)).thenReturn(targetMessageManager);
@@ -138,7 +135,7 @@ public class CopyProcessorTest {
         StatusResponse okResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedOk(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(okResponse);
 
-        testee.process(copyRequest, mockResponder, mockImapSession);
+        testee.process(copyRequest, mockResponder, imapSession);
 
         verify(mockMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockMailboxManager).endProcessingRequest(mailboxSession);
@@ -155,20 +152,18 @@ public class CopyProcessorTest {
     public void processShouldRespondNoOnUnExistingTargetMailbox() throws Exception {
         CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
 
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         MailboxPath selected = new MailboxPath(INBOX, "selected");
         SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
         when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8)));
         when(selectedMailbox.existsCount()).thenReturn(8L);
         when(selectedMailbox.getPath()).thenReturn(selected);
-        when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+        imapSession.selected(selectedMailbox);
         when(mockMailboxManager.mailboxExists(INBOX, mailboxSession)).thenReturn(false);
 
         StatusResponse noResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedNo(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(noResponse);
 
-        testee.process(copyRequest, mockResponder, mockImapSession);
+        testee.process(copyRequest, mockResponder, imapSession);
 
         verify(mockMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockMailboxManager).endProcessingRequest(mailboxSession);
@@ -181,20 +176,18 @@ public class CopyProcessorTest {
     public void processShouldRespondNoOnMailboxException() throws Exception {
         CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
 
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         MailboxPath selected = new MailboxPath(INBOX, "selected");
         SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
         when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8)));
         when(selectedMailbox.existsCount()).thenReturn(8L);
         when(selectedMailbox.getPath()).thenReturn(selected);
-        when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+        imapSession.selected(selectedMailbox);
         when(mockMailboxManager.mailboxExists(INBOX, mailboxSession)).thenThrow(new MailboxException());
 
         StatusResponse noResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedNo(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class))).thenReturn(noResponse);
 
-        testee.process(copyRequest, mockResponder, mockImapSession);
+        testee.process(copyRequest, mockResponder, imapSession);
 
         verify(mockMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockMailboxManager).endProcessingRequest(mailboxSession);
@@ -207,9 +200,9 @@ public class CopyProcessorTest {
     public void processShouldNotHandleMoveRequests() {
         MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
 
-        testee.process(moveRequest, mockResponder, mockImapSession);
+        testee.process(moveRequest, mockResponder, imapSession);
 
-        verify(mockNextProcessor).process(moveRequest, mockResponder, mockImapSession);
+        verify(mockNextProcessor).process(moveRequest, mockResponder, imapSession);
         verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
     }
 
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java
index d43a94b..2769f8c 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java
@@ -32,12 +32,10 @@ import static org.mockito.Mockito.when;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapProcessor.Responder;
-import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.DeleteACLRequest;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
 import org.apache.james.mailbox.MailboxManager;
@@ -64,7 +62,7 @@ public class DeleteACLProcessorTest {
     private static final String MAILBOX_NAME = ImapConstants.INBOX_NAME;
     private static final Username USER_1 = Username.of("user1");
 
-    private ImapSession imapSession;
+    private FakeImapSession imapSession;
     private MailboxManager mailboxManager;
     private MailboxSession mailboxSession;
     private MetaData metaData;
@@ -81,17 +79,15 @@ public class DeleteACLProcessorTest {
         UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
         mailboxManager = mock(MailboxManager.class);
         subject = new DeleteACLProcessor(mock(ImapProcessor.class), mailboxManager, statusResponseFactory, new NoopMetricFactory());
-        imapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mailboxSession = MailboxSessionUtil.create(USER_1);
 
         MessageManager messageManager = mock(MessageManager.class);
         metaData = mock(MetaData.class);
         responder = mock(Responder.class);
 
-        when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
-            .thenReturn(mailboxSession);
-        when(imapSession.getState())
-            .thenReturn(ImapSessionState.AUTHENTICATED);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
         when(messageManager.getMetaData(anyBoolean(), any(MailboxSession.class), any(FetchGroup.class)))
             .thenReturn(metaData);
         when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class)))
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetACLProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetACLProcessorTest.java
index 4f5a58e..c617d3a 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetACLProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetACLProcessorTest.java
@@ -32,12 +32,10 @@ import static org.mockito.Mockito.when;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapProcessor.Responder;
-import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.GetACLRequest;
 import org.apache.james.imap.message.response.ACLResponse;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
@@ -64,7 +62,7 @@ public class GetACLProcessorTest {
     private static final String MAILBOX_NAME = ImapConstants.INBOX_NAME;
     private static final Username USER_1 = Username.of("user1");
 
-    private ImapSession imapSession;
+    private FakeImapSession imapSession;
     private MailboxManager mailboxManager;
     private MailboxSession mailboxSession;
     private MetaData metaData;
@@ -80,7 +78,7 @@ public class GetACLProcessorTest {
         UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
         mailboxManager = mock(MailboxManager.class);
         subject = new GetACLProcessor(mock(ImapProcessor.class), mailboxManager, statusResponseFactory, new NoopMetricFactory());
-        imapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mailboxSession = MailboxSessionUtil.create(USER_1);
         MessageManager messageManager = mock(MessageManager.class);
         metaData = mock(MetaData.class);
@@ -88,10 +86,8 @@ public class GetACLProcessorTest {
 
         getACLRequest = new GetACLRequest(TAG, ImapCommand.anyStateCommand("Name"), MAILBOX_NAME);
 
-        when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
-            .thenReturn(mailboxSession);
-        when(imapSession.getState())
-            .thenReturn(ImapSessionState.AUTHENTICATED);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
         when(messageManager.getMetaData(anyBoolean(), any(MailboxSession.class), any(FetchGroup.class)))
             .thenReturn(metaData);
         when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class)))
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetAnnotationProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetAnnotationProcessorTest.java
index ff1a44d..b950b7a 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetAnnotationProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetAnnotationProcessorTest.java
@@ -36,15 +36,12 @@ import java.util.Set;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.Tag;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponse.ResponseCode;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.GetAnnotationRequest;
 import org.apache.james.imap.message.request.GetAnnotationRequest.Depth;
@@ -85,7 +82,7 @@ public class GetAnnotationProcessorTest {
     private MailboxManager mockMailboxManager;
     private StatusResponseFactory mockStatusResponseFactory;
     private ImapProcessor.Responder mockResponder;
-    private ImapSession mockImapSession;
+    private FakeImapSession imapSession;
     private MailboxSession mailboxSession;
 
     private Set<MailboxAnnotationKey> keys;
@@ -103,7 +100,7 @@ public class GetAnnotationProcessorTest {
         mockMailboxManager = mock(MailboxManager.class);
         mockStatusResponseFactory = mock(StatusResponseFactory.class);
         mockResponder = mock(ImapProcessor.Responder.class);
-        mockImapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
 
         Username username = Username.of("username");
         mailboxSession = MailboxSessionUtil.create(username);
@@ -117,8 +114,8 @@ public class GetAnnotationProcessorTest {
         captorResponsecode = ArgumentCaptor.forClass(ResponseCode.class);
         captorAnnotationResponse = ArgumentCaptor.forClass(AnnotationResponse.class);
 
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
     }
 
     @Before
@@ -140,7 +137,7 @@ public class GetAnnotationProcessorTest {
         when(mockStatusResponseFactory.taggedNo(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class), any(ResponseCode.class)))
             .thenReturn(statusResponse);
 
-        processor.process(annotationRequestBuilder.build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.build(), mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedNo(any(Tag.class), any(ImapCommand.class), humanTextCaptor.capture(), captorResponsecode.capture());
         verify(mockResponder).respond(statusResponse);
@@ -156,7 +153,7 @@ public class GetAnnotationProcessorTest {
         when(mockStatusResponseFactory.taggedNo(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class)))
             .thenReturn(statusResponse);
 
-        processor.process(annotationRequestBuilder.build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.build(), mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedNo(any(Tag.class), any(ImapCommand.class), humanTextCaptor.capture());
         verify(mockResponder).respond(statusResponse);
@@ -167,7 +164,7 @@ public class GetAnnotationProcessorTest {
 
     @Test
     public void processShouldGetAllAnnotationsAndReturnCompleteResponse() throws Exception {
-        processor.process(annotationRequestBuilder.build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.build(), mockResponder, imapSession);
 
         verify(mockMailboxManager, times(1)).getAllAnnotations(inbox, mailboxSession);
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class), any(ImapCommand.class), humanTextCaptor.capture());
@@ -180,7 +177,7 @@ public class GetAnnotationProcessorTest {
 
     @Test
     public void processShouldGetAnnotationsByKeysAndReturnCompleteResponse() throws Exception {
-        processor.process(annotationRequestBuilder.keys(keys).build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.keys(keys).build(), mockResponder, imapSession);
 
         verify(mockMailboxManager, times(1)).getAnnotationsByKeys(eq(inbox), eq(mailboxSession), eq(keys));
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class), any(ImapCommand.class), humanTextCaptor.capture());
@@ -194,7 +191,7 @@ public class GetAnnotationProcessorTest {
     public void processShouldGetAnnotationsAndReturnCompleteResponseWithTheLongestEntryInfoWhenLimitMaxsize() throws Exception {
         when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, SHARED_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION));
 
-        processor.process(annotationRequestBuilder.maxsize(Optional.of(10)).build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.maxsize(Optional.of(10)).build(), mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class),
                 any(ImapCommand.class),
@@ -211,7 +208,7 @@ public class GetAnnotationProcessorTest {
     public void processShouldGetAnnotationsAndReturnCompleteResponseDoesNotTruncateDataByMaxsize() throws Exception {
         when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, SHARED_ANNOTATION));
 
-        processor.process(annotationRequestBuilder.maxsize(Optional.of(100)).build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.maxsize(Optional.of(100)).build(), mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class),
                 any(ImapCommand.class),
@@ -226,7 +223,7 @@ public class GetAnnotationProcessorTest {
     public void processShouldGetAnnotationsAndReturnCompleteResponseWithTruncateDataByMaxsize() throws Exception {
         when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(SHARED_ANNOTATION, PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION));
 
-        processor.process(annotationRequestBuilder.maxsize(Optional.of(15)).build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.maxsize(Optional.of(15)).build(), mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class),
             any(ImapCommand.class),
@@ -243,7 +240,7 @@ public class GetAnnotationProcessorTest {
     public void processShouldGetAnnotationsAndReturnCompleteResponseDoesnotTruncateDataByMaxsizeWhenNoMoreOverSizeItem() throws Exception {
         when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(SHARED_ANNOTATION, PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION));
 
-        processor.process(annotationRequestBuilder.maxsize(Optional.of(100)).build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.maxsize(Optional.of(100)).build(), mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class),
             any(ImapCommand.class),
@@ -259,7 +256,7 @@ public class GetAnnotationProcessorTest {
     public void processShouldGetAnnotationsByOneDepthAndReturnCompleteResponseWithTruncateDataByMaxsize() throws Exception {
         when(mockMailboxManager.getAnnotationsByKeysWithOneDepth(inbox, mailboxSession, keys)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION));
 
-        processor.process(annotationRequestBuilder.maxsize(Optional.of(14)).depth(Depth.ONE).keys(keys).build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.maxsize(Optional.of(14)).depth(Depth.ONE).keys(keys).build(), mockResponder, imapSession);
 
         verify(mockMailboxManager, times(1)).getAnnotationsByKeysWithOneDepth(eq(inbox), eq(mailboxSession), eq(keys));
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class),
@@ -277,7 +274,7 @@ public class GetAnnotationProcessorTest {
     public void processShouldGetAnnotationsAndReturnCompleteResponseWithTruncateDataByLessThenOrEqualMaxsize() throws Exception {
         when(mockMailboxManager.getAllAnnotations(inbox, mailboxSession)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, SHARED_ANNOTATION));
 
-        processor.process(annotationRequestBuilder.maxsize(Optional.of(15)).build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.maxsize(Optional.of(15)).build(), mockResponder, imapSession);
 
         verify(mockMailboxManager, times(1)).getAllAnnotations(eq(inbox), eq(mailboxSession));
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class),
@@ -295,7 +292,7 @@ public class GetAnnotationProcessorTest {
     public void processShouldGetAnnotationsByInfinityDepthAndReturnCompleteResponseWithTruncateDataByMaxsize() throws Exception {
         when(mockMailboxManager.getAnnotationsByKeysWithAllDepth(inbox, mailboxSession, keys)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION));
 
-        processor.process(annotationRequestBuilder.maxsize(Optional.of(14)).depth(Depth.INFINITY).keys(keys).build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.maxsize(Optional.of(14)).depth(Depth.INFINITY).keys(keys).build(), mockResponder, imapSession);
 
         verify(mockMailboxManager, times(1)).getAnnotationsByKeysWithAllDepth(eq(inbox), eq(mailboxSession), eq(keys));
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class),
@@ -314,7 +311,7 @@ public class GetAnnotationProcessorTest {
     public void processShouldGetAnnotationsByInfinityDepthAndReturnCompleteResponse() throws Exception {
         when(mockMailboxManager.getAnnotationsByKeysWithAllDepth(inbox, mailboxSession, keys)).thenReturn(ImmutableList.of(PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION));
 
-        processor.process(annotationRequestBuilder.depth(Depth.INFINITY).keys(keys).build(), mockResponder, mockImapSession);
+        processor.process(annotationRequestBuilder.depth(Depth.INFINITY).keys(keys).build(), mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedOk(any(Tag.class),
             any(ImapCommand.class),
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
index 7f18494..c7d583b 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
@@ -37,7 +37,6 @@ import org.apache.james.core.quota.QuotaSizeLimit;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -102,7 +101,7 @@ public class GetQuotaProcessorTest {
         GetQuotaRequest getQuotaRequest = new GetQuotaRequest(TAG, ImapCommand.anyStateCommand("Name"), QUOTA_ROOT.getValue());
 
         when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
+        when(mockedImapSession.getMailboxSession())
             .thenReturn(mailboxSession);
         when(mockedQuotaRootResolver.retrieveAssociatedMailboxes(QUOTA_ROOT, mailboxSession))
             .thenReturn(ImmutableList.of(mailbox));
@@ -132,8 +131,7 @@ public class GetQuotaProcessorTest {
         GetQuotaRequest getQuotaRequest = new GetQuotaRequest(TAG, ImapCommand.anyStateCommand("Name"), QUOTA_ROOT.getValue());
 
         when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
-            .thenReturn(mailboxSession);
+        when(mockedImapSession.getMailboxSession()).thenReturn(mailboxSession);
         when(mockedQuotaRootResolver.retrieveAssociatedMailboxes(QUOTA_ROOT, mailboxSession))
             .thenReturn(ImmutableList.of(mailbox));
         when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession))
@@ -157,8 +155,7 @@ public class GetQuotaProcessorTest {
         GetQuotaRequest getQuotaRequest = new GetQuotaRequest(TAG, ImapCommand.anyStateCommand("Name"), QUOTA_ROOT.getValue());
 
         when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
-            .thenReturn(mailboxSession);
+        when(mockedImapSession.getMailboxSession()).thenReturn(mailboxSession);
         when(mockedQuotaRootResolver.retrieveAssociatedMailboxes(QUOTA_ROOT, mailboxSession))
             .thenReturn(ImmutableList.of(mailbox));
         when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession))
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
index 726799f..30b3cd1 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaRootProcessorTest.java
@@ -37,12 +37,10 @@ import org.apache.james.core.quota.QuotaCountUsage;
 import org.apache.james.core.quota.QuotaSizeLimit;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.GetQuotaRootRequest;
 import org.apache.james.imap.message.response.QuotaResponse;
 import org.apache.james.imap.message.response.QuotaRootResponse;
@@ -73,7 +71,7 @@ public class GetQuotaRootProcessorTest {
         Quota.<QuotaSizeLimit, QuotaSizeUsage>builder().used(QuotaSizeUsage.size(240)).computedLimit(QuotaSizeLimit.size(15890)).build();
 
     private GetQuotaRootProcessor testee;
-    private ImapSession mockedImapSession;
+    private FakeImapSession imapSession;
     private ImapProcessor.Responder mockedResponder;
     private QuotaManager mockedQuotaManager;
     private QuotaRootResolver mockedQuotaRootResolver;
@@ -84,7 +82,7 @@ public class GetQuotaRootProcessorTest {
     public void setUp() {
         mailboxSession = MailboxSessionUtil.create(PLOP);
         UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
-        mockedImapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mockedQuotaManager = mock(QuotaManager.class);
         mockedQuotaRootResolver = mock(QuotaRootResolver.class);
         mockedResponder = mock(ImapProcessor.Responder.class);
@@ -97,8 +95,8 @@ public class GetQuotaRootProcessorTest {
     public void processorShouldWorkOnValidRights() throws Exception {
         GetQuotaRootRequest getQuotaRootRequest = new GetQuotaRootRequest(TAG, ImapCommand.anyStateCommand("Name"), "INBOX");
 
-        when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
         when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
         when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession)).thenReturn(true);
         when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenReturn(MESSAGE_QUOTA);
@@ -108,7 +106,7 @@ public class GetQuotaRootProcessorTest {
         final QuotaResponse messageQuotaResponse = new QuotaResponse("MESSAGE", "plop", MESSAGE_QUOTA);
         final QuotaRootResponse quotaRootResponse = new QuotaRootResponse("INBOX", "plop");
 
-        testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
+        testee.doProcess(getQuotaRootRequest, mockedResponder, imapSession);
 
         verify(mockedMailboxManager, times(1)).startProcessingRequest(mailboxSession);
         verify(mockedMailboxManager, times(1)).endProcessingRequest(mailboxSession);
@@ -127,11 +125,11 @@ public class GetQuotaRootProcessorTest {
     public void processorShouldWorkOnErrorThrown() throws Exception {
         GetQuotaRootRequest getQuotaRootRequest = new GetQuotaRootRequest(TAG, ImapCommand.anyStateCommand("Name"), "INBOX");
 
-        when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
         when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession)).thenThrow(new MailboxException());
 
-        testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
+        testee.doProcess(getQuotaRootRequest, mockedResponder, imapSession);
 
         verify(mockedMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockedMailboxManager).endProcessingRequest(mailboxSession);
@@ -148,11 +146,11 @@ public class GetQuotaRootProcessorTest {
     public void processorShouldWorkOnNonValidRights() throws Exception {
         GetQuotaRootRequest getQuotaRootRequest = new GetQuotaRootRequest(TAG, ImapCommand.anyStateCommand("Name"), "INBOX");
 
-        when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
         when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession)).thenReturn(false);
 
-        testee.doProcess(getQuotaRootRequest, mockedResponder, mockedImapSession);
+        testee.doProcess(getQuotaRootRequest, mockedResponder, imapSession);
 
         verify(mockedMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockedMailboxManager).endProcessingRequest(mailboxSession);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
index 75c6424..211ebd6 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
@@ -31,7 +31,6 @@ import java.util.Collection;
 
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
@@ -184,7 +183,7 @@ public class LSubProcessorTest {
     }
 
     private void expectSubscriptions() throws Exception {
-        when(session.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        when(session.getMailboxSession()).thenReturn(mailboxSession);
         when(manager.subscriptions(mailboxSession)).thenReturn(subscriptions);
     }
 }
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/ListRightsProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/ListRightsProcessorTest.java
index 43a80c2..6e107b2 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/ListRightsProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/ListRightsProcessorTest.java
@@ -32,12 +32,10 @@ import static org.mockito.Mockito.when;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapProcessor.Responder;
-import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.ListRightsRequest;
 import org.apache.james.imap.message.response.ListRightsResponse;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
@@ -65,7 +63,7 @@ public class ListRightsProcessorTest {
     private static final String MAILBOX_NAME = ImapConstants.INBOX_NAME;
     private static final Username USER_1 = Username.of("user1");
 
-    private ImapSession imapSession;
+    private FakeImapSession imapSession;
     private MailboxManager mailboxManager;
     private MailboxSession mailboxSession;
     private MetaData metaData;
@@ -83,7 +81,7 @@ public class ListRightsProcessorTest {
         UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
         mailboxManager = mock(MailboxManager.class);
         subject = new ListRightsProcessor(mock(ImapProcessor.class), mailboxManager, statusResponseFactory, new NoopMetricFactory());
-        imapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mailboxSession = MailboxSessionUtil.create(USER_1);
         MessageManager messageManager = mock(MessageManager.class);
         metaData = mock(MetaData.class);
@@ -91,10 +89,8 @@ public class ListRightsProcessorTest {
 
         argumentCaptor = ArgumentCaptor.forClass(ImapResponseMessage.class);
 
-        when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
-            .thenReturn(mailboxSession);
-        when(imapSession.getState())
-            .thenReturn(ImapSessionState.AUTHENTICATED);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
         when(messageManager.getMetaData(anyBoolean(), any(MailboxSession.class), any(MetaData.FetchGroup.class)))
             .thenReturn(metaData);
         when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class)))
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
index 51def47..4bbbf83 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
@@ -33,16 +33,14 @@ import java.util.Optional;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.Tag;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.api.process.SelectedMailbox;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.CopyRequest;
 import org.apache.james.imap.message.request.MoveRequest;
 import org.apache.james.mailbox.MailboxManager;
@@ -70,7 +68,7 @@ public class MoveProcessorTest {
     private MailboxManager mockMailboxManager;
     private StatusResponseFactory mockStatusResponseFactory;
     private ImapProcessor.Responder mockResponder;
-    private ImapSession mockImapSession;
+    private FakeImapSession imapSession;
     private MailboxSession mailboxSession;
 
     @Before
@@ -79,12 +77,15 @@ public class MoveProcessorTest {
         mockMailboxManager = mock(MailboxManager.class);
         mockStatusResponseFactory = mock(StatusResponseFactory.class);
         mockResponder = mock(ImapProcessor.Responder.class);
-        mockImapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mailboxSession = MailboxSessionUtil.create(USERNAME);
 
         when(mockMailboxManager.hasCapability(eq(MailboxCapabilities.Move))).thenReturn(true);
         testee = new MoveProcessor(mockNextProcessor, mockMailboxManager, mockStatusResponseFactory, new NoopMetricFactory());
         verify(mockMailboxManager).hasCapability(MailboxCapabilities.Move);
+
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
     }
 
     @Test
@@ -102,15 +103,12 @@ public class MoveProcessorTest {
     @Test
     public void processShouldWork() throws Exception {
         MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
-
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         MailboxPath selected = new MailboxPath(INBOX, "selected");
         SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
         when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8)));
         when(selectedMailbox.existsCount()).thenReturn(8L);
         when(selectedMailbox.getPath()).thenReturn(selected);
-        when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+        imapSession.selected(selectedMailbox);
         when(mockMailboxManager.mailboxExists(INBOX, mailboxSession)).thenReturn(true);
         MessageManager targetMessageManager = mock(MessageManager.class);
         when(mockMailboxManager.getMailbox(INBOX, mailboxSession)).thenReturn(targetMessageManager);
@@ -122,7 +120,7 @@ public class MoveProcessorTest {
         when(mockMailboxManager.moveMessages(MessageRange.range(MessageUid.of(4), MessageUid.of(6)), selected, INBOX, mailboxSession))
             .thenReturn(Lists.<MessageRange>newArrayList(MessageRange.range(MessageUid.of(4), MessageUid.of(6))));
 
-        testee.process(moveRequest, mockResponder, mockImapSession);
+        testee.process(moveRequest, mockResponder, imapSession);
 
         verify(mockMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockMailboxManager).endProcessingRequest(mailboxSession);
@@ -138,15 +136,12 @@ public class MoveProcessorTest {
     @Test
     public void processShouldWorkWithMultipleRanges() throws Exception {
         MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(5, 6), new IdRange(1,3)}, ImapConstants.INBOX_NAME, true, TAG);
-
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         MailboxPath selected = new MailboxPath(INBOX, "selected");
         SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
         when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8)));
         when(selectedMailbox.existsCount()).thenReturn(8L);
         when(selectedMailbox.getPath()).thenReturn(selected);
-        when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+        imapSession.selected(selectedMailbox);
         when(mockMailboxManager.mailboxExists(INBOX, mailboxSession)).thenReturn(true);
         MessageManager targetMessageManager = mock(MessageManager.class);
         when(mockMailboxManager.getMailbox(INBOX, mailboxSession)).thenReturn(targetMessageManager);
@@ -156,7 +151,7 @@ public class MoveProcessorTest {
         StatusResponse okResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedOk(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(okResponse);
 
-        testee.process(moveRequest, mockResponder, mockImapSession);
+        testee.process(moveRequest, mockResponder, imapSession);
 
         verify(mockMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockMailboxManager).endProcessingRequest(mailboxSession);
@@ -172,21 +167,18 @@ public class MoveProcessorTest {
     @Test
     public void processShouldRespondNoOnUnExistingTargetMailbox() throws Exception {
         MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(5, 6), new IdRange(1,3)}, ImapConstants.INBOX_NAME, true, TAG);
-
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         MailboxPath selected = new MailboxPath(INBOX, "selected");
         SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
         when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8)));
         when(selectedMailbox.existsCount()).thenReturn(8L);
         when(selectedMailbox.getPath()).thenReturn(selected);
-        when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+        imapSession.selected(selectedMailbox);
         when(mockMailboxManager.mailboxExists(INBOX, mailboxSession)).thenReturn(false);
 
         StatusResponse noResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedNo(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(noResponse);
 
-        testee.process(moveRequest, mockResponder, mockImapSession);
+        testee.process(moveRequest, mockResponder, imapSession);
 
         verify(mockMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockMailboxManager).endProcessingRequest(mailboxSession);
@@ -198,21 +190,18 @@ public class MoveProcessorTest {
     @Test
     public void processShouldRespondNoOnMailboxException() throws Exception {
         MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(5, 6), new IdRange(1,3)}, ImapConstants.INBOX_NAME, true, TAG);
-
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         MailboxPath selected = new MailboxPath(INBOX, "selected");
         SelectedMailbox selectedMailbox = mock(SelectedMailbox.class);
         when(selectedMailbox.getLastUid()).thenReturn(Optional.of(MessageUid.of(8)));
         when(selectedMailbox.existsCount()).thenReturn(8L);
         when(selectedMailbox.getPath()).thenReturn(selected);
-        when(mockImapSession.getSelected()).thenReturn(selectedMailbox);
+        imapSession.selected(selectedMailbox);
         when(mockMailboxManager.mailboxExists(INBOX, mailboxSession)).thenThrow(new MailboxException());
 
         StatusResponse noResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedNo(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class))).thenReturn(noResponse);
 
-        testee.process(moveRequest, mockResponder, mockImapSession);
+        testee.process(moveRequest, mockResponder, imapSession);
 
         verify(mockMailboxManager).startProcessingRequest(mailboxSession);
         verify(mockMailboxManager).endProcessingRequest(mailboxSession);
@@ -225,9 +214,9 @@ public class MoveProcessorTest {
     public void processShouldNotHandleCopyRequests() {
         CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
 
-        testee.process(copyRequest, mockResponder, mockImapSession);
+        testee.process(copyRequest, mockResponder, imapSession);
 
-        verify(mockNextProcessor).process(copyRequest, mockResponder, mockImapSession);
+        verify(mockNextProcessor).process(copyRequest, mockResponder, imapSession);
         verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
     }
 }
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
index 06cfb79..2606938 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
@@ -33,7 +33,6 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.Tag;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponse;
@@ -81,7 +80,7 @@ public class NamespaceProcessorTest {
     @Test
     public void testNamespaceResponseShouldContainPersonalAndUserSpaces() {
         when(imapSessionStub.supportMultipleNamespaces()).thenReturn(true);
-        when(imapSessionStub.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        when(imapSessionStub.getMailboxSession()).thenReturn(mailboxSession);
         when(imapSessionStub.getAttribute(EnableProcessor.ENABLED_CAPABILITIES)).thenReturn(null);
 
         when(mailboxSession.getPersonalSpace()).thenReturn(PERSONAL_PREFIX);
@@ -106,7 +105,7 @@ public class NamespaceProcessorTest {
     @Test
     public void testNamespaceResponseShouldContainSharedSpaces() {
         when(imapSessionStub.supportMultipleNamespaces()).thenReturn(true);
-        when(imapSessionStub.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        when(imapSessionStub.getMailboxSession()).thenReturn(mailboxSession);
         when(imapSessionStub.getAttribute(EnableProcessor.ENABLED_CAPABILITIES)).thenReturn(null);
 
         when(mailboxSession.getPersonalSpace()).thenReturn(PERSONAL_PREFIX);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
index 1653c0d..7fdf373 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
@@ -42,7 +42,6 @@ import javax.mail.Flags.Flag;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
@@ -142,8 +141,7 @@ public class SearchProcessorTest {
     }
 
     private void allowUnsolicitedResponses() {
-        when(session.getAttribute(ImapSessionUtils.MAILBOX_USER_ATTRIBUTE_SESSION_KEY)).thenReturn(USER);
-        when(session.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        when(session.getMailboxSession()).thenReturn(mailboxSession);
     }
 
     @Test
@@ -469,7 +467,7 @@ public class SearchProcessorTest {
 
     private void check(SearchKey key, final SearchQuery query) throws Exception {
         when(session.getAttribute(SearchProcessor.SEARCH_MODSEQ)).thenReturn(null);
-        when(session.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        when(session.getMailboxSession()).thenReturn(mailboxSession);
         when(mailbox.search(query, mailboxSession)).thenReturn(Stream.empty());
         when(selectedMailbox.getApplicableFlags()).thenReturn(new Flags());
         when(selectedMailbox.hasNewApplicableFlags()).thenReturn(false);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java
index dcb4629..24e9232 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java
@@ -32,12 +32,10 @@ import static org.mockito.Mockito.when;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapProcessor.Responder;
-import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.SetACLRequest;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
 import org.apache.james.mailbox.MailboxManager;
@@ -68,7 +66,7 @@ public class SetACLProcessorTest {
     private static final String SET_RIGHTS = "aw";
     private static final String UNSUPPORTED_RIGHT = "W";
 
-    private ImapSession imapSession;
+    private FakeImapSession imapSession;
     private MailboxManager mailboxManager;
     private MailboxSession mailboxSession;
     private SetACLProcessor subject;
@@ -85,7 +83,7 @@ public class SetACLProcessorTest {
         UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
         mailboxManager = mock(MailboxManager.class);
         subject = new SetACLProcessor(mock(ImapProcessor.class), mailboxManager, statusResponseFactory, new NoopMetricFactory());
-        imapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mailboxSession = MailboxSessionUtil.create(USER_1);
         MessageManager messageManager = mock(MessageManager.class);
         MetaData metaData = mock(MetaData.class);
@@ -93,10 +91,8 @@ public class SetACLProcessorTest {
 
         argumentCaptor = ArgumentCaptor.forClass(ImapResponseMessage.class);
 
-        when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
-            .thenReturn(mailboxSession);
-        when(imapSession.getState())
-            .thenReturn(ImapSessionState.AUTHENTICATED);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
         when(messageManager.getMetaData(anyBoolean(), any(MailboxSession.class), any(FetchGroup.class)))
             .thenReturn(metaData);
         when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class)))
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetAnnotationProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetAnnotationProcessorTest.java
index cd0b4ee..e2998bd 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetAnnotationProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetAnnotationProcessorTest.java
@@ -34,14 +34,11 @@ import java.util.List;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.Tag;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.SetAnnotationRequest;
 import org.apache.james.mailbox.MailboxManager;
@@ -73,7 +70,7 @@ public class SetAnnotationProcessorTest {
     private MailboxManager mockMailboxManager;
     private StatusResponseFactory mockStatusResponseFactory;
     private ImapProcessor.Responder mockResponder;
-    private ImapSession mockImapSession;
+    private FakeImapSession imapSession;
     private MailboxSession mockMailboxSession;
 
     private List<MailboxAnnotation> mailboxAnnotations;
@@ -90,7 +87,7 @@ public class SetAnnotationProcessorTest {
         mockMailboxManager = mock(MailboxManager.class);
         mockStatusResponseFactory = mock(StatusResponseFactory.class);
         mockResponder = mock(ImapProcessor.Responder.class);
-        mockImapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
 
         Username username = Username.of("username");
         mockMailboxSession = MailboxSessionUtil.create(username);
@@ -99,8 +96,8 @@ public class SetAnnotationProcessorTest {
         request = new SetAnnotationRequest(TAG, ImapCommand.anyStateCommand("Name"), ImapConstants.INBOX_NAME, mailboxAnnotations);
         humanTextCaptor = ArgumentCaptor.forClass(HumanReadableText.class);
 
-        when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mockMailboxSession);
     }
 
     @Before
@@ -125,7 +122,7 @@ public class SetAnnotationProcessorTest {
         doThrow(MailboxNotFoundException.class).when(mockMailboxManager).updateAnnotations(eq(inbox),
             eq(mockMailboxSession), eq(mailboxAnnotations));
 
-        processor.process(request, mockResponder, mockImapSession);
+        processor.process(request, mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedNo(any(Tag.class), any(ImapCommand.class),
                 humanTextCaptor.capture(), any(StatusResponse.ResponseCode.class));
@@ -137,7 +134,7 @@ public class SetAnnotationProcessorTest {
     public void processShouldResponseNoWithGenericFailureWhenManagerThrowMailboxException() throws Exception {
         doThrow(MailboxException.class).when(mockMailboxManager).updateAnnotations(eq(inbox), eq(mockMailboxSession), eq(mailboxAnnotations));
 
-        processor.process(request, mockResponder, mockImapSession);
+        processor.process(request, mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedNo(any(Tag.class), any(ImapCommand.class), humanTextCaptor.capture());
 
@@ -149,7 +146,7 @@ public class SetAnnotationProcessorTest {
         when(mockStatusResponseFactory.taggedOk(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class)))
             .thenReturn(okResponse);
 
-        processor.process(request, mockResponder, mockImapSession);
+        processor.process(request, mockResponder, imapSession);
 
         verify(mockMailboxManager).updateAnnotations(inbox, mockMailboxSession, mailboxAnnotations);
         verify(mockResponder).respond(okResponse);
@@ -162,7 +159,7 @@ public class SetAnnotationProcessorTest {
     public void processShouldResponseNoWhenManagerThrowsAnnotationException() throws Exception {
         doThrow(AnnotationException.class).when(mockMailboxManager).updateAnnotations(eq(inbox), eq(mockMailboxSession), eq(mailboxAnnotations));
 
-        processor.process(request, mockResponder, mockImapSession);
+        processor.process(request, mockResponder, imapSession);
 
         verify(mockStatusResponseFactory, times(1)).taggedNo(any(Tag.class), any(ImapCommand.class), humanTextCaptor.capture());
 
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
index 89c7773..7a67573 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
@@ -29,7 +29,6 @@ import static org.mockito.Mockito.when;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -66,7 +65,7 @@ public class SetQuotaProcessorTest {
         SetQuotaRequest setQuotaRequest = new SetQuotaRequest(TAG, ImapCommand.anyStateCommand("Name"), "quotaRoot");
 
         when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
+        when(mockedImapSession.getMailboxSession())
             .thenReturn(mailboxSession);
 
         testee.doProcess(setQuotaRequest, mockedResponder, mockedImapSession);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index bf70ce3..1ba1f14 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -32,7 +32,6 @@ import javax.mail.Flags;
 import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
@@ -133,7 +132,7 @@ public class MailboxEventAnalyserTest {
     public void setUp() throws MailboxException {
         ImapSession imapSession = mock(ImapSession.class);
         InVMEventBus eventBus = new InVMEventBus(new InVmEventDelivery(new NoopMetricFactory()));
-        when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY))
+        when(imapSession.getMailboxSession())
             .thenReturn(MAILBOX_SESSION);
         when(imapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
 
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index 95a25c1..d0ed403 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -37,7 +37,6 @@ import java.util.stream.Stream;
 import javax.mail.Flags;
 
 import org.apache.james.core.Username;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
@@ -102,7 +101,7 @@ public class SelectedMailboxImplTest {
             .then(delayedSearchAnswer());
         when(messageManager.getId()).thenReturn(mailboxId);
 
-        when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mock(MailboxSession.class));
+        when(imapSession.getMailboxSession()).thenReturn(mock(MailboxSession.class));
 
         when(mailbox.generateAssociatedPath()).thenReturn(mailboxPath);
         when(mailbox.getMailboxId()).thenReturn(mailboxId);
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
index bb8799e..56042a7 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPMDCContext.java
@@ -25,10 +25,8 @@ import java.net.SocketAddress;
 import java.util.Optional;
 
 import org.apache.james.core.Username;
-import org.apache.james.imap.api.ImapSessionUtils;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.api.process.SelectedMailbox;
-import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.util.MDCBuilder;
 import org.jboss.netty.channel.ChannelHandlerContext;
 import org.jboss.netty.channel.ChannelLocal;
@@ -64,11 +62,9 @@ public class IMAPMDCContext {
     private static MDCBuilder from(Object o) {
         if (o instanceof ImapSession) {
             ImapSession imapSession = (ImapSession) o;
-            MailboxSession mailboxSession = (MailboxSession) imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY);
 
             return MDCBuilder.create()
-                .addContext(MDCBuilder.USER, Optional.ofNullable(mailboxSession)
-                    .map(MailboxSession::getUser)
+                .addContext(MDCBuilder.USER, Optional.ofNullable(imapSession.getUserName())
                     .map(Username::asString))
                 .addContext(from(Optional.ofNullable(imapSession.getSelected())));
         }


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


[james-project] 04/15: [Refactoring] Strong typing for IMAP capabilities

Posted by bt...@apache.org.
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 7c5c8835fc5f4e057cd2f5c1219e89515c2b8e91
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Dec 11 09:39:48 2019 +0700

    [Refactoring] Strong typing for IMAP capabilities
---
 .../apache/james/imap/api/ImapConfiguration.java   | 10 ++--
 .../org/apache/james/imap/api/ImapConstants.java   | 42 +++++++++------
 .../message/Capability.java}                       | 62 +++++++++++++---------
 .../parser/AbstractSelectionCommandParser.java     |  7 +--
 .../imap/decode/parser/EnableCommandParser.java    | 10 ++--
 .../imap/encode/CapabilityResponseEncoder.java     |  5 +-
 .../james/imap/encode/EnableResponseEncoder.java   |  7 +--
 .../james/imap/message/request/EnableRequest.java  |  7 +--
 .../imap/message/response/CapabilityResponse.java  |  8 +--
 .../imap/message/response/EnableResponse.java      |  4 +-
 .../imap/processor/AbstractMailboxProcessor.java   |  3 +-
 .../imap/processor/AbstractSelectionProcessor.java | 13 ++---
 .../imap/processor/AuthenticateProcessor.java      |  9 ++--
 .../processor/CapabilityImplementingProcessor.java |  3 +-
 .../james/imap/processor/CapabilityProcessor.java  | 15 +++---
 .../james/imap/processor/CompressProcessor.java    |  5 +-
 .../james/imap/processor/DeleteACLProcessor.java   |  5 +-
 .../james/imap/processor/EnableProcessor.java      | 19 +++----
 .../james/imap/processor/ExpungeProcessor.java     |  7 ++-
 .../james/imap/processor/GetACLProcessor.java      |  5 +-
 .../imap/processor/GetAnnotationProcessor.java     |  3 +-
 .../james/imap/processor/GetQuotaProcessor.java    |  5 +-
 .../imap/processor/GetQuotaRootProcessor.java      |  5 +-
 .../apache/james/imap/processor/IdleProcessor.java |  5 +-
 .../james/imap/processor/ListRightsProcessor.java  |  5 +-
 .../james/imap/processor/LoginProcessor.java       |  5 +-
 .../apache/james/imap/processor/MoveProcessor.java |  5 +-
 .../james/imap/processor/MyRightsProcessor.java    |  5 +-
 .../james/imap/processor/NamespaceProcessor.java   | 10 ++--
 .../processor/PermitEnableCapabilityProcessor.java |  5 +-
 .../james/imap/processor/SearchProcessor.java      |  5 +-
 .../james/imap/processor/SetACLProcessor.java      |  8 +--
 .../imap/processor/SetAnnotationProcessor.java     |  3 +-
 .../james/imap/processor/SetQuotaProcessor.java    | 16 +++---
 .../james/imap/processor/StartTLSProcessor.java    |  5 +-
 .../james/imap/processor/StoreProcessor.java       |  3 +-
 .../james/imap/processor/UnselectProcessor.java    | 12 +++--
 .../james/imap/processor/XListProcessor.java       |  5 +-
 .../james/imap/api/ImapConfigurationTest.java      | 11 ++--
 .../james/imap/api/message/CapabilityTest.java}    | 46 +++++++++-------
 .../imap/processor/CapabilityProcessorTest.java    |  5 +-
 .../james/imap/processor/MoveProcessorTest.java    |  2 +-
 42 files changed, 244 insertions(+), 176 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConfiguration.java b/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConfiguration.java
index 6b3e81e..2bd613e 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConfiguration.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConfiguration.java
@@ -23,6 +23,7 @@ import java.util.Optional;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.james.imap.api.message.Capability;
 
 import com.github.steveash.guavate.Guavate;
 import com.google.common.base.MoreObjects;
@@ -97,9 +98,10 @@ public class ImapConfiguration {
         }
 
         public ImapConfiguration build() {
-            ImmutableSet<String> normalizeDisableCaps = disabledCaps.stream()
+            ImmutableSet<Capability> normalizeDisableCaps = disabledCaps.stream()
                     .filter(Builder::noBlankString)
                     .map(StringUtils::normalizeSpace)
+                    .map(Capability::of)
                     .collect(Guavate.toImmutableSet());
             return new ImapConfiguration(
                     enableIdle.orElse(DEFAULT_ENABLE_IDLE),
@@ -112,11 +114,11 @@ public class ImapConfiguration {
 
     private final long idleTimeInterval;
     private final TimeUnit idleTimeIntervalUnit;
-    private final ImmutableSet<String> disabledCaps;
+    private final ImmutableSet<Capability> disabledCaps;
     private final boolean enableIdle;
     private final boolean isCondstoreEnable;
 
-    private ImapConfiguration(boolean enableIdle, long idleTimeInterval, TimeUnit idleTimeIntervalUnit, ImmutableSet<String> disabledCaps, boolean isCondstoreEnable) {
+    private ImapConfiguration(boolean enableIdle, long idleTimeInterval, TimeUnit idleTimeIntervalUnit, ImmutableSet<Capability> disabledCaps, boolean isCondstoreEnable) {
         this.enableIdle = enableIdle;
         this.idleTimeInterval = idleTimeInterval;
         this.idleTimeIntervalUnit = idleTimeIntervalUnit;
@@ -132,7 +134,7 @@ public class ImapConfiguration {
         return idleTimeIntervalUnit;
     }
 
-    public ImmutableSet<String> getDisabledCaps() {
+    public ImmutableSet<Capability> getDisabledCaps() {
         return disabledCaps;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConstants.java b/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConstants.java
index 0d9ef2f..17162f3 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConstants.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConstants.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.imap.api;
 
+import org.apache.james.imap.api.message.Capability;
+
 public interface ImapConstants {
     // Basic response types
     String OK = "OK";
@@ -81,33 +83,41 @@ public interface ImapConstants {
 
     String VERSION = "IMAP4rev1";
 
-    String SUPPORTS_LITERAL_PLUS = "LITERAL+";
+    Capability BASIC_CAPABILITIES = Capability.of(VERSION);
+
+    Capability SUPPORTS_LITERAL_PLUS = Capability.of("LITERAL+");
 
-    String SUPPORTS_RFC3348 = "CHILDREN";
+    Capability SUPPORTS_RFC3348 = Capability.of("CHILDREN");
 
     String UTF8 = "UTF-8";
-    
-    String SUPPORTS_I18NLEVEL_1 = "I18NLEVEL=1";
 
-    String SUPPORTS_NAMESPACES = "NAMESPACE";
+    Capability SUPPORTS_I18NLEVEL_1 = Capability.of("I18NLEVEL=1");
 
-    String SUPPORTS_STARTTLS = "STARTTLS";
+    Capability SUPPORTS_NAMESPACES = Capability.of("NAMESPACE");
 
-    String SUPPORTS_IDLE = "IDLE";
+    Capability SUPPORTS_STARTTLS = Capability.of("STARTTLS");
 
-    String SUPPORTS_XLIST = "XLIST";
+    Capability SUPPORTS_IDLE = Capability.of("IDLE");
 
-    String SUPPORTS_ENABLE = "ENABLE";
-    
-    String SUPPORTS_CONDSTORE = "CONDSTORE";
-    
-    String SUPPORTS_QRESYNC = "QRESYNC";
+    Capability SUPPORTS_XLIST = Capability.of("XLIST");
+
+    Capability SUPPORTS_ENABLE = Capability.of("ENABLE");
+
+    Capability SUPPORTS_CONDSTORE = Capability.of("CONDSTORE");
+
+    Capability SUPPORTS_UNSELECT = Capability.of("UNSELECT");
+
+    Capability SUPPORTS_QRESYNC = Capability.of("QRESYNC");
+
+    Capability SUPPORTS_ACL = Capability.of("ACL");
+
+    Capability SUPPORTS_QUOTA = Capability.of("QUOTA");
 
-    String SUPPORTS_ACL = "ACL";
+    Capability SUPPORTS_MOVE = Capability.of("MOVE");
 
-    String SUPPORTS_QUOTA = "QUOTA";
+    Capability SUPPORTS_UIDPLUS = Capability.of("UIDPLUS");
 
-    String SUPPORTS_ANNOTATION = "ANNOTATION";
+    Capability SUPPORTS_ANNOTATION = Capability.of("ANNOTATION");
     
     String INBOX_NAME = "INBOX";
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java b/protocols/imap/src/main/java/org/apache/james/imap/api/message/Capability.java
similarity index 52%
copy from protocols/imap/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java
copy to protocols/imap/src/main/java/org/apache/james/imap/api/message/Capability.java
index 09e52f8..0b10c02 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/message/Capability.java
@@ -16,40 +16,52 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.imap.encode;
 
-import java.io.IOException;
-import java.util.Set;
+package org.apache.james.imap.api.message;
 
-import org.apache.james.imap.api.ImapMessage;
-import org.apache.james.imap.api.process.ImapSession;
-import org.apache.james.imap.encode.base.AbstractChainedImapEncoder;
-import org.apache.james.imap.message.response.EnableResponse;
+import java.util.Locale;
+import java.util.Objects;
 
-/**
- * Encodes <code>Enable</code> response.
- */
-public class EnableResponseEncoder extends AbstractChainedImapEncoder {
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
 
-    public EnableResponseEncoder(ImapEncoder next) {
-        super(next);
+public class Capability {
+    public static Capability of(String value) {
+        Preconditions.checkNotNull(value, "'value' can not be null");
+        Preconditions.checkArgument(!value.isEmpty(), "'value' can not be empty");
+
+        return new Capability(value.toUpperCase(Locale.US));
+    }
+
+    private final String value;
+
+    private Capability(String value) {
+        this.value = value;
+    }
+
+    public String asString() {
+        return value;
     }
 
     @Override
-    protected void doEncode(ImapMessage acceptableMessage, ImapResponseComposer composer, ImapSession session) throws IOException {
-        final EnableResponse response = (EnableResponse) acceptableMessage;
-        Set<String> capabilities = response.getCapabilities();
-        composer.untagged();
-        // Return ENABLED capabilities. See IMAP-323
-        composer.message("ENABLED");
-        for (String capability : capabilities) {
-            composer.message(capability);
+    public final boolean equals(Object o) {
+        if (o instanceof Capability) {
+            Capability that = (Capability) o;
+
+            return Objects.equals(this.value, that.value);
         }
-        composer.end();
+        return false;
     }
-    
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(value);
+    }
+
     @Override
-    protected boolean isAcceptable(ImapMessage message) {
-        return (message instanceof EnableResponse);
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+            .add("value", value)
+            .toString();
     }
 }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
index 4376179..4224e5a 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AbstractSelectionCommandParser.java
@@ -34,16 +34,13 @@ import org.apache.james.imap.message.request.AbstractMailboxSelectionRequest;
 import org.apache.james.mailbox.MessageUid;
 
 public abstract class AbstractSelectionCommandParser extends AbstractImapCommandParser {
-    private static final byte[] CONDSTORE = ImapConstants.SUPPORTS_CONDSTORE.getBytes();
-    private static final byte[] QRESYNC = ImapConstants.SUPPORTS_QRESYNC.getBytes();
+    private static final byte[] CONDSTORE = ImapConstants.SUPPORTS_CONDSTORE.asString().getBytes();
+    private static final byte[] QRESYNC = ImapConstants.SUPPORTS_QRESYNC.asString().getBytes();
 
     public AbstractSelectionCommandParser(ImapCommand command) {
         super(command);
     }
     
-
-
-    
     @Override
     protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, Tag tag, ImapSession session) throws DecodingException {
         final String mailboxName = request.mailbox();
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/EnableCommandParser.java b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/EnableCommandParser.java
index b4a9880..256713a 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/EnableCommandParser.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/EnableCommandParser.java
@@ -20,12 +20,12 @@ package org.apache.james.imap.decode.parser;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Locale;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.api.Tag;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.ImapRequestLineReader;
@@ -40,13 +40,11 @@ public class EnableCommandParser extends AbstractImapCommandParser {
 
     @Override
     protected ImapMessage decode(ImapCommand command, ImapRequestLineReader request, Tag tag, ImapSession session) throws DecodingException {
-        List<String> caps = new ArrayList<>();
-        String cap = request.astring();
-        caps.add(cap.toUpperCase(Locale.US));
+        List<Capability> caps = new ArrayList<>();
+        caps.add(Capability.of(request.astring()));
         while (request.nextChar() == ' ') {
             request.consume();
-            cap = request.astring();
-            caps.add(cap.toUpperCase(Locale.US));
+            caps.add(Capability.of(request.astring()));
         }
         request.eol();
         return new EnableRequest(tag, command, caps);
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/CapabilityResponseEncoder.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/CapabilityResponseEncoder.java
index df7f96c..90eee64 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/CapabilityResponseEncoder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/CapabilityResponseEncoder.java
@@ -23,6 +23,7 @@ import java.util.Iterator;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.encode.base.AbstractChainedImapEncoder;
 import org.apache.james.imap.message.response.CapabilityResponse;
@@ -41,11 +42,11 @@ public class CapabilityResponseEncoder extends AbstractChainedImapEncoder {
     @Override
     protected void doEncode(ImapMessage acceptableMessage, ImapResponseComposer composer, ImapSession session) throws IOException {
         final CapabilityResponse response = (CapabilityResponse) acceptableMessage;
-        Iterator<String> capabilities = response.getCapabilities().iterator();
+        Iterator<Capability> capabilities = response.getCapabilities().iterator();
         composer.untagged();
         composer.message(ImapConstants.CAPABILITY_COMMAND_NAME);
         while (capabilities.hasNext()) {
-            composer.message(capabilities.next());
+            composer.message(capabilities.next().asString());
         }
         composer.end();        
     }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java
index 09e52f8..d9ca32f 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/EnableResponseEncoder.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.util.Set;
 
 import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.encode.base.AbstractChainedImapEncoder;
 import org.apache.james.imap.message.response.EnableResponse;
@@ -38,12 +39,12 @@ public class EnableResponseEncoder extends AbstractChainedImapEncoder {
     @Override
     protected void doEncode(ImapMessage acceptableMessage, ImapResponseComposer composer, ImapSession session) throws IOException {
         final EnableResponse response = (EnableResponse) acceptableMessage;
-        Set<String> capabilities = response.getCapabilities();
+        Set<Capability> capabilities = response.getCapabilities();
         composer.untagged();
         // Return ENABLED capabilities. See IMAP-323
         composer.message("ENABLED");
-        for (String capability : capabilities) {
-            composer.message(capability);
+        for (Capability capability : capabilities) {
+            composer.message(capability.asString());
         }
         composer.end();
     }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/request/EnableRequest.java b/protocols/imap/src/main/java/org/apache/james/imap/message/request/EnableRequest.java
index e285d27..d05be83 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/request/EnableRequest.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/request/EnableRequest.java
@@ -22,12 +22,13 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.Tag;
+import org.apache.james.imap.api.message.Capability;
 
 public class EnableRequest extends AbstractImapRequest {
 
-    private final List<String> capabilities;
+    private final List<Capability> capabilities;
 
-    public EnableRequest(Tag tag, ImapCommand command, List<String> capabilities) {
+    public EnableRequest(Tag tag, ImapCommand command, List<Capability> capabilities) {
         super(tag, command);
         this.capabilities = capabilities;
     }
@@ -37,7 +38,7 @@ public class EnableRequest extends AbstractImapRequest {
      * 
      * @return caps
      */
-    public List<String> getCapabilities() {
+    public List<Capability> getCapabilities() {
         return capabilities;
     }
 }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/CapabilityResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/CapabilityResponse.java
index cf933fa..3da1b76 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/CapabilityResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/CapabilityResponse.java
@@ -20,6 +20,7 @@ package org.apache.james.imap.message.response;
 
 import java.util.Set;
 
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 
 /**
@@ -29,7 +30,7 @@ import org.apache.james.imap.api.message.response.ImapResponseMessage;
  */
 public class CapabilityResponse implements ImapResponseMessage {
 
-    private final Set<String> capabilities;
+    private final Set<Capability> capabilities;
 
     /**
      * Constructs a response based on the given capabilities.
@@ -37,8 +38,7 @@ public class CapabilityResponse implements ImapResponseMessage {
      * @param capabilities
      *            not null
      */
-    public CapabilityResponse(Set<String> capabilities) {
-        super();
+    public CapabilityResponse(Set<Capability> capabilities) {
         this.capabilities = capabilities;
     }
 
@@ -47,7 +47,7 @@ public class CapabilityResponse implements ImapResponseMessage {
      * 
      * @return not null
      */
-    public Set<String> getCapabilities() {
+    public Set<Capability> getCapabilities() {
         return capabilities;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/EnableResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/EnableResponse.java
index d3dd4ac..ac0b715 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/EnableResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/EnableResponse.java
@@ -20,9 +20,11 @@ package org.apache.james.imap.message.response;
 
 import java.util.Set;
 
+import org.apache.james.imap.api.message.Capability;
+
 public class EnableResponse extends CapabilityResponse {
 
-    public EnableResponse(Set<String> capabilities) {
+    public EnableResponse(Set<Capability> capabilities) {
         super(capabilities);
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
index 7eff975..5380767 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
@@ -30,6 +30,7 @@ import javax.mail.Flags;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
 import org.apache.james.imap.api.message.request.ImapRequest;
@@ -278,7 +279,7 @@ public abstract class AbstractMailboxProcessor<R extends ImapRequest> extends Ab
     }
 
     protected void condstoreEnablingCommand(ImapSession session, Responder responder, MetaData metaData, boolean sendHighestModSeq) {
-        Set<String> enabled = EnableProcessor.getEnabledCapabilities(session);
+        Set<Capability> enabled = EnableProcessor.getEnabledCapabilities(session);
         if (!enabled.contains(ImapConstants.SUPPORTS_CONDSTORE)) {
             if (sendHighestModSeq) {
                 if (metaData.isModSeqPermanent()) {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
index a532b9e..e7a1184 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java
@@ -25,6 +25,7 @@ import java.util.List;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
 import org.apache.james.imap.api.message.request.ImapRequest;
@@ -61,7 +62,7 @@ import com.google.common.collect.ImmutableList;
 
 abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequest> extends AbstractMailboxProcessor<R> implements PermitEnableCapabilityProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSelectionProcessor.class);
-    private static final List<String> CAPS = ImmutableList.of(ImapConstants.SUPPORTS_QRESYNC, ImapConstants.SUPPORTS_CONDSTORE);
+    private static final List<Capability> CAPS = ImmutableList.of(ImapConstants.SUPPORTS_QRESYNC, ImapConstants.SUPPORTS_CONDSTORE);
 
     private final StatusResponseFactory statusResponseFactory;
     private final boolean openReadOnly;
@@ -418,17 +419,17 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPS;
     }
 
     @Override
-    public List<String> getPermitEnableCapabilities(ImapSession session) {
+    public List<Capability> getPermitEnableCapabilities(ImapSession session) {
         return CAPS;
     }
 
     @Override
-    public void enable(ImapMessage message, Responder responder, ImapSession session, String capability) throws EnableException {
+    public void enable(ImapMessage message, Responder responder, ImapSession session, Capability capability) throws EnableException {
 
         if (EnableProcessor.getEnabledCapabilities(session).contains(capability) == false) {
             SelectedMailbox sm = session.getSelected();
@@ -436,7 +437,7 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
             // QRESYNC or CONDSTORE
             //
             // See http://www.dovecot.org/list/dovecot/2008-March/029561.html
-            if (capability.equalsIgnoreCase(ImapConstants.SUPPORTS_CONDSTORE) || capability.equalsIgnoreCase(ImapConstants.SUPPORTS_QRESYNC)) {
+            if (capability.equals(ImapConstants.SUPPORTS_CONDSTORE) || capability.equals(ImapConstants.SUPPORTS_QRESYNC)) {
                 try {
                     MetaData metaData  = null;
                     boolean send = false;
@@ -447,7 +448,7 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ
                     }
                     condstoreEnablingCommand(session, responder, metaData, send);
                 } catch (MailboxException e) {
-                    throw new EnableException("Unable to enable " + capability, e);
+                    throw new EnableException("Unable to enable " + capability.asString(), e);
                 }
             }
             
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
index 6a92f7c..24620b9 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
@@ -28,6 +28,7 @@ import java.util.StringTokenizer;
 
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.request.ImapRequest;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -134,15 +135,15 @@ public class AuthenticateProcessor extends AbstractAuthProcessor<AuthenticateReq
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
-        List<String> caps = new ArrayList<>();
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
+        List<Capability> caps = new ArrayList<>();
         // Only ounce AUTH=PLAIN if the session does allow plain auth or TLS is active.
         // See IMAP-304
         if (session.isPlainAuthDisallowed()  == false || session.isTLSActive()) {
-            caps.add("AUTH=PLAIN");
+            caps.add(Capability.of("AUTH=PLAIN"));
         }
         // Support for SASL-IR. See RFC4959
-        caps.add("SASL-IR");
+        caps.add(Capability.of("SASL-IR"));
         return ImmutableList.copyOf(caps);
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/CapabilityImplementingProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/CapabilityImplementingProcessor.java
index 042bf2f..a336a78 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/CapabilityImplementingProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/CapabilityImplementingProcessor.java
@@ -21,6 +21,7 @@ package org.apache.james.imap.processor;
 
 import java.util.List;
 
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
 
@@ -34,5 +35,5 @@ public interface CapabilityImplementingProcessor extends ImapProcessor {
      *
      * @return list not null
      */
-    List<String> getImplementedCapabilities(ImapSession session);
+    List<Capability> getImplementedCapabilities(ImapSession session);
 }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/CapabilityProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/CapabilityProcessor.java
index d82f129..03f3a93 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/CapabilityProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/CapabilityProcessor.java
@@ -19,11 +19,11 @@
 
 package org.apache.james.imap.processor;
 
+import static org.apache.james.imap.api.ImapConstants.BASIC_CAPABILITIES;
 import static org.apache.james.imap.api.ImapConstants.SUPPORTS_CONDSTORE;
 import static org.apache.james.imap.api.ImapConstants.SUPPORTS_I18NLEVEL_1;
 import static org.apache.james.imap.api.ImapConstants.SUPPORTS_LITERAL_PLUS;
 import static org.apache.james.imap.api.ImapConstants.SUPPORTS_RFC3348;
-import static org.apache.james.imap.api.ImapConstants.VERSION;
 
 import java.io.Closeable;
 import java.util.ArrayList;
@@ -32,6 +32,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.james.imap.api.ImapConfiguration;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -45,15 +46,15 @@ import com.google.common.collect.ImmutableList;
 
 public class CapabilityProcessor extends AbstractMailboxProcessor<CapabilityRequest> implements CapabilityImplementingProcessor {
 
-    private static final List<String> CAPS = ImmutableList.of(
-            VERSION,
+    private static final List<Capability> CAPS = ImmutableList.of(
+            BASIC_CAPABILITIES,
             SUPPORTS_LITERAL_PLUS,
             SUPPORTS_RFC3348,
             SUPPORTS_I18NLEVEL_1,
             SUPPORTS_CONDSTORE);
 
     private final List<CapabilityImplementingProcessor> capabilities = new ArrayList<>();
-    private final Set<String> disabledCaps = new HashSet<>();
+    private final Set<Capability> disabledCaps = new HashSet<>();
 
     public CapabilityProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -96,7 +97,7 @@ public class CapabilityProcessor extends AbstractMailboxProcessor<CapabilityRequ
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPS;
     }
     
@@ -106,8 +107,8 @@ public class CapabilityProcessor extends AbstractMailboxProcessor<CapabilityRequ
      * @param session
      * @return supported
      */
-    public Set<String> getSupportedCapabilities(ImapSession session) {
-        Set<String> caps = new HashSet<>();
+    public Set<Capability> getSupportedCapabilities(ImapSession session) {
+        Set<Capability> caps = new HashSet<>();
         for (CapabilityImplementingProcessor capability : capabilities) {
             caps.addAll(capability.getImplementedCapabilities(session));
         }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/CompressProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/CompressProcessor.java
index c9331ae..5109058 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/CompressProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/CompressProcessor.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -35,7 +36,7 @@ import com.google.common.collect.ImmutableList;
 
 public class CompressProcessor extends AbstractChainedProcessor<CompressRequest> implements CapabilityImplementingProcessor {
     private static final String ALGO = "DEFLATE";
-    private static final List<String> CAPA = ImmutableList.of(ImapConstants.COMPRESS_COMMAND_NAME + "=" + ALGO);
+    private static final List<Capability> CAPA = ImmutableList.of(Capability.of(ImapConstants.COMPRESS_COMMAND_NAME + "=" + ALGO));
     private final StatusResponseFactory factory;
     private static final String COMPRESSED = "COMPRESSED";
 
@@ -67,7 +68,7 @@ public class CompressProcessor extends AbstractChainedProcessor<CompressRequest>
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         if (session.isCompressionSupported()) {
             return CAPA;
         }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java
index 722eb09..0db8646 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/DeleteACLProcessor.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -50,7 +51,7 @@ import com.google.common.collect.ImmutableList;
 public class DeleteACLProcessor extends AbstractMailboxProcessor<DeleteACLRequest> implements CapabilityImplementingProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(DeleteACLProcessor.class);
 
-    private static final List<String> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_ACL);
+    private static final List<Capability> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_ACL);
 
     public DeleteACLProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -134,7 +135,7 @@ public class DeleteACLProcessor extends AbstractMailboxProcessor<DeleteACLReques
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPABILITIES;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/EnableProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/EnableProcessor.java
index 74b8982..33e650d 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/EnableProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/EnableProcessor.java
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.request.ImapRequest;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -49,7 +50,7 @@ public class EnableProcessor extends AbstractMailboxProcessor<EnableRequest> imp
 
     private static final List<PermitEnableCapabilityProcessor> capabilities = new ArrayList<>();
     public static final String ENABLED_CAPABILITIES = "ENABLED_CAPABILITIES";
-    private static final List<String> CAPS = ImmutableList.of(SUPPORTS_ENABLE);
+    private static final List<Capability> CAPS = ImmutableList.of(SUPPORTS_ENABLE);
     private final CapabilityProcessor capabilityProcessor;
 
     public EnableProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory, List<PermitEnableCapabilityProcessor> capabilities,
@@ -70,8 +71,8 @@ public class EnableProcessor extends AbstractMailboxProcessor<EnableRequest> imp
     protected void processRequest(EnableRequest request, ImapSession session, Responder responder) {
         try {
 
-            List<String> caps = request.getCapabilities();
-            Set<String> enabledCaps = enable(request, responder, session, caps.iterator());
+            List<Capability> caps = request.getCapabilities();
+            Set<Capability> enabledCaps = enable(request, responder, session, caps.iterator());
             responder.respond(new EnableResponse(enabledCaps));
 
             unsolicitedResponses(session, responder, false);
@@ -82,10 +83,10 @@ public class EnableProcessor extends AbstractMailboxProcessor<EnableRequest> imp
         }
     }
    
-    public Set<String> enable(ImapRequest request, Responder responder, ImapSession session, Iterator<String> caps) throws EnableException {
-        Set<String> enabledCaps = new HashSet<>();
+    public Set<Capability> enable(ImapRequest request, Responder responder, ImapSession session, Iterator<Capability> caps) throws EnableException {
+        Set<Capability> enabledCaps = new HashSet<>();
         while (caps.hasNext()) {
-            String cap = caps.next();
+            Capability cap = caps.next();
             // Check if the CAPABILITY is supported at all
             if (capabilityProcessor.getSupportedCapabilities(session).contains(cap)) {
                 for (PermitEnableCapabilityProcessor enableProcessor : capabilities) {
@@ -111,8 +112,8 @@ public class EnableProcessor extends AbstractMailboxProcessor<EnableRequest> imp
      * Return all enabled <code>CAPABILITIES</code> for this {@link ImapSession}
      */
     @SuppressWarnings("unchecked")
-    public static Set<String> getEnabledCapabilities(ImapSession session) {
-        Set<String> caps = (Set<String>) session.getAttribute(ENABLED_CAPABILITIES);
+    public static Set<Capability> getEnabledCapabilities(ImapSession session) {
+        Set<Capability> caps = (Set<Capability>) session.getAttribute(ENABLED_CAPABILITIES);
         
         if (caps == null) {
             caps = new HashSet<>();
@@ -122,7 +123,7 @@ public class EnableProcessor extends AbstractMailboxProcessor<EnableRequest> imp
     }
     
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPS;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
index 431aad7..fd45881 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ExpungeProcessor.java
@@ -19,12 +19,15 @@
 
 package org.apache.james.imap.processor;
 
+import static org.apache.james.imap.api.ImapConstants.SUPPORTS_UIDPLUS;
+
 import java.io.Closeable;
 import java.util.Iterator;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.response.StatusResponse.ResponseCode;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
@@ -51,7 +54,7 @@ import com.google.common.collect.ImmutableList;
 public class ExpungeProcessor extends AbstractMailboxProcessor<ExpungeRequest> implements CapabilityImplementingProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(ExpungeProcessor.class);
 
-    private static final List<String> UIDPLUS = ImmutableList.of("UIDPLUS");
+    private static final List<Capability> UIDPLUS = ImmutableList.of(SUPPORTS_UIDPLUS);
 
     public ExpungeProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -121,7 +124,7 @@ public class ExpungeProcessor extends AbstractMailboxProcessor<ExpungeRequest> i
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return UIDPLUS;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java
index 06148c1..b17250b 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetACLProcessor.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -52,7 +53,7 @@ import com.google.common.collect.ImmutableList;
 public class GetACLProcessor extends AbstractMailboxProcessor<GetACLRequest> implements CapabilityImplementingProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(GetACLProcessor.class);
 
-    private static final List<String> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_ACL);
+    private static final List<Capability> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_ACL);
 
     public GetACLProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -109,7 +110,7 @@ public class GetACLProcessor extends AbstractMailboxProcessor<GetACLRequest> imp
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPABILITIES;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java
index 14f697e..8cd15c9 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetAnnotationProcessor.java
@@ -29,6 +29,7 @@ import java.util.function.Predicate;
 import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.request.ImapRequest;
 import org.apache.james.imap.api.message.response.StatusResponse.ResponseCode;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
@@ -62,7 +63,7 @@ public class GetAnnotationProcessor extends AbstractMailboxProcessor<GetAnnotati
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return ImmutableList.of(ImapConstants.SUPPORTS_ANNOTATION);
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java
index 20976cf..1f9e2bf 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaProcessor.java
@@ -28,6 +28,7 @@ import org.apache.james.core.quota.QuotaSizeLimit;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -52,7 +53,7 @@ import com.google.common.collect.ImmutableList;
  */
 public class GetQuotaProcessor extends AbstractMailboxProcessor<GetQuotaRequest> implements CapabilityImplementingProcessor {
 
-    private static final List<String> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_QUOTA);
+    private static final List<Capability> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_QUOTA);
 
     private final QuotaManager quotaManager;
     private final QuotaRootResolver quotaRootResolver;
@@ -65,7 +66,7 @@ public class GetQuotaProcessor extends AbstractMailboxProcessor<GetQuotaRequest>
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPABILITIES;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
index c9a4db3..d794b03 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/GetQuotaRootProcessor.java
@@ -28,6 +28,7 @@ import org.apache.james.core.quota.QuotaSizeLimit;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -54,7 +55,7 @@ import com.google.common.collect.ImmutableList;
  */
 public class GetQuotaRootProcessor extends AbstractMailboxProcessor<GetQuotaRootRequest> implements CapabilityImplementingProcessor {
 
-    private static final List<String> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_QUOTA);
+    private static final List<Capability> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_QUOTA);
     private final QuotaRootResolver quotaRootResolver;
     private final QuotaManager quotaManager;
 
@@ -66,7 +67,7 @@ public class GetQuotaRootProcessor extends AbstractMailboxProcessor<GetQuotaRoot
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPABILITIES;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
index f1dbe51..2af0936 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/IdleProcessor.java
@@ -33,6 +33,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.james.imap.api.ImapConfiguration;
 import org.apache.james.imap.api.ImapSessionState;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapLineHandler;
@@ -54,7 +55,7 @@ import org.apache.james.util.concurrent.NamedThreadFactory;
 import com.google.common.collect.ImmutableList;
 
 public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> implements CapabilityImplementingProcessor {
-    private static final List<String> CAPS = ImmutableList.of(SUPPORTS_IDLE);
+    private static final List<Capability> CAPS = ImmutableList.of(SUPPORTS_IDLE);
     public static final int DEFAULT_SCHEDULED_POOL_CORE_SIZE = 5;
     private static final String DONE = "DONE";
 
@@ -154,7 +155,7 @@ public class IdleProcessor extends AbstractMailboxProcessor<IdleRequest> impleme
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPS;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java
index 850d800..4c7a147 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListRightsProcessor.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -51,7 +52,7 @@ import com.google.common.collect.ImmutableList;
 public class ListRightsProcessor extends AbstractMailboxProcessor<ListRightsRequest> implements CapabilityImplementingProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(ListRightsProcessor.class);
 
-    private static final List<String> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_ACL);
+    private static final List<Capability> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_ACL);
 
     public ListRightsProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -123,7 +124,7 @@ public class ListRightsProcessor extends AbstractMailboxProcessor<ListRightsRequ
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPABILITIES;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/LoginProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/LoginProcessor.java
index 3faa59f..568a245 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/LoginProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/LoginProcessor.java
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -39,7 +40,7 @@ import com.google.common.collect.ImmutableList;
  */
 public class LoginProcessor extends AbstractAuthProcessor<LoginRequest> implements CapabilityImplementingProcessor {
 
-    private static final List<String> LOGINDISABLED_CAPS = ImmutableList.of("LOGINDISABLED");
+    private static final List<Capability> LOGINDISABLED_CAPS = ImmutableList.of(Capability.of("LOGINDISABLED"));
     
     public LoginProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -58,7 +59,7 @@ public class LoginProcessor extends AbstractAuthProcessor<LoginRequest> implemen
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         // Announce LOGINDISABLED if plain auth / login is deactivated and the session is not using
         // TLS. See IMAP-304
         if (session.isPlainAuthDisallowed() && session.isTLSActive() == false) {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
index 129251c..bbe1cc4 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/MoveProcessor.java
@@ -23,6 +23,7 @@ import java.io.Closeable;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -61,9 +62,9 @@ public class MoveProcessor extends AbstractMessageRangeProcessor<MoveRequest> im
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         if (moveCapabilitySupported) {
-            return ImmutableList.of(ImapConstants.MOVE_COMMAND_NAME);
+            return ImmutableList.of(ImapConstants.SUPPORTS_MOVE);
         } else {
             return ImmutableList.of();
         }
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/MyRightsProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/MyRightsProcessor.java
index 5e9ac7e..63f5138 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/MyRightsProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/MyRightsProcessor.java
@@ -25,6 +25,7 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -49,7 +50,7 @@ import org.slf4j.LoggerFactory;
 public class MyRightsProcessor extends AbstractMailboxProcessor<MyRightsRequest> implements CapabilityImplementingProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(MyRightsProcessor.class);
 
-    private static final List<String> CAPABILITIES = Collections.singletonList(ImapConstants.SUPPORTS_ACL);
+    private static final List<Capability> CAPABILITIES = Collections.singletonList(ImapConstants.SUPPORTS_ACL);
 
     public MyRightsProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -106,7 +107,7 @@ public class MyRightsProcessor extends AbstractMailboxProcessor<MyRightsRequest>
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPABILITIES;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
index afbd533..eb2e8c5 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/NamespaceProcessor.java
@@ -22,11 +22,10 @@ import static org.apache.james.imap.api.ImapConstants.SUPPORTS_NAMESPACES;
 
 import java.io.Closeable;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -37,12 +36,13 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * Processes a NAMESPACE command into a suitable set of responses.
  */
 public class NamespaceProcessor extends AbstractMailboxProcessor<NamespaceRequest> implements CapabilityImplementingProcessor {
-    private static final List<String> CAPS = Collections.unmodifiableList(Arrays.asList(SUPPORTS_NAMESPACES));
-    
+    private static final List<Capability> CAPS = ImmutableList.of(SUPPORTS_NAMESPACES);
     
     public NamespaceProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -103,7 +103,7 @@ public class NamespaceProcessor extends AbstractMailboxProcessor<NamespaceReques
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPS;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/PermitEnableCapabilityProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/PermitEnableCapabilityProcessor.java
index 52e6242..8416e43 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/PermitEnableCapabilityProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/PermitEnableCapabilityProcessor.java
@@ -21,6 +21,7 @@ package org.apache.james.imap.processor;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.process.ImapSession;
 
 /**
@@ -33,12 +34,12 @@ public interface PermitEnableCapabilityProcessor extends CapabilityImplementingP
      * 
      * Be sure that these are also returned by {@link #getImplementedCapabilities(ImapSession)}
      */
-    List<String> getPermitEnableCapabilities(ImapSession session);
+    List<Capability> getPermitEnableCapabilities(ImapSession session);
     
     /**
      * Callback which is used when a ENABLED command was used to enable on of the CAPABILITIES which is managed by this implementation
      */
-    void enable(ImapMessage message, Responder responder, ImapSession session, String capability) throws EnableException;
+    void enable(ImapMessage message, Responder responder, ImapSession session, Capability capability) throws EnableException;
 
     /**
      * Exception which should get thrown if for whatever reason its not possible to enable a capability
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
index c124234..b28216d 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SearchProcessor.java
@@ -31,6 +31,7 @@ import javax.mail.Flags.Flag;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
 import org.apache.james.imap.api.message.request.DayMonthYear;
@@ -73,7 +74,7 @@ public class SearchProcessor extends AbstractMailboxProcessor<SearchRequest> imp
     private static final Logger LOGGER = LoggerFactory.getLogger(SearchProcessor.class);
 
     protected static final String SEARCH_MODSEQ = "SEARCH_MODSEQ";
-    private static final List<String> CAPS = ImmutableList.of("WITHIN", "ESEARCH", "SEARCHRES");
+    private static final List<Capability> CAPS = ImmutableList.of(Capability.of("WITHIN"), Capability.of("ESEARCH"), Capability.of("SEARCHRES"));
     
     public SearchProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -498,7 +499,7 @@ public class SearchProcessor extends AbstractMailboxProcessor<SearchRequest> imp
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPS;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java
index 708ae15..afba088 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetACLProcessor.java
@@ -20,11 +20,11 @@
 package org.apache.james.imap.processor;
 
 import java.io.Closeable;
-import java.util.Collections;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -45,13 +45,15 @@ import org.apache.james.util.MDCBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * SETACL Processor.
  */
 public class SetACLProcessor extends AbstractMailboxProcessor<SetACLRequest> implements CapabilityImplementingProcessor {
     private static final Logger LOGGER = LoggerFactory.getLogger(SetACLProcessor.class);
 
-    private static final List<String> CAPABILITIES = Collections.singletonList(ImapConstants.SUPPORTS_ACL);
+    private static final List<Capability> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_ACL);
 
     public SetACLProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -151,7 +153,7 @@ public class SetACLProcessor extends AbstractMailboxProcessor<SetACLRequest> imp
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return CAPABILITIES;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetAnnotationProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetAnnotationProcessor.java
index 94e84e3..12209a0 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetAnnotationProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetAnnotationProcessor.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -52,7 +53,7 @@ public class SetAnnotationProcessor extends AbstractMailboxProcessor<SetAnnotati
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return ImmutableList.of(ImapConstants.SUPPORTS_ANNOTATION);
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetQuotaProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetQuotaProcessor.java
index 3601b64..3f0e443 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/SetQuotaProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/SetQuotaProcessor.java
@@ -20,11 +20,11 @@
 package org.apache.james.imap.processor;
 
 import java.io.Closeable;
-import java.util.Collections;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -33,16 +33,13 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * SETQUOTA processor
  */
 public class SetQuotaProcessor extends AbstractMailboxProcessor<SetQuotaRequest> implements CapabilityImplementingProcessor {
-    private static final List<String> CAPABILITIES = Collections.singletonList(ImapConstants.SUPPORTS_QUOTA);
-
-    @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
-        return CAPABILITIES;
-    }
+    private static final List<Capability> CAPABILITIES = ImmutableList.of(ImapConstants.SUPPORTS_QUOTA);
 
     public SetQuotaProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -50,6 +47,11 @@ public class SetQuotaProcessor extends AbstractMailboxProcessor<SetQuotaRequest>
     }
 
     @Override
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
+        return CAPABILITIES;
+    }
+
+    @Override
     protected void processRequest(SetQuotaRequest request, ImapSession session, Responder responder) {
         Object[] params = new Object[]{
             "Full admin rights",
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/StartTLSProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/StartTLSProcessor.java
index 60cb5e6..65977f9 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/StartTLSProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/StartTLSProcessor.java
@@ -24,6 +24,7 @@ import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -37,7 +38,7 @@ import com.google.common.collect.ImmutableList;
  * Processing STARTLS commands
  */
 public class StartTLSProcessor extends AbstractChainedProcessor<StartTLSRequest> implements CapabilityImplementingProcessor {
-    private static final List<String> STARTTLS_CAP = ImmutableList.of(ImapConstants.SUPPORTS_STARTTLS);
+    private static final List<Capability> STARTTLS_CAP = ImmutableList.of(ImapConstants.SUPPORTS_STARTTLS);
     private final StatusResponseFactory factory;
 
     public StartTLSProcessor(ImapProcessor next, StatusResponseFactory factory) {
@@ -58,7 +59,7 @@ public class StartTLSProcessor extends AbstractChainedProcessor<StartTLSRequest>
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         if (session.supportStartTLS()) {
             return STARTTLS_CAP;
         } else {
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
index 4f6695d..cbba9d4 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/StoreProcessor.java
@@ -32,6 +32,7 @@ import javax.mail.Flags;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.IdRange;
 import org.apache.james.imap.api.message.UidRange;
 import org.apache.james.imap.api.message.response.StatusResponse;
@@ -247,7 +248,7 @@ public class StoreProcessor extends AbstractMailboxProcessor<StoreRequest> {
             selected.resetNewApplicableFlags();
         }
         
-        Set<String> enabled = EnableProcessor.getEnabledCapabilities(session);
+        Set<Capability> enabled = EnableProcessor.getEnabledCapabilities(session);
         boolean qresyncEnabled = enabled.contains(ImapConstants.SUPPORTS_QRESYNC);
         boolean condstoreEnabled = enabled.contains(ImapConstants.SUPPORTS_CONDSTORE);
         
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/UnselectProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/UnselectProcessor.java
index 5253f33..64176c1 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/UnselectProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/UnselectProcessor.java
@@ -18,12 +18,13 @@
  ****************************************************************/
 package org.apache.james.imap.processor;
 
+import static org.apache.james.imap.api.ImapConstants.SUPPORTS_UNSELECT;
+
 import java.io.Closeable;
-import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
@@ -32,14 +33,15 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
 
+import com.google.common.collect.ImmutableList;
+
 /**
  * Processor which implements the UNSELECT extension.
  * 
  * See RFC3691
  */
 public class UnselectProcessor extends AbstractMailboxProcessor<UnselectRequest> implements CapabilityImplementingProcessor {
-
-    private static final List<String> UNSELECT = Collections.unmodifiableList(Arrays.asList("UNSELECT"));
+    private static final List<Capability> UNSELECT = ImmutableList.of(SUPPORTS_UNSELECT);
 
     public UnselectProcessor(ImapProcessor next, MailboxManager mailboxManager, StatusResponseFactory factory,
             MetricFactory metricFactory) {
@@ -58,7 +60,7 @@ public class UnselectProcessor extends AbstractMailboxProcessor<UnselectRequest>
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         return UNSELECT;
     }
 
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/XListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/XListProcessor.java
index 381ae28..a7d4a6d 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/XListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/XListProcessor.java
@@ -24,6 +24,7 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
@@ -44,7 +45,7 @@ import com.google.common.collect.ImmutableList;
  */
 public class XListProcessor extends ListProcessor implements CapabilityImplementingProcessor {
 
-    private static final List<String> XLIST_CAPS = ImmutableList.of(SUPPORTS_XLIST);
+    private static final List<Capability> XLIST_CAPS = ImmutableList.of(SUPPORTS_XLIST);
     private final MailboxTyper mailboxTyper;
 
     // some interface
@@ -55,7 +56,7 @@ public class XListProcessor extends ListProcessor implements CapabilityImplement
     }
 
     @Override
-    public List<String> getImplementedCapabilities(ImapSession session) {
+    public List<Capability> getImplementedCapabilities(ImapSession session) {
         // if there's no mailboxTyper, do not annnoyce XLIST capability
         if (mailboxTyper == null) {
             return Collections.emptyList();
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/api/ImapConfigurationTest.java b/protocols/imap/src/test/java/org/apache/james/imap/api/ImapConfigurationTest.java
index b8697d7..ab589f2 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/api/ImapConfigurationTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/api/ImapConfigurationTest.java
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.util.concurrent.TimeUnit;
 
+import org.apache.james.imap.api.message.Capability;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -105,7 +106,7 @@ public class ImapConfigurationTest {
                 .disabledCaps(ImmutableSet.of("AnyValue"))
                 .build();
 
-        assertThat(imapConfiguration.getDisabledCaps()).containsExactly("AnyValue");
+        assertThat(imapConfiguration.getDisabledCaps()).containsExactly(Capability.of("AnyValue"));
     }
 
     @Test
@@ -114,7 +115,7 @@ public class ImapConfigurationTest {
                 .disabledCaps(ImmutableSet.of("AnyValue", "OtherValue"))
                 .build();
 
-        assertThat(imapConfiguration.getDisabledCaps()).containsExactly("AnyValue", "OtherValue");
+        assertThat(imapConfiguration.getDisabledCaps()).containsExactly(Capability.of("AnyValue"), Capability.of("OtherValue"));
     }
 
     @Test
@@ -123,7 +124,7 @@ public class ImapConfigurationTest {
                 .disabledCaps(ImmutableSet.of("   AnyValue   ", "  OtherValue   "))
                 .build();
 
-        assertThat(imapConfiguration.getDisabledCaps()).containsExactly("AnyValue", "OtherValue");
+        assertThat(imapConfiguration.getDisabledCaps()).containsExactly(Capability.of("AnyValue"), Capability.of("OtherValue"));
     }
 
     @Test
@@ -132,7 +133,7 @@ public class ImapConfigurationTest {
                 .disabledCaps("   AnyValue   ", "  OtherValue   ")
                 .build();
 
-        assertThat(imapConfiguration.getDisabledCaps()).containsExactly("AnyValue", "OtherValue");
+        assertThat(imapConfiguration.getDisabledCaps()).containsExactly(Capability.of("AnyValue"), Capability.of("OtherValue"));
     }
 
     @Test
@@ -141,7 +142,7 @@ public class ImapConfigurationTest {
                 .disabledCap("   AnyValue   ")
                 .build();
 
-        assertThat(imapConfiguration.getDisabledCaps()).containsExactly("AnyValue");
+        assertThat(imapConfiguration.getDisabledCaps()).containsExactly(Capability.of("AnyValue"));
     }
 
     @Test
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/request/EnableRequest.java b/protocols/imap/src/test/java/org/apache/james/imap/api/message/CapabilityTest.java
similarity index 58%
copy from protocols/imap/src/main/java/org/apache/james/imap/message/request/EnableRequest.java
copy to protocols/imap/src/test/java/org/apache/james/imap/api/message/CapabilityTest.java
index e285d27..f84a98a 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/request/EnableRequest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/api/message/CapabilityTest.java
@@ -16,28 +16,38 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.imap.message.request;
 
-import java.util.List;
+package org.apache.james.imap.api.message;
 
-import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.Tag;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-public class EnableRequest extends AbstractImapRequest {
+import org.junit.jupiter.api.Test;
 
-    private final List<String> capabilities;
+import nl.jqno.equalsverifier.EqualsVerifier;
 
-    public EnableRequest(Tag tag, ImapCommand command, List<String> capabilities) {
-        super(tag, command);
-        this.capabilities = capabilities;
+class CapabilityTest {
+    @Test
+    void shouldMatchBeanContract() {
+        EqualsVerifier.forClass(Capability.class)
+            .verify();
     }
-    
-    /**
-     * Return a List of <code>CAPABILITIES</code>. All these must be uppercase
-     * 
-     * @return caps
-     */
-    public List<String> getCapabilities() {
-        return capabilities;
+
+    @Test
+    void ofShouldThrowWhenNull() {
+        assertThatThrownBy(() -> Capability.of(null))
+            .isInstanceOf(NullPointerException.class);
+    }
+
+    @Test
+    void ofShouldThrowWhenEmpty() {
+        assertThatThrownBy(() -> Capability.of(""))
+            .isInstanceOf(IllegalArgumentException.class);
+    }
+
+    @Test
+    void ofShouldNormalizeCase() {
+        assertThat(Capability.of("a"))
+            .isEqualTo(Capability.of("A"));
     }
-}
+}
\ No newline at end of file
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/CapabilityProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/CapabilityProcessorTest.java
index cfebddf..cefb8eb 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/CapabilityProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/CapabilityProcessorTest.java
@@ -24,6 +24,7 @@ import java.util.Set;
 
 import org.apache.james.imap.api.ImapConfiguration;
 import org.apache.james.imap.api.ImapConstants;
+import org.apache.james.imap.api.message.Capability;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.processor.base.UnknownRequestProcessor;
@@ -49,7 +50,7 @@ public class CapabilityProcessorTest {
     public void condstoreShouldBeSupportedWhenSelectedFor() {
         testee.configure(ImapConfiguration.builder().isCondstoreEnable(true).build());
 
-        Set<String> supportedCapabilities = testee.getSupportedCapabilities(null);
+        Set<Capability> supportedCapabilities = testee.getSupportedCapabilities(null);
         assertThat(supportedCapabilities).contains(ImapConstants.SUPPORTS_CONDSTORE);
     }
 
@@ -57,7 +58,7 @@ public class CapabilityProcessorTest {
     public void condstoreShouldBeNotSupportedByDefault() {
         testee.configure(ImapConfiguration.builder().build());
 
-        Set<String> supportedCapabilities = testee.getSupportedCapabilities(null);
+        Set<Capability> supportedCapabilities = testee.getSupportedCapabilities(null);
         assertThat(supportedCapabilities).doesNotContain(ImapConstants.SUPPORTS_CONDSTORE);
     }
 }
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
index 4bbbf83..6f2dd62 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
@@ -90,7 +90,7 @@ public class MoveProcessorTest {
 
     @Test
     public void getImplementedCapabilitiesShouldContainMoveWhenSupportedByMailboxManager() {
-        assertThat(testee.getImplementedCapabilities(null)).containsExactly(ImapConstants.MOVE_COMMAND_NAME);
+        assertThat(testee.getImplementedCapabilities(null)).containsExactly(ImapConstants.SUPPORTS_MOVE);
     }
 
     @Test


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


[james-project] 15/15: [Refactoring] Move TikaTextExtractorTest to JUnit 5

Posted by bt...@apache.org.
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 c2d2a86b1f699b56d4156de3a4e49c89fcee35ec
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Tue Dec 10 10:46:40 2019 +0700

    [Refactoring] Move TikaTextExtractorTest to JUnit 5
---
 .../james/mailbox/tika/TikaTextExtractorTest.java  | 62 ++++++++++------------
 1 file changed, 29 insertions(+), 33 deletions(-)

diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaTextExtractorTest.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaTextExtractorTest.java
index 0d0fa75..2b0d126 100644
--- a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaTextExtractorTest.java
+++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaTextExtractorTest.java
@@ -20,6 +20,7 @@
 package org.apache.james.mailbox.tika;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -32,28 +33,23 @@ import org.apache.james.mailbox.extractor.ParsedContent;
 import org.apache.james.mailbox.extractor.TextExtractor;
 import org.apache.james.mailbox.tika.TikaTextExtractor.ContentAndMetadataDeserializer;
 import org.apache.james.metrics.api.NoopMetricFactory;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
 
 import com.fasterxml.jackson.databind.node.ArrayNode;
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.TextNode;
 
-public class TikaTextExtractorTest {
+class TikaTextExtractorTest {
 
-    private TextExtractor textExtractor;
+    TextExtractor textExtractor;
 
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
+    @RegisterExtension
+    static TikaExtension tika = new TikaExtension();
 
-    @ClassRule
-    public static TikaContainer tika = new TikaContainer();
-
-    @Before
-    public void setUp() throws Exception {
+    @BeforeEach
+    void setUp() throws Exception {
         textExtractor = new TikaTextExtractor(new NoopMetricFactory(), new TikaHttpClientImpl(TikaConfiguration.builder()
                 .host(tika.getIp())
                 .port(tika.getPort())
@@ -62,13 +58,13 @@ public class TikaTextExtractorTest {
     }
 
     @Test
-    public void textualContentShouldReturnEmptyWhenInputStreamIsEmpty() throws Exception {
+    void textualContentShouldReturnEmptyWhenInputStreamIsEmpty() throws Exception {
         assertThat(textExtractor.extractContent(IOUtils.toInputStream("", StandardCharsets.UTF_8), "text/plain").getTextualContent())
             .contains("");
     }
 
     @Test
-    public void textTest() throws Exception {
+    void textTest() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/Text.txt");
         assertThat(inputStream).isNotNull();
         assertThat(textExtractor.extractContent(inputStream, "text/plain").getTextualContent())
@@ -78,7 +74,7 @@ public class TikaTextExtractorTest {
     }
 
     @Test
-    public void textMicrosoftWorldTest() throws Exception {
+    void textMicrosoftWorldTest() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/writter.docx");
         assertThat(inputStream).isNotNull();
         assertThat(textExtractor.extractContent(inputStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document").getTextualContent())
@@ -88,7 +84,7 @@ public class TikaTextExtractorTest {
     }
 
     @Test
-    public void textOdtTest() throws Exception {
+    void textOdtTest() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/writter.odt");
         assertThat(inputStream).isNotNull();
         assertThat(textExtractor.extractContent(inputStream, "application/vnd.oasis.opendocument.text").getTextualContent())
@@ -98,7 +94,7 @@ public class TikaTextExtractorTest {
     }
 
     @Test
-    public void documentWithBadDeclaredMetadataShouldBeWellHandled() throws Exception {
+    void documentWithBadDeclaredMetadataShouldBeWellHandled() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/fake.txt");
         assertThat(inputStream).isNotNull();
         assertThat(textExtractor.extractContent(inputStream, "application/vnd.oasis.opendocument.text").getTextualContent())
@@ -108,7 +104,7 @@ public class TikaTextExtractorTest {
     }
     
     @Test
-    public void slidePowerPointTest() throws Exception {
+    void slidePowerPointTest() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/slides.pptx");
         assertThat(inputStream).isNotNull();
         assertThat(textExtractor.extractContent(inputStream, "application/vnd.openxmlformats-officedocument.presentationml.presentation").getTextualContent())
@@ -119,7 +115,7 @@ public class TikaTextExtractorTest {
     }
 
     @Test
-    public void slideOdpTest() throws Exception {
+    void slideOdpTest() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/slides.odp");
         assertThat(inputStream).isNotNull();
         assertThat(textExtractor.extractContent(inputStream, "application/vnd.oasis.opendocument.presentation").getTextualContent())
@@ -130,7 +126,7 @@ public class TikaTextExtractorTest {
     }
     
     @Test
-    public void pdfTest() throws Exception {
+    void pdfTest() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/PDF.pdf");
         assertThat(inputStream).isNotNull();
         assertThat(textExtractor.extractContent(inputStream, "application/pdf").getTextualContent())
@@ -140,7 +136,7 @@ public class TikaTextExtractorTest {
     }
     
     @Test
-    public void odsTest() throws Exception {
+    void odsTest() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/calc.ods");
         assertThat(inputStream).isNotNull();
         assertThat(textExtractor.extractContent(inputStream, "application/vnd.oasis.opendocument.spreadsheet").getTextualContent())
@@ -150,7 +146,7 @@ public class TikaTextExtractorTest {
     }
     
     @Test
-    public void excelTest() throws Exception {
+    void excelTest() throws Exception {
         InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/calc.xlsx");
         assertThat(inputStream).isNotNull();
         assertThat(textExtractor.extractContent(inputStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet").getTextualContent())
@@ -161,7 +157,7 @@ public class TikaTextExtractorTest {
     }
 
     @Test
-    public void deserializerShouldNotThrowWhenMoreThanOneNode() throws Exception {
+    void deserializerShouldNotThrowWhenMoreThanOneNode() throws Exception {
         TikaTextExtractor textExtractor = new TikaTextExtractor(
             new NoopMetricFactory(), 
             (inputStream, contentType) -> Optional.of(new ByteArrayInputStream(("[{\"X-TIKA:content\": \"This is an awesome LibreOffice document !\"}, " +
@@ -173,7 +169,7 @@ public class TikaTextExtractorTest {
     }
 
     @Test
-    public void deserializerShouldTakeFirstNodeWhenSeveral() throws Exception {
+    void deserializerShouldTakeFirstNodeWhenSeveral() throws Exception {
         String expectedExtractedContent = "content A";
         TikaTextExtractor textExtractor = new TikaTextExtractor(
             new NoopMetricFactory(), 
@@ -188,21 +184,21 @@ public class TikaTextExtractorTest {
     }
 
     @Test
-    public void deserializerShouldThrowWhenNodeIsNotAnObject() throws Exception {
-        expectedException.expect(IllegalStateException.class);
-        expectedException.expectMessage("The element should be a Json object");
-
+    void deserializerShouldThrowWhenNodeIsNotAnObject() {
         TikaTextExtractor textExtractor = new TikaTextExtractor(
             new NoopMetricFactory(), 
             (inputStream, contentType) -> Optional.of(new ByteArrayInputStream("[\"value1\"]"
                                                         .getBytes(StandardCharsets.UTF_8))));
 
         InputStream inputStream = new ByteArrayInputStream("toto".getBytes(StandardCharsets.UTF_8));
-        textExtractor.extractContent(inputStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+
+        assertThatThrownBy(() -> textExtractor.extractContent(inputStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
+            .isInstanceOf(IllegalStateException.class)
+            .hasMessage("The element should be a Json object");
     }
 
     @Test
-    public void asListOfStringShouldReturnASingletonWhenOneElement() {
+    void asListOfStringShouldReturnASingletonWhenOneElement() {
         ContentAndMetadataDeserializer deserializer = new TikaTextExtractor.ContentAndMetadataDeserializer();
         List<String> listOfString = deserializer.asListOfString(TextNode.valueOf("text"));
         
@@ -210,7 +206,7 @@ public class TikaTextExtractorTest {
     }
 
     @Test
-    public void asListOfStringShouldReturnAListWhenMultipleElements() {
+    void asListOfStringShouldReturnAListWhenMultipleElements() {
         ArrayNode jsonArray = new ArrayNode(JsonNodeFactory.instance)
             .add("first")
             .add("second")


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


[james-project] 05/15: [Refactoring] Remove unused IMAP constants

Posted by bt...@apache.org.
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 eb53f4992ad65eb3c6b10d8c12f1173574f25adc
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Dec 11 09:40:37 2019 +0700

    [Refactoring] Remove unused IMAP constants
---
 .../org/apache/james/imap/api/ImapConstants.java   | 30 ----------------------
 1 file changed, 30 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConstants.java b/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConstants.java
index 17162f3..d5026f1 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConstants.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/api/ImapConstants.java
@@ -41,20 +41,10 @@ public interface ImapConstants {
 
     String UID = "UID";
 
-    String MIME_HEADER_CONTENT_LOCATION = "Content-Location";
-
-    String MIME_HEADER_CONTENT_MD5 = "Content-MD5";
-
-    String MIME_HEADER_CONTENT_LANGUAGE = "Content-Language";
-
-    String[] EMPTY_STRING_ARRAY = {};
-
     byte BYTE_OPENING_PARENTHESIS = 0x28;
 
     byte BYTE_CLOSING_PARENTHESIS = 0x29;
 
-    byte BYTE_SP = 0x20;
-
     byte BYTE_DQUOTE = 0x22;
 
     byte BYTE_BACK_SLASH = 0x5C;
@@ -69,16 +59,6 @@ public interface ImapConstants {
 
     byte BYTE_CLOSE_BRACE = 0x7D;
 
-    char OPENING_PARENTHESIS = '(';
-
-    char CLOSING_PARENTHESIS = ')';
-
-    char OPENING_SQUARE_BRACKET = '[';
-
-    char CLOSING_SQUARE_BRACKET = ']';
-
-    char SP_CHAR = ' ';
-
     char DQUOTE = '\"';
 
     String VERSION = "IMAP4rev1";
@@ -89,8 +69,6 @@ public interface ImapConstants {
 
     Capability SUPPORTS_RFC3348 = Capability.of("CHILDREN");
 
-    String UTF8 = "UTF-8";
-
     Capability SUPPORTS_I18NLEVEL_1 = Capability.of("I18NLEVEL=1");
 
     Capability SUPPORTS_NAMESPACES = Capability.of("NAMESPACE");
@@ -279,12 +257,6 @@ public interface ImapConstants {
 
     String NAME_ATTRIBUTE_UNMARKED = "\\Unmarked";
 
-    String PS_TEXT = "TEXT";
-
-    String PS_HEADER = "HEADER";
-
-    String PS_MIME = "MIME";
-
     String FETCH_RFC822 = "RFC822";
 
     String FETCH_RFC822_HEADER = "RFC822.HEADER";
@@ -306,8 +278,6 @@ public interface ImapConstants {
 
     String COMPRESS_COMMAND_NAME = "COMPRESS";
 
-    int DEFAULT_BATCH_SIZE = 100;
-
     // Quota resources definition
 
     String STORAGE_QUOTA_RESOURCE = "STORAGE";


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


[james-project] 07/15: [Refactoring] Create a Tika extension for JUnit 5 in mailbox-tika package

Posted by bt...@apache.org.
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 8ba41230807e58c54c1b2c5df5895e1ac127c9de
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Fri Dec 6 14:59:55 2019 +0700

    [Refactoring] Create a Tika extension for JUnit 5 in mailbox-tika package
---
 .../apache/james/mailbox/tika/TikaExtension.java   | 67 ++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaExtension.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaExtension.java
new file mode 100644
index 0000000..82f924d
--- /dev/null
+++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaExtension.java
@@ -0,0 +1,67 @@
+/****************************************************************
+ * 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.mailbox.tika;
+
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.ParameterContext;
+import org.junit.jupiter.api.extension.ParameterResolutionException;
+import org.junit.jupiter.api.extension.ParameterResolver;
+
+public class TikaExtension implements AfterAllCallback, BeforeAllCallback, ParameterResolver {
+    private final TikaContainer tika;
+
+    public TikaExtension() {
+        this.tika = new TikaContainer();
+    }
+
+    @Override
+    public void beforeAll(ExtensionContext extensionContext) {
+        tika.start();
+    }
+
+    @Override
+    public void afterAll(ExtensionContext extensionContext) {
+        tika.stop();
+    }
+
+    @Override
+    public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+        return (parameterContext.getParameter().getType() == TikaContainer.class);
+    }
+
+    @Override
+    public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
+        return tika;
+    }
+
+    public String getIp() {
+        return tika.getIp();
+    }
+
+    public int getPort() {
+        return tika.getPort();
+    }
+
+    public int getTimeoutInMillis() {
+        return tika.getTimeoutInMillis();
+    }
+}


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


[james-project] 03/15: [Refactoring] Stop mocking ImapSession

Posted by bt...@apache.org.
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 528c0f04898e8109af91723ffe37b043a6a9c117
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Dec 11 11:30:03 2019 +0700

    [Refactoring] Stop mocking ImapSession
    
    Use FakeImapSession instead.
    
    This allows reducing mockito footprint in IMAP unti tests...
---
 .../decode/parser/CreateCommandParserTest.java     | 20 ++++++++----------
 .../parser/FetchCommandParserPartialFetchTest.java |  4 ++--
 .../parser/GetAnnotationCommandParserTest.java     |  3 ++-
 .../parser/SearchCommandParserCharsetTest.java     |  7 ++-----
 .../SearchCommandParserQuotedCharsetTest.java      |  3 ++-
 .../imap/encode/NamespaceResponseEncoderTest.java  |  2 +-
 .../ImapRequestHandlerAdandonConnectionTest.java   |  6 ++----
 .../imap/processor/GetQuotaProcessorTest.java      | 22 ++++++++------------
 .../james/imap/processor/LSubProcessorTest.java    |  5 +++--
 .../imap/processor/NamespaceProcessorTest.java     | 24 ++++++++++------------
 .../james/imap/processor/SearchProcessorTest.java  | 14 ++++++-------
 .../imap/processor/SetQuotaProcessorTest.java      | 23 ++++++++-------------
 .../processor/base/MailboxEventAnalyserTest.java   | 10 ++++-----
 .../processor/base/SelectedMailboxImplTest.java    |  8 ++++----
 14 files changed, 63 insertions(+), 88 deletions(-)

diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CreateCommandParserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CreateCommandParserTest.java
index c2bbd10..7c9e6ed 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CreateCommandParserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/CreateCommandParserTest.java
@@ -22,8 +22,6 @@ package org.apache.james.imap.decode.parser;
 import static org.apache.james.imap.ImapFixture.TAG;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
@@ -32,9 +30,9 @@ import java.nio.charset.StandardCharsets;
 
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.CreateRequest;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
@@ -45,16 +43,14 @@ public class CreateCommandParserTest {
     private static final OutputStream outputStream = null;
     private static final ImapCommand command = ImapCommand.anyStateCommand("Command");
 
-    private ImapSession mockImapSession;
-    private MailboxSession mailboxSession;
+    private FakeImapSession imapSession;
     private CreateCommandParser parser;
 
     @Before
     public void setUp() throws Exception {
-        mockImapSession = mock(ImapSession.class);
-        mailboxSession = MailboxSessionUtil.create(Username.of("userName"));
-
-        when(mockImapSession.getMailboxSession()).thenReturn(mailboxSession);
+        MailboxSession mailboxSession = MailboxSessionUtil.create(Username.of("userName"));
+        imapSession = new FakeImapSession();
+        imapSession.setMailboxSession(mailboxSession);
 
         parser = new CreateCommandParser();
     }
@@ -64,7 +60,7 @@ public class CreateCommandParserTest {
         InputStream inputStream = new ByteArrayInputStream(" \n".getBytes(StandardCharsets.US_ASCII));
         ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream);
 
-        assertThatThrownBy(() -> parser.decode(command, lineReader, TAG, mockImapSession))
+        assertThatThrownBy(() -> parser.decode(command, lineReader, TAG, imapSession))
             .isInstanceOf(DecodingException.class);
     }
 
@@ -73,7 +69,7 @@ public class CreateCommandParserTest {
         InputStream inputStream = new ByteArrayInputStream("..\n".getBytes(StandardCharsets.US_ASCII));
         ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream);
 
-        assertThatThrownBy(() -> parser.decode(command, lineReader, TAG, mockImapSession))
+        assertThatThrownBy(() -> parser.decode(command, lineReader, TAG, imapSession))
             .isInstanceOf(DecodingException.class);
     }
 
@@ -82,7 +78,7 @@ public class CreateCommandParserTest {
         InputStream inputStream = new ByteArrayInputStream(".AnyMailbox.\n".getBytes(StandardCharsets.US_ASCII));
         ImapRequestStreamLineReader lineReader = new ImapRequestStreamLineReader(inputStream, outputStream);
 
-        CreateRequest imapMessage = (CreateRequest)parser.decode(command, lineReader, TAG, mockImapSession);
+        CreateRequest imapMessage = (CreateRequest)parser.decode(command, lineReader, TAG, imapSession);
         assertThat(imapMessage.getMailboxName()).isEqualTo(".AnyMailbox");
     }
 
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
index 17cc5f0..8b4f8c8 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/FetchCommandParserPartialFetchTest.java
@@ -21,7 +21,6 @@ package org.apache.james.imap.decode.parser;
 
 import static org.apache.james.imap.ImapFixture.TAG;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.mockito.Mockito.mock;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -37,6 +36,7 @@ import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -50,7 +50,7 @@ public class FetchCommandParserPartialFetchTest  {
     public void setUp() throws Exception {
         parser = new FetchCommandParser();
         command = ImapCommand.anyStateCommand("Command");
-        session = mock(ImapSession.class);
+        session = new FakeImapSession();
     }
 
     @Test
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/GetAnnotationCommandParserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/GetAnnotationCommandParserTest.java
index 838bec4..38b5481 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/GetAnnotationCommandParserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/GetAnnotationCommandParserTest.java
@@ -31,6 +31,7 @@ import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.GetAnnotationRequest;
 import org.apache.james.imap.message.request.GetAnnotationRequest.Depth;
 import org.apache.james.mailbox.model.MailboxAnnotationKey;
@@ -42,7 +43,7 @@ public class GetAnnotationCommandParserTest {
     private static final MailboxAnnotationKey PRIVATE_KEY = new MailboxAnnotationKey("/private/comment");
     private static final MailboxAnnotationKey SHARED_KEY = new MailboxAnnotationKey("/shared/comment");
     private static final ImapCommand command = ImapCommand.anyStateCommand("Command");
-    private static final ImapSession session = null;
+    private static final ImapSession session = new FakeImapSession();
     private static final OutputStream outputStream = null;
 
     private GetAnnotationCommandParser parser;
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
index 4191aa2..805ff55 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserCharsetTest.java
@@ -39,9 +39,9 @@ import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.message.request.SearchKey;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -70,14 +70,11 @@ public class SearchCommandParserCharsetTest {
     ImapCommand command;
     ImapMessage message;
 
-    private ImapSession session;
-
     @Before
     public void setUp() throws Exception {
         parser = new SearchCommandParser();
         command = ImapCommand.anyStateCommand("Command");
         message = mock(ImapMessage.class);
-        session = mock(ImapSession.class);
 
         mockStatusResponseFactory = mock(StatusResponseFactory.class);
         parser.setStatusResponseFactory(mockStatusResponseFactory);
@@ -88,7 +85,7 @@ public class SearchCommandParserCharsetTest {
         ImapRequestLineReader reader = new ImapRequestStreamLineReader(
                 new ByteArrayInputStream("CHARSET BOGUS ".getBytes(StandardCharsets.US_ASCII)),
                 new ByteArrayOutputStream());
-        parser.decode(command, reader, TAG, false, session);
+        parser.decode(command, reader, TAG, false, new FakeImapSession());
 
         verify(mockStatusResponseFactory, times(1)).taggedNo(
             eq(TAG),
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
index fe8f0f8..5fb2dc7 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/decode/parser/SearchCommandParserQuotedCharsetTest.java
@@ -44,6 +44,7 @@ import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.DecodingException;
 import org.apache.james.imap.decode.ImapRequestLineReader;
 import org.apache.james.imap.decode.ImapRequestStreamLineReader;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -138,7 +139,7 @@ public class SearchCommandParserQuotedCharsetTest {
         command = ImapCommand.anyStateCommand("Command");
         message = mock(ImapMessage.class);
         mockStatusResponseFactory = mock(StatusResponseFactory.class);
-        session = mock(ImapSession.class);
+        session = new FakeImapSession();
 
         parser.setStatusResponseFactory(mockStatusResponseFactory);
     }
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java
index c70cb02..0226d68 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/NamespaceResponseEncoderTest.java
@@ -44,7 +44,7 @@ public class NamespaceResponseEncoderTest {
 
     @Before
     public void setUp() throws Exception {
-        dummySession = mock(ImapSession.class);
+        dummySession = new FakeImapSession();
         final ImapEncoder stubNextEncoderInChain = mock(ImapEncoder.class);
         subject = new NamespaceResponseEncoder(stubNextEncoderInChain);
         mockComposer = mock(ImapResponseComposer.class);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java b/protocols/imap/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
index e875212..be93819 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
@@ -25,9 +25,9 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 
 import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.decode.ImapDecoder;
 import org.apache.james.imap.decode.main.ImapRequestStreamHandler;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.encode.ImapEncoder;
 import org.junit.Before;
 import org.junit.Test;
@@ -45,7 +45,6 @@ public class ImapRequestHandlerAdandonConnectionTest {
     ImapDecoder decoderStub;
     ImapProcessor processorStub;
     ImapEncoder encoderStub;
-    ImapSession sessionStub;
     
     @Before
     public void setUp() throws Exception {
@@ -55,7 +54,6 @@ public class ImapRequestHandlerAdandonConnectionTest {
         decoderStub = mock(ImapDecoder.class);
         processorStub = mock(ImapProcessor.class);
         encoderStub = mock(ImapEncoder.class);
-        sessionStub = mock(ImapSession.class);
         // System under test
         subject = new ImapRequestStreamHandler(decoderStub, processorStub, encoderStub);
     }
@@ -69,7 +67,7 @@ public class ImapRequestHandlerAdandonConnectionTest {
         // 
         // Exercise
         //
-        boolean result = subject.handleRequest(fakeInput, fakeOutput, sessionStub);
+        boolean result = subject.handleRequest(fakeInput, fakeOutput, new FakeImapSession());
         
         //
         // Verify output
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
index c7d583b..c1cbd79 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/GetQuotaProcessorTest.java
@@ -36,10 +36,10 @@ import org.apache.james.core.quota.QuotaCountUsage;
 import org.apache.james.core.quota.QuotaSizeLimit;
 import org.apache.james.core.quota.QuotaSizeUsage;
 import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.ImapSessionState;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.GetQuotaRequest;
 import org.apache.james.imap.message.response.QuotaResponse;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
@@ -72,7 +72,7 @@ public class GetQuotaProcessorTest {
         Quota.<QuotaSizeLimit, QuotaSizeUsage>builder().used(QuotaSizeUsage.size(240)).computedLimit(QuotaSizeLimit.size(15890)).build();
 
     private GetQuotaProcessor testee;
-    private ImapSession mockedImapSession;
+    private ImapSession imapSession;
     private ImapProcessor.Responder mockedResponder;
     private QuotaManager mockedQuotaManager;
     private QuotaRootResolver mockedQuotaRootResolver;
@@ -84,7 +84,7 @@ public class GetQuotaProcessorTest {
     public void setUp() throws Exception {
         mailboxSession = MailboxSessionUtil.create(PLOP);
         UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
-        mockedImapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mockedQuotaManager = mock(QuotaManager.class);
         mockedQuotaRootResolver = mock(QuotaRootResolver.class);
         when(mockedQuotaRootResolver.fromString(eq(QUOTA_ROOT.getValue()))).thenReturn(QUOTA_ROOT);
@@ -94,15 +94,14 @@ public class GetQuotaProcessorTest {
             statusResponseFactory, mockedQuotaManager, mockedQuotaRootResolver, new NoopMetricFactory());
         mailbox = mock(Mailbox.class);
         when(mailbox.generateAssociatedPath()).thenReturn(MAILBOX_PATH);
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
     }
 
     @Test
     public void processorShouldWorkOnValidRights() throws Exception {
         GetQuotaRequest getQuotaRequest = new GetQuotaRequest(TAG, ImapCommand.anyStateCommand("Name"), QUOTA_ROOT.getValue());
 
-        when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getMailboxSession())
-            .thenReturn(mailboxSession);
         when(mockedQuotaRootResolver.retrieveAssociatedMailboxes(QUOTA_ROOT, mailboxSession))
             .thenReturn(ImmutableList.of(mailbox));
         when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession))
@@ -113,7 +112,7 @@ public class GetQuotaProcessorTest {
         QuotaResponse storageQuotaResponse = new QuotaResponse("STORAGE", "plop", STORAGE_QUOTA);
         QuotaResponse messageQuotaResponse = new QuotaResponse("MESSAGE", "plop", MESSAGE_QUOTA);
 
-        testee.doProcess(getQuotaRequest, mockedResponder, mockedImapSession);
+        testee.doProcess(getQuotaRequest, mockedResponder, imapSession);
 
         ArgumentCaptor<ImapResponseMessage> argumentCaptor = ArgumentCaptor.forClass(ImapResponseMessage.class);
         verify(mockedResponder, times(3)).respond(argumentCaptor.capture());
@@ -130,8 +129,6 @@ public class GetQuotaProcessorTest {
     public void processorShouldWorkOnExceptionThrown() throws Exception {
         GetQuotaRequest getQuotaRequest = new GetQuotaRequest(TAG, ImapCommand.anyStateCommand("Name"), QUOTA_ROOT.getValue());
 
-        when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getMailboxSession()).thenReturn(mailboxSession);
         when(mockedQuotaRootResolver.retrieveAssociatedMailboxes(QUOTA_ROOT, mailboxSession))
             .thenReturn(ImmutableList.of(mailbox));
         when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession))
@@ -139,7 +136,7 @@ public class GetQuotaProcessorTest {
         when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenThrow(new MailboxException());
         when(mockedQuotaManager.getStorageQuota(QUOTA_ROOT)).thenReturn(STORAGE_QUOTA);
 
-        testee.doProcess(getQuotaRequest, mockedResponder, mockedImapSession);
+        testee.doProcess(getQuotaRequest, mockedResponder, imapSession);
 
         ArgumentCaptor<ImapResponseMessage> argumentCaptor = ArgumentCaptor.forClass(ImapResponseMessage.class);
         verify(mockedResponder).respond(argumentCaptor.capture());
@@ -154,14 +151,12 @@ public class GetQuotaProcessorTest {
     public void processorShouldWorkOnNoRights() throws Exception {
         GetQuotaRequest getQuotaRequest = new GetQuotaRequest(TAG, ImapCommand.anyStateCommand("Name"), QUOTA_ROOT.getValue());
 
-        when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getMailboxSession()).thenReturn(mailboxSession);
         when(mockedQuotaRootResolver.retrieveAssociatedMailboxes(QUOTA_ROOT, mailboxSession))
             .thenReturn(ImmutableList.of(mailbox));
         when(mockedMailboxManager.hasRight(MAILBOX_PATH, MailboxACL.Right.Read, mailboxSession))
             .thenReturn(false);
 
-        testee.doProcess(getQuotaRequest, mockedResponder, mockedImapSession);
+        testee.doProcess(getQuotaRequest, mockedResponder, imapSession);
 
         ArgumentCaptor<ImapResponseMessage> argumentCaptor = ArgumentCaptor.forClass(ImapResponseMessage.class);
         verify(mockedResponder).respond(argumentCaptor.capture());
@@ -171,5 +166,4 @@ public class GetQuotaProcessorTest {
             .hasSize(1)
             .allMatch(StatusResponseTypeMatcher.NO_RESPONSE_MATCHER::matches);
     }
-
 }
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
index 211ebd6..897a98c 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
@@ -36,6 +36,7 @@ import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.LsubRequest;
 import org.apache.james.imap.message.response.LSubResponse;
 import org.apache.james.mailbox.MailboxManager;
@@ -87,7 +88,7 @@ public class LSubProcessorTest {
     public void setUp() throws Exception {
         subscriptions = new ArrayList<>();
         serverResponseFactory = mock(StatusResponseFactory.class);
-        session = mock(ImapSession.class);
+        session = new FakeImapSession();
         command = ImapCommand.anyStateCommand("Command");
         next = mock(ImapProcessor.class);
         responder = mock(ImapProcessor.Responder.class);
@@ -97,6 +98,7 @@ public class LSubProcessorTest {
         manager =  mock(SubscriptionManager.class);
         mailboxSession = MailboxSessionUtil.create(USER);
         processor = new LSubProcessor(next, mock(MailboxManager.class), manager, serverResponseFactory, new NoopMetricFactory());
+        session.setMailboxSession(mailboxSession);
     }
 
     @Test
@@ -183,7 +185,6 @@ public class LSubProcessorTest {
     }
 
     private void expectSubscriptions() throws Exception {
-        when(session.getMailboxSession()).thenReturn(mailboxSession);
         when(manager.subscriptions(mailboxSession)).thenReturn(subscriptions);
     }
 }
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
index 2606938..f6e868d 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
@@ -21,6 +21,7 @@ package org.apache.james.imap.processor;
 import static org.apache.james.imap.ImapFixture.TAG;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
@@ -40,6 +41,7 @@ import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
 import org.apache.james.imap.api.process.ImapProcessor.Responder;
 import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.NamespaceRequest;
 import org.apache.james.imap.message.response.NamespaceResponse;
 import org.apache.james.mailbox.MailboxManager;
@@ -58,7 +60,7 @@ public class NamespaceProcessorTest {
     
     NamespaceProcessor subject;
     StatusResponseFactory statusResponseStub;
-    ImapSession imapSessionStub;
+    ImapSession imapSession;
     MailboxSession mailboxSession;
     NamespaceRequest namespaceRequest;
     Collection<String> sharedSpaces;
@@ -70,32 +72,30 @@ public class NamespaceProcessorTest {
         statusResponseStub = mock(StatusResponseFactory.class);
         mailboxManagerStub = mock(MailboxManager.class);
         subject = new NamespaceProcessor(mock(ImapProcessor.class), mailboxManagerStub, statusResponseStub, new NoopMetricFactory());
-        imapSessionStub = mock(ImapSession.class);
+        imapSession = spy(new FakeImapSession());
         mailboxSession = mock(MailboxSession.class);
      
         namespaceRequest = new NamespaceRequest(ImapCommand.anyStateCommand("Name"), TAG);
-       
+        imapSession.setMailboxSession(mailboxSession);
     }
 
     @Test
     public void testNamespaceResponseShouldContainPersonalAndUserSpaces() {
-        when(imapSessionStub.supportMultipleNamespaces()).thenReturn(true);
-        when(imapSessionStub.getMailboxSession()).thenReturn(mailboxSession);
-        when(imapSessionStub.getAttribute(EnableProcessor.ENABLED_CAPABILITIES)).thenReturn(null);
+        when(imapSession.supportMultipleNamespaces()).thenReturn(true);
 
         when(mailboxSession.getPersonalSpace()).thenReturn(PERSONAL_PREFIX);
         when(mailboxSession.getOtherUsersSpace()).thenReturn(USERS_PREFIX);
         when(mailboxSession.getSharedSpaces()).thenReturn(new ArrayList<>());
         when(mailboxSession.getPathDelimiter()).thenReturn(MailboxConstants.DEFAULT_DELIMITER);
 
-        when(imapSessionStub.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
+        when(imapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
         when(statusResponseStub.taggedOk(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class)))
             .thenReturn(mock(StatusResponse.class));
 
         final NamespaceResponse response = buildResponse(null);
         final Responder responderMock = mock(Responder.class);
 
-        subject.doProcess(namespaceRequest, responderMock, imapSessionStub);
+        subject.doProcess(namespaceRequest, responderMock, imapSession);
 
         verify(responderMock, times(1)).respond(response);
         verify(responderMock, times(1)).respond(any(StatusResponse.class));
@@ -104,16 +104,14 @@ public class NamespaceProcessorTest {
     
     @Test
     public void testNamespaceResponseShouldContainSharedSpaces() {
-        when(imapSessionStub.supportMultipleNamespaces()).thenReturn(true);
-        when(imapSessionStub.getMailboxSession()).thenReturn(mailboxSession);
-        when(imapSessionStub.getAttribute(EnableProcessor.ENABLED_CAPABILITIES)).thenReturn(null);
+        when(imapSession.supportMultipleNamespaces()).thenReturn(true);
 
         when(mailboxSession.getPersonalSpace()).thenReturn(PERSONAL_PREFIX);
         when(mailboxSession.getOtherUsersSpace()).thenReturn(USERS_PREFIX);
         when(mailboxSession.getSharedSpaces()).thenReturn(Arrays.asList(SHARED_PREFIX));
         when(mailboxSession.getPathDelimiter()).thenReturn(MailboxConstants.DEFAULT_DELIMITER);
 
-        when(imapSessionStub.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
+        when(imapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
         when(statusResponseStub.taggedOk(any(Tag.class), any(ImapCommand.class), any(HumanReadableText.class)))
             .thenReturn(mock(StatusResponse.class));
         
@@ -123,7 +121,7 @@ public class NamespaceProcessorTest {
         
         final Responder responderMock = mock(Responder.class);
 
-        subject.doProcess(namespaceRequest, responderMock, imapSessionStub);
+        subject.doProcess(namespaceRequest, responderMock, imapSession);
 
         verify(responderMock, times(1)).respond(response);
         verify(responderMock, times(1)).respond(any(StatusResponse.class));
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
index 7fdf373..9a6f3d3 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
@@ -51,8 +51,8 @@ import org.apache.james.imap.api.message.request.SearchOperation;
 import org.apache.james.imap.api.message.response.StatusResponse;
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.api.process.SelectedMailbox;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.SearchRequest;
 import org.apache.james.imap.message.response.SearchResponse;
 import org.apache.james.mailbox.MailboxManager;
@@ -108,7 +108,7 @@ public class SearchProcessorTest {
     SearchProcessor processor;
     ImapProcessor next;
     ImapProcessor.Responder responder;
-    ImapSession session;
+    FakeImapSession session;
     ImapCommand command;
     StatusResponseFactory serverResponseFactory;
     StatusResponse statusResponse;
@@ -120,7 +120,7 @@ public class SearchProcessorTest {
     @Before
     public void setUp() throws Exception {
         serverResponseFactory = mock(StatusResponseFactory.class);
-        session = mock(ImapSession.class);
+        session = new FakeImapSession();
         command = ImapCommand.anyStateCommand("Command");
         next = mock(ImapProcessor.class);
         responder = mock(ImapProcessor.Responder.class);
@@ -141,7 +141,7 @@ public class SearchProcessorTest {
     }
 
     private void allowUnsolicitedResponses() {
-        when(session.getMailboxSession()).thenReturn(mailboxSession);
+        session.setMailboxSession(mailboxSession);
     }
 
     @Test
@@ -196,7 +196,7 @@ public class SearchProcessorTest {
 
     private void expectsGetSelectedMailbox() throws Exception {
         when(mailboxManager.getMailbox(mailboxId, mailboxSession)).thenReturn(mailbox, mailbox);
-        when(session.getSelected()).thenReturn(selectedMailbox);
+        session.selected(selectedMailbox);
         when(selectedMailbox.isRecentUidRemoved()).thenReturn(false);
         when(selectedMailbox.isSizeChanged()).thenReturn(false);
         when(selectedMailbox.getPath()).thenReturn(mailboxPath);
@@ -466,8 +466,7 @@ public class SearchProcessorTest {
     }
 
     private void check(SearchKey key, final SearchQuery query) throws Exception {
-        when(session.getAttribute(SearchProcessor.SEARCH_MODSEQ)).thenReturn(null);
-        when(session.getMailboxSession()).thenReturn(mailboxSession);
+        session.setMailboxSession(mailboxSession);
         when(mailbox.search(query, mailboxSession)).thenReturn(Stream.empty());
         when(selectedMailbox.getApplicableFlags()).thenReturn(new Flags());
         when(selectedMailbox.hasNewApplicableFlags()).thenReturn(false);
@@ -485,7 +484,6 @@ public class SearchProcessorTest {
     private void verifyCalls() {
         verify(selectedMailbox).resetEvents();
 
-        verify(session).setAttribute(SearchProcessor.SEARCH_MODSEQ, null);
         verify(responder).respond(new SearchResponse(EMPTY, null));
 
         verify(responder).respond(same(statusResponse));
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
index 7a67573..a437f2e 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/SetQuotaProcessorTest.java
@@ -24,14 +24,12 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
 
 import org.apache.james.core.Username;
 import org.apache.james.imap.api.ImapCommand;
-import org.apache.james.imap.api.ImapSessionState;
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.imap.message.request.SetQuotaRequest;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
 import org.apache.james.mailbox.MailboxManager;
@@ -44,31 +42,26 @@ import org.mockito.ArgumentCaptor;
 
 public class SetQuotaProcessorTest {
     private SetQuotaProcessor testee;
-    private ImapSession mockedImapSession;
+    private FakeImapSession imapSession;
     private ImapProcessor.Responder mockedResponder;
-    private MailboxManager mockedMailboxManager;
-    private MailboxSession mailboxSession;
 
     @Before
     public void setUp() {
-        mailboxSession = MailboxSessionUtil.create(Username.of("plop"));
+        MailboxSession mailboxSession = MailboxSessionUtil.create(Username.of("plop"));
         UnpooledStatusResponseFactory statusResponseFactory = new UnpooledStatusResponseFactory();
-        mockedImapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mockedResponder = mock(ImapProcessor.Responder.class);
-        mockedMailboxManager = mock(MailboxManager.class);
-        testee = new SetQuotaProcessor(mock(ImapProcessor.class), mockedMailboxManager,
+        testee = new SetQuotaProcessor(mock(ImapProcessor.class), mock(MailboxManager.class),
             statusResponseFactory, new NoopMetricFactory());
+        imapSession.authenticated();
+        imapSession.setMailboxSession(mailboxSession);
     }
 
     @Test
     public void processorShouldWorkOnNoRights() {
         SetQuotaRequest setQuotaRequest = new SetQuotaRequest(TAG, ImapCommand.anyStateCommand("Name"), "quotaRoot");
 
-        when(mockedImapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mockedImapSession.getMailboxSession())
-            .thenReturn(mailboxSession);
-
-        testee.doProcess(setQuotaRequest, mockedResponder, mockedImapSession);
+        testee.doProcess(setQuotaRequest, mockedResponder, imapSession);
 
         ArgumentCaptor<ImapResponseMessage> imapResponseMessageArgumentCaptor = ArgumentCaptor.forClass(ImapResponseMessage.class);
         verify(mockedResponder).respond(imapResponseMessageArgumentCaptor.capture());
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 1ba1f14..d45c82a 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -31,8 +31,7 @@ import javax.mail.Flags;
 
 import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.core.Username;
-import org.apache.james.imap.api.ImapSessionState;
-import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
@@ -130,11 +129,10 @@ public class MailboxEventAnalyserTest {
 
     @Before
     public void setUp() throws MailboxException {
-        ImapSession imapSession = mock(ImapSession.class);
+        FakeImapSession imapSession = new FakeImapSession();
         InVMEventBus eventBus = new InVMEventBus(new InVmEventDelivery(new NoopMetricFactory()));
-        when(imapSession.getMailboxSession())
-            .thenReturn(MAILBOX_SESSION);
-        when(imapSession.getState()).thenReturn(ImapSessionState.AUTHENTICATED);
+        imapSession.setMailboxSession(MAILBOX_SESSION);
+        imapSession.authenticated();
 
         MailboxManager mailboxManager = mock(MailboxManager.class);
         MessageManager messageManager = mock(MessageManager.class);
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
index d0ed403..7144f3f 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/SelectedMailboxImplTest.java
@@ -37,7 +37,7 @@ import java.util.stream.Stream;
 import javax.mail.Flags;
 
 import org.apache.james.core.Username;
-import org.apache.james.imap.api.process.ImapSession;
+import org.apache.james.imap.encode.FakeImapSession;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MailboxSessionUtil;
@@ -74,7 +74,7 @@ public class SelectedMailboxImplTest {
     private MailboxManager mailboxManager;
     private MessageManager messageManager;
     private MailboxPath mailboxPath;
-    private ImapSession imapSession;
+    private FakeImapSession imapSession;
     private Mailbox mailbox;
     private TestId mailboxId;
     private EventBus eventBus;
@@ -87,7 +87,7 @@ public class SelectedMailboxImplTest {
         mailboxPath = MailboxPath.inbox(Username.of("tellier@linagora.com"));
         mailboxManager = mock(MailboxManager.class);
         messageManager = mock(MessageManager.class);
-        imapSession = mock(ImapSession.class);
+        imapSession = new FakeImapSession();
         mailbox = mock(Mailbox.class);
         mailboxId = TestId.of(42);
         mailboxIdRegistrationKey = new MailboxIdRegistrationKey(mailboxId);
@@ -101,7 +101,7 @@ public class SelectedMailboxImplTest {
             .then(delayedSearchAnswer());
         when(messageManager.getId()).thenReturn(mailboxId);
 
-        when(imapSession.getMailboxSession()).thenReturn(mock(MailboxSession.class));
+        imapSession.setMailboxSession(mock(MailboxSession.class));
 
         when(mailbox.generateAssociatedPath()).thenReturn(mailboxPath);
         when(mailbox.getMailboxId()).thenReturn(mailboxId);


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


[james-project] 14/15: [Refactoring] Move TikaConfigurationTest to JUnit 5

Posted by bt...@apache.org.
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 c35858b24b074504fd4f1ace9a8af0dca001c276
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Tue Dec 10 10:43:03 2019 +0700

    [Refactoring] Move TikaConfigurationTest to JUnit 5
---
 .../java/org/apache/james/mailbox/tika/TikaConfigurationTest.java   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaConfigurationTest.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaConfigurationTest.java
index b83ed85..1bc8734 100644
--- a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaConfigurationTest.java
+++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/TikaConfigurationTest.java
@@ -19,14 +19,14 @@
 
 package org.apache.james.mailbox.tika;
 
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
 
-public class TikaConfigurationTest {
+class TikaConfigurationTest {
 
     @Test
-    public void shouldMatchBeanContract() {
+    void shouldMatchBeanContract() {
         EqualsVerifier.forClass(TikaConfiguration.class)
             .verify();
     }


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


[james-project] 06/15: [Refactoring] CapabilityResponse: standardize equals and hashCode

Posted by bt...@apache.org.
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 4f6b2952776eeb631991e91bc22841731ac64070
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Dec 11 09:43:34 2019 +0700

    [Refactoring] CapabilityResponse: standardize equals and hashCode
---
 .../imap/message/response/CapabilityResponse.java  | 34 +++++++---------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/CapabilityResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/CapabilityResponse.java
index 3da1b76..8e8bb7f 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/CapabilityResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/CapabilityResponse.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.imap.message.response;
 
+import java.util.Objects;
 import java.util.Set;
 
 import org.apache.james.imap.api.message.Capability;
@@ -52,33 +53,18 @@ public class CapabilityResponse implements ImapResponseMessage {
     }
 
     @Override
-    public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + ((capabilities == null) ? 0 : capabilities.hashCode());
-        return result;
+    public final boolean equals(Object o) {
+        if (o instanceof CapabilityResponse) {
+            CapabilityResponse that = (CapabilityResponse) o;
+
+            return Objects.equals(this.capabilities, that.capabilities);
+        }
+        return false;
     }
 
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final CapabilityResponse other = (CapabilityResponse) obj;
-        if (capabilities == null) {
-            if (other.capabilities != null) {
-                return false;
-            }
-        } else if (!capabilities.equals(other.capabilities)) {
-            return false;
-        }
-        return true;
+    public final int hashCode() {
+        return Objects.hash(capabilities);
     }
 
     /**


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