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 <[email protected]>
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("[email protected]"));
         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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to