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 2018/12/18 08:00:51 UTC

[08/13] james-project git commit: MAILBOX-365 Get rid of some MailboxSession mocks

MAILBOX-365 Get rid of some MailboxSession mocks

We can now use directly the POJO with its testing factory methods


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

Branch: refs/heads/master
Commit: 8810856058a0263b5916fa61f0a78a5db88e04b4
Parents: 71c5a80
Author: Benoit Tellier <bt...@linagora.com>
Authored: Sat Dec 15 17:01:24 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Dec 18 14:48:24 2018 +0700

----------------------------------------------------------------------
 .../mailbox/store/StoreBlobManagerTest.java     |  2 +-
 .../mailbox/store/mail/model/UsernameTest.java  | 11 ---
 .../apache/james/imap/api/ImapSessionUtils.java |  2 +-
 .../james/imap/processor/LogoutProcessor.java   |  2 +-
 .../james/imap/main/PathConverterTest.java      |  6 +-
 .../james/imap/processor/CopyProcessorTest.java | 97 +++++++++-----------
 .../imap/processor/DeleteACLProcessorTest.java  |  9 +-
 .../imap/processor/GetACLProcessorTest.java     |  8 +-
 .../james/imap/processor/LSubProcessorTest.java | 34 +------
 .../imap/processor/ListRightsProcessorTest.java |  8 +-
 .../james/imap/processor/MoveProcessorTest.java | 96 ++++++++-----------
 .../imap/processor/NamespaceProcessorTest.java  | 24 ++---
 .../imap/processor/SearchProcessorTest.java     |  2 +-
 .../imap/processor/SetACLProcessorTest.java     |  8 +-
 .../base/MailboxEventAnalyserTest.java          |  2 +-
 .../apache/james/jmap/DownloadServletTest.java  |  2 +-
 16 files changed, 107 insertions(+), 206 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreBlobManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreBlobManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreBlobManagerTest.java
index 322c8d5..db48237 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreBlobManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreBlobManagerTest.java
@@ -66,7 +66,7 @@ public class StoreBlobManagerTest {
     public void setUp() {
         attachmentManager = mock(AttachmentManager.class);
         messageIdManager = mock(MessageIdManager.class);
-        session = mock(MailboxSession.class);
+        session = MailboxSession.create("user");
 
         blobManager = new StoreBlobManager(attachmentManager, messageIdManager, new TestMessageId.Factory());
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java
index 0ec4eed..1f34d74 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/UsernameTest.java
@@ -57,15 +57,4 @@ public class UsernameTest {
             .isInstanceOf(NullPointerException.class);
     }
 
-    @Test
-    public void fromMailboxSessionShouldThrowOnNullUsername() {
-        MailboxSession mailboxSession = mock(MailboxSession.class);
-        MailboxSession.User user = mock(MailboxSession.User.class);
-        when(mailboxSession.getUser()).thenReturn(user);
-        when(user.getUserName()).thenReturn(null);
-
-        assertThatThrownBy(() -> Username.fromMailboxSession(mailboxSession))
-            .isInstanceOf(NullPointerException.class);
-    }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/main/java/org/apache/james/imap/api/ImapSessionUtils.java
----------------------------------------------------------------------
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
index 9c8fc44..6d4e25a 100644
--- 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
@@ -39,7 +39,7 @@ public class ImapSessionUtils {
     public static String getUserName(ImapSession imapSession) {
         Preconditions.checkNotNull(imapSession);
         return Optional.ofNullable(getMailboxSession(imapSession))
-            .map(mailboxSession -> mailboxSession.getUser().getUserName())
+            .map(mailboxSession -> mailboxSession.getUser().asString())
             .orElse(null);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/main/java/org/apache/james/imap/processor/LogoutProcessor.java
----------------------------------------------------------------------
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 4b9a09a..46e3364 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
@@ -53,7 +53,7 @@ public class LogoutProcessor extends AbstractMailboxProcessor<LogoutRequest> {
             bye(responder);
             okComplete(command, tag, responder);
         } catch (MailboxException e) {
-            LOGGER.error("Logout failed for user {}", mailboxSession.getUser().getUserName(), e);
+            LOGGER.error("Logout failed for user {}", mailboxSession.getUser().asString(), e);
             no(command, tag, responder, HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING);
         }
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/main/PathConverterTest.java
----------------------------------------------------------------------
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 b395109..e959573 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
@@ -47,13 +47,9 @@ public class PathConverterTest {
     @Before
     public void setUp() {
         imapSession = mock(ImapSession.class);
-        mailboxSession = mock(MailboxSession.class);
-        MailboxSession.User user = mock(MailboxSession.User.class);
+        mailboxSession = MailboxSession.create(USERNAME);
         pathConverter = PathConverter.forSession(imapSession);
         when(imapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
-        when(mailboxSession.getUser()).thenReturn(user);
-        when(mailboxSession.getPathDelimiter()).thenReturn(PATH_DELIMITER);
-        when(user.getUserName()).thenReturn(USERNAME);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/CopyProcessorTest.java
----------------------------------------------------------------------
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 245f90f..5a097b3 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
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
 
 import java.util.Optional;
 
+import org.apache.james.core.User;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.ImapSessionState;
@@ -55,9 +56,9 @@ import org.junit.Test;
 import com.google.common.collect.Lists;
 
 public class CopyProcessorTest {
-
     public static final String TAG = "TAG";
-    private static final MailboxSession.SessionId SESSION_ID_42 = MailboxSession.SessionId.of(42L);
+    private static final String USERNAME = "username";
+    private static final User USER = User.fromUsername(USERNAME);
 
     private CopyProcessor testee;
     private ImapProcessor mockNextProcessor;
@@ -65,7 +66,7 @@ public class CopyProcessorTest {
     private StatusResponseFactory mockStatusResponseFactory;
     private ImapProcessor.Responder mockResponder;
     private ImapSession mockImapSession;
-    private MailboxSession mockMailboxSession;
+    private MailboxSession mailboxSession;
 
     @Before
     public void setUp() {
@@ -74,7 +75,7 @@ public class CopyProcessorTest {
         mockStatusResponseFactory = mock(StatusResponseFactory.class);
         mockResponder = mock(ImapProcessor.Responder.class);
         mockImapSession = mock(ImapSession.class);
-        mockMailboxSession = mock(MailboxSession.class);
+        mailboxSession = MailboxSession.create(USER.asString());
 
         testee = new CopyProcessor(mockNextProcessor, mockMailboxManager, mockStatusResponseFactory, new NoopMetricFactory());
     }
@@ -83,35 +84,31 @@ public class CopyProcessorTest {
     public void processShouldWork() throws Exception {
         CopyRequest copyRequest = new CopyRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
 
-        MailboxSession.User user = mock(MailboxSession.User.class);
-        when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
-        MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        MailboxPath inbox = MailboxPath.inbox(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);
-        when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(true);
+        when(mockMailboxManager.mailboxExists(inbox, mailboxSession)).thenReturn(true);
         MessageManager targetMessageManager = mock(MessageManager.class);
-        when(mockMailboxManager.getMailbox(inbox, mockMailboxSession)).thenReturn(targetMessageManager);
-        when(targetMessageManager.getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN)).thenReturn(new MailboxMetaData(null, null, 58L, MessageUid.of(18), 8L, 8L, 8L, MessageUid.of(8), true, true, null));
+        when(mockMailboxManager.getMailbox(inbox, mailboxSession)).thenReturn(targetMessageManager);
+        when(targetMessageManager.getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN)).thenReturn(new MailboxMetaData(null, null, 58L, MessageUid.of(18), 8L, 8L, 8L, MessageUid.of(8), true, true, null));
         StatusResponse okResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedOk(any(String.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, mockMailboxSession)).thenReturn(Lists.<MessageRange>newArrayList(MessageRange.range(MessageUid.of(4), MessageUid.of(6))));
+        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);
 
-        verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
-        verify(mockMailboxManager).getMailbox(inbox, mockMailboxSession);
-        verify(mockMailboxManager).copyMessages(MessageRange.range(MessageUid.of(4), MessageUid.of(6)), selected, inbox, mockMailboxSession);
-        verify(targetMessageManager).getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
+        verify(mockMailboxManager).startProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).endProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).mailboxExists(inbox, mailboxSession);
+        verify(mockMailboxManager).getMailbox(inbox, mailboxSession);
+        verify(mockMailboxManager).copyMessages(MessageRange.range(MessageUid.of(4), MessageUid.of(6)), selected, inbox, mailboxSession);
+        verify(targetMessageManager).getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
         verify(mockResponder).respond(okResponse);
         verifyNoMoreInteractions(mockMailboxManager, targetMessageManager, mockResponder, mockNextProcessor);
     }
@@ -121,35 +118,31 @@ 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);
 
-        MailboxSession.User user = mock(MailboxSession.User.class);
-        when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
-        MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        MailboxPath inbox = MailboxPath.inbox(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);
-        when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(true);
+        when(mockMailboxManager.mailboxExists(inbox, mailboxSession)).thenReturn(true);
         MessageManager targetMessageManager = mock(MessageManager.class);
-        when(mockMailboxManager.getMailbox(inbox, mockMailboxSession)).thenReturn(targetMessageManager);
-        when(targetMessageManager.getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN)).thenReturn(new MailboxMetaData(null, null, 58L, MessageUid.of(18), 8L, 8L, 8L, MessageUid.of(8), true, true, null));
+        when(mockMailboxManager.getMailbox(inbox, mailboxSession)).thenReturn(targetMessageManager);
+        when(targetMessageManager.getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN)).thenReturn(new MailboxMetaData(null, null, 58L, MessageUid.of(18), 8L, 8L, 8L, MessageUid.of(8), true, true, null));
         StatusResponse okResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedOk(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(okResponse);
 
         testee.process(copyRequest, mockResponder, mockImapSession);
 
-        verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
-        verify(mockMailboxManager).getMailbox(inbox, mockMailboxSession);
-        verify(mockMailboxManager).copyMessages(MessageRange.range(MessageUid.of(5), MessageUid.of(6)), selected, inbox, mockMailboxSession);
-        verify(mockMailboxManager).copyMessages(MessageRange.range(MessageUid.of(1), MessageUid.of(3)), selected, inbox, mockMailboxSession);
-        verify(targetMessageManager).getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
+        verify(mockMailboxManager).startProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).endProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).mailboxExists(inbox, mailboxSession);
+        verify(mockMailboxManager).getMailbox(inbox, mailboxSession);
+        verify(mockMailboxManager).copyMessages(MessageRange.range(MessageUid.of(5), MessageUid.of(6)), selected, inbox, mailboxSession);
+        verify(mockMailboxManager).copyMessages(MessageRange.range(MessageUid.of(1), MessageUid.of(3)), selected, inbox, mailboxSession);
+        verify(targetMessageManager).getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
         verify(mockResponder).respond(okResponse);
         verifyNoMoreInteractions(mockMailboxManager, targetMessageManager, mockResponder, mockNextProcessor);
     }
@@ -158,29 +151,25 @@ 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);
 
-        MailboxSession.User user = mock(MailboxSession.User.class);
-        when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
-        MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        MailboxPath inbox = MailboxPath.inbox(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);
-        when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(false);
+        when(mockMailboxManager.mailboxExists(inbox, mailboxSession)).thenReturn(false);
 
         StatusResponse noResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(noResponse);
 
         testee.process(copyRequest, mockResponder, mockImapSession);
 
-        verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+        verify(mockMailboxManager).startProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).endProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).mailboxExists(inbox, mailboxSession);
         verify(mockResponder).respond(noResponse);
         verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
     }
@@ -189,29 +178,25 @@ 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);
 
-        MailboxSession.User user = mock(MailboxSession.User.class);
-        when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
-        MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        MailboxPath inbox = MailboxPath.inbox(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);
-        when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenThrow(new MailboxException());
+        when(mockMailboxManager.mailboxExists(inbox, mailboxSession)).thenThrow(new MailboxException());
 
         StatusResponse noResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class))).thenReturn(noResponse);
 
         testee.process(copyRequest, mockResponder, mockImapSession);
 
-        verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+        verify(mockMailboxManager).startProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).endProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).mailboxExists(inbox, mailboxSession);
         verify(mockResponder).respond(noResponse);
         verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/DeleteACLProcessorTest.java
----------------------------------------------------------------------
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 6cc2cbd..fcc7cc4 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
@@ -40,7 +40,6 @@ import org.apache.james.imap.message.request.DeleteACLRequest;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageManager.MetaData;
 import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
@@ -82,8 +81,8 @@ public class DeleteACLProcessorTest {
         mailboxManager = mock(MailboxManager.class);
         subject = new DeleteACLProcessor(mock(ImapProcessor.class), mailboxManager, statusResponseFactory, new NoopMetricFactory());
         imapSession = mock(ImapSession.class);
-        mailboxSession = mock(MailboxSession.class);
-        User user1 = mock(User.class);
+        mailboxSession = MailboxSession.create(USER_1);
+
         MessageManager messageManager = mock(MessageManager.class);
         metaData = mock(MetaData.class);
         responder = mock(Responder.class);
@@ -92,10 +91,6 @@ public class DeleteACLProcessorTest {
             .thenReturn(mailboxSession);
         when(imapSession.getState())
             .thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mailboxSession.getUser())
-            .thenReturn(user1);
-        when(user1.getUserName())
-            .thenReturn(USER_1);
         when(messageManager.getMetaData(anyBoolean(), any(MailboxSession.class), any(FetchGroup.class)))
             .thenReturn(metaData);
         when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class)))

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/GetACLProcessorTest.java
----------------------------------------------------------------------
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 8522169..a87d530 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
@@ -41,7 +41,6 @@ import org.apache.james.imap.message.response.ACLResponse;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageManager.MetaData;
 import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
@@ -79,8 +78,7 @@ public class GetACLProcessorTest {
         mailboxManager = mock(MailboxManager.class);
         subject = new GetACLProcessor(mock(ImapProcessor.class), mailboxManager, statusResponseFactory, new NoopMetricFactory());
         imapSession = mock(ImapSession.class);
-        mailboxSession = mock(MailboxSession.class);
-        User user1 = mock(User.class);
+        mailboxSession = MailboxSession.create(USER_1);
         MessageManager messageManager = mock(MessageManager.class);
         metaData = mock(MetaData.class);
         responder = mock(Responder.class);
@@ -91,10 +89,6 @@ public class GetACLProcessorTest {
             .thenReturn(mailboxSession);
         when(imapSession.getState())
             .thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mailboxSession.getUser())
-            .thenReturn(user1);
-        when(user1.getUserName())
-            .thenReturn(USER_1);
         when(messageManager.getMetaData(anyBoolean(), any(MailboxSession.class), any(FetchGroup.class)))
             .thenReturn(metaData);
         when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class)))

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/LSubProcessorTest.java
----------------------------------------------------------------------
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 648d139..bc29406 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
@@ -69,28 +69,7 @@ public class LSubProcessorTest {
     private static final String MAILBOX_A = "A.MAILBOX";
 
     private static final String TAG = "TAG";
-    public static final MailboxSession.User USER = new MailboxSession.User() {
-        @Override
-        public List<Locale> getLocalePreferences() {
-            return new ArrayList<>();
-        }
-
-        @Override
-        public String getPassword() {
-            return "test";
-        }
-
-        @Override
-        public String getUserName() {
-            return "test";
-        }
-
-        @Override
-        public boolean isSameUser(String username) {
-            return "test".equalsIgnoreCase(username);
-        }
-
-    };
+    public static final String USER = "test";
 
     LSubProcessor processor;
     ImapProcessor next;
@@ -117,7 +96,7 @@ public class LSubProcessorTest {
         statusResponse = mock(StatusResponse.class);
         responderImpl = responder;
         manager =  mock(SubscriptionManager.class);
-        mailboxSession = mock(MailboxSession.class);
+        mailboxSession = MailboxSession.create(USER);
         processor = new LSubProcessor(next, mock(MailboxManager.class), manager, serverResponseFactory, new NoopMetricFactory());
     }
 
@@ -130,8 +109,6 @@ public class LSubProcessorTest {
         subscriptions.add(CHILD_ONE);
         subscriptions.add(CHILD_TWO);
 
-        when(mailboxSession.getUser()).thenReturn(USER);
-
         expectSubscriptions();
         when(serverResponseFactory.taggedOk(eq(TAG), same(command), eq(HumanReadableText.COMPLETED)))
             .thenReturn(statusResponse);
@@ -154,8 +131,6 @@ public class LSubProcessorTest {
         subscriptions.add(CHILD_ONE);
         subscriptions.add(CHILD_TWO);
 
-        when(mailboxSession.getUser()).thenReturn(USER);
-
         expectSubscriptions();
         when(serverResponseFactory.taggedOk(eq(TAG), same(command), eq(HumanReadableText.COMPLETED)))
             .thenReturn(statusResponse);
@@ -178,8 +153,6 @@ public class LSubProcessorTest {
         subscriptions.add(CHILD_ONE);
         subscriptions.add(CHILD_TWO);
 
-        when(mailboxSession.getUser()).thenReturn(USER);
-
         expectSubscriptions();
         when(serverResponseFactory.taggedOk(eq(TAG), same(command), eq(HumanReadableText.COMPLETED)))
             .thenReturn(statusResponse);
@@ -197,8 +170,6 @@ public class LSubProcessorTest {
         subscriptions.add(MAILBOX_A);
         subscriptions.add(MAILBOX_B);
         subscriptions.add(MAILBOX_C);
-
-        when(mailboxSession.getUser()).thenReturn(USER);
         expectSubscriptions();
         when(serverResponseFactory.taggedOk(eq(TAG), same(command), eq(HumanReadableText.COMPLETED)))
             .thenReturn(statusResponse);
@@ -214,7 +185,6 @@ public class LSubProcessorTest {
 
     private void expectSubscriptions() throws Exception {
         when(session.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
-        when(mailboxSession.getPathDelimiter()).thenReturn(HIERARCHY_DELIMITER);
         when(manager.subscriptions(mailboxSession)).thenReturn(subscriptions);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/ListRightsProcessorTest.java
----------------------------------------------------------------------
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 ff7f0e5..b61f2ae 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
@@ -41,7 +41,6 @@ import org.apache.james.imap.message.response.ListRightsResponse;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageManager.MetaData;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -84,8 +83,7 @@ public class ListRightsProcessorTest {
         mailboxManager = mock(MailboxManager.class);
         subject = new ListRightsProcessor(mock(ImapProcessor.class), mailboxManager, statusResponseFactory, new NoopMetricFactory());
         imapSession = mock(ImapSession.class);
-        mailboxSession = mock(MailboxSession.class);
-        User user1 = mock(User.class);
+        mailboxSession = MailboxSession.create(USER_1);
         MessageManager messageManager = mock(MessageManager.class);
         metaData = mock(MetaData.class);
         responder = mock(Responder.class);
@@ -96,10 +94,6 @@ public class ListRightsProcessorTest {
             .thenReturn(mailboxSession);
         when(imapSession.getState())
             .thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mailboxSession.getUser())
-            .thenReturn(user1);
-        when(user1.getUserName())
-            .thenReturn(USER_1);
         when(messageManager.getMetaData(anyBoolean(), any(MailboxSession.class), any(MetaData.FetchGroup.class)))
             .thenReturn(metaData);
         when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class)))

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/MoveProcessorTest.java
----------------------------------------------------------------------
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 38fb706..244115e 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
@@ -29,6 +29,7 @@ import static org.mockito.Mockito.when;
 
 import java.util.Optional;
 
+import org.apache.james.core.User;
 import org.apache.james.imap.api.ImapCommand;
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.ImapSessionState;
@@ -58,9 +59,8 @@ import org.junit.Test;
 import com.google.common.collect.Lists;
 
 public class MoveProcessorTest {
-
     public static final String TAG = "TAG";
-    private static final MailboxSession.SessionId SESSION_ID_42 = MailboxSession.SessionId.of(42L);
+    private static final User USER = User.fromUsername("username");
 
     private MoveProcessor testee;
     private ImapProcessor mockNextProcessor;
@@ -68,7 +68,7 @@ public class MoveProcessorTest {
     private StatusResponseFactory mockStatusResponseFactory;
     private ImapProcessor.Responder mockResponder;
     private ImapSession mockImapSession;
-    private MailboxSession mockMailboxSession;
+    private MailboxSession mailboxSession;
 
     @Before
     public void setUp() {
@@ -77,7 +77,7 @@ public class MoveProcessorTest {
         mockStatusResponseFactory = mock(StatusResponseFactory.class);
         mockResponder = mock(ImapProcessor.Responder.class);
         mockImapSession = mock(ImapSession.class);
-        mockMailboxSession = mock(MailboxSession.class);
+        mailboxSession = MailboxSession.create(USER.asString());
 
         when(mockMailboxManager.hasCapability(eq(MailboxCapabilities.Move))).thenReturn(true);
         testee = new MoveProcessor(mockNextProcessor, mockMailboxManager, mockStatusResponseFactory, new NoopMetricFactory());
@@ -100,37 +100,33 @@ public class MoveProcessorTest {
     public void processShouldWork() throws Exception {
         MoveRequest moveRequest = new MoveRequest(ImapCommand.anyStateCommand("Name"), new IdRange[] {new IdRange(4, 6)}, ImapConstants.INBOX_NAME, true, TAG);
 
-        MailboxSession.User user = mock(MailboxSession.User.class);
-        when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
-        MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        MailboxPath inbox = MailboxPath.inbox(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);
-        when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(true);
+        when(mockMailboxManager.mailboxExists(inbox, mailboxSession)).thenReturn(true);
         MessageManager targetMessageManager = mock(MessageManager.class);
-        when(mockMailboxManager.getMailbox(inbox, mockMailboxSession)).thenReturn(targetMessageManager);
-        when(targetMessageManager.getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN))
+        when(mockMailboxManager.getMailbox(inbox, mailboxSession)).thenReturn(targetMessageManager);
+        when(targetMessageManager.getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN))
             .thenReturn(new MailboxMetaData(null, null, 58L, MessageUid.of(18), 8L, 8L, 8L, MessageUid.of(8), true, true, null));
         StatusResponse okResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedOk(any(String.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, mockMailboxSession))
+        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);
 
-        verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
-        verify(mockMailboxManager).getMailbox(inbox, mockMailboxSession);
-        verify(mockMailboxManager).moveMessages(MessageRange.range(MessageUid.of(4), MessageUid.of(6)), selected, inbox, mockMailboxSession);
-        verify(targetMessageManager).getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
+        verify(mockMailboxManager).startProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).endProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).mailboxExists(inbox, mailboxSession);
+        verify(mockMailboxManager).getMailbox(inbox, mailboxSession);
+        verify(mockMailboxManager).moveMessages(MessageRange.range(MessageUid.of(4), MessageUid.of(6)), selected, inbox, mailboxSession);
+        verify(targetMessageManager).getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
         verify(mockResponder).respond(okResponse);
         verifyNoMoreInteractions(mockMailboxManager, targetMessageManager, mockResponder, mockNextProcessor);
     }
@@ -140,36 +136,32 @@ public class MoveProcessorTest {
     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);
 
-        MailboxSession.User user = mock(MailboxSession.User.class);
-        when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
-        MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        MailboxPath inbox = MailboxPath.inbox(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);
-        when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(true);
+        when(mockMailboxManager.mailboxExists(inbox, mailboxSession)).thenReturn(true);
         MessageManager targetMessageManager = mock(MessageManager.class);
-        when(mockMailboxManager.getMailbox(inbox, mockMailboxSession)).thenReturn(targetMessageManager);
-        when(targetMessageManager.getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN))
+        when(mockMailboxManager.getMailbox(inbox, mailboxSession)).thenReturn(targetMessageManager);
+        when(targetMessageManager.getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN))
             .thenReturn(new MailboxMetaData(null, null, 58L, MessageUid.of(18), 8L, 8L, 8L, MessageUid.of(8), true, true, null));
         StatusResponse okResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedOk(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(okResponse);
 
         testee.process(moveRequest, mockResponder, mockImapSession);
 
-        verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
-        verify(mockMailboxManager).getMailbox(inbox, mockMailboxSession);
-        verify(mockMailboxManager).moveMessages(MessageRange.range(MessageUid.of(5), MessageUid.of(6)), selected, inbox, mockMailboxSession);
-        verify(mockMailboxManager).moveMessages(MessageRange.range(MessageUid.of(1), MessageUid.of(3)), selected, inbox, mockMailboxSession);
-        verify(targetMessageManager).getMetaData(false, mockMailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
+        verify(mockMailboxManager).startProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).endProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).mailboxExists(inbox, mailboxSession);
+        verify(mockMailboxManager).getMailbox(inbox, mailboxSession);
+        verify(mockMailboxManager).moveMessages(MessageRange.range(MessageUid.of(5), MessageUid.of(6)), selected, inbox, mailboxSession);
+        verify(mockMailboxManager).moveMessages(MessageRange.range(MessageUid.of(1), MessageUid.of(3)), selected, inbox, mailboxSession);
+        verify(targetMessageManager).getMetaData(false, mailboxSession, MessageManager.MetaData.FetchGroup.NO_UNSEEN);
         verify(mockResponder).respond(okResponse);
         verifyNoMoreInteractions(mockMailboxManager, targetMessageManager, mockResponder, mockNextProcessor);
     }
@@ -178,29 +170,25 @@ public class MoveProcessorTest {
     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);
 
-        MailboxSession.User user = mock(MailboxSession.User.class);
-        when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
-        MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        MailboxPath inbox = MailboxPath.inbox(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);
-        when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenReturn(false);
+        when(mockMailboxManager.mailboxExists(inbox, mailboxSession)).thenReturn(false);
 
         StatusResponse noResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class), any(StatusResponse.ResponseCode.class))).thenReturn(noResponse);
 
         testee.process(moveRequest, mockResponder, mockImapSession);
 
-        verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+        verify(mockMailboxManager).startProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).endProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).mailboxExists(inbox, mailboxSession);
         verify(mockResponder).respond(noResponse);
         verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
     }
@@ -209,29 +197,25 @@ public class MoveProcessorTest {
     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);
 
-        MailboxSession.User user = mock(MailboxSession.User.class);
-        when(user.getUserName()).thenReturn("username");
-        when(mockMailboxSession.getUser()).thenReturn(user);
-        when(mockMailboxSession.getSessionId()).thenReturn(SESSION_ID_42);
         when(mockImapSession.getState()).thenReturn(ImapSessionState.SELECTED);
-        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mockMailboxSession);
-        MailboxPath inbox = MailboxPath.inbox(mockMailboxSession);
+        when(mockImapSession.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
+        MailboxPath inbox = MailboxPath.inbox(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);
-        when(mockMailboxManager.mailboxExists(inbox, mockMailboxSession)).thenThrow(new MailboxException());
+        when(mockMailboxManager.mailboxExists(inbox, mailboxSession)).thenThrow(new MailboxException());
 
         StatusResponse noResponse = mock(StatusResponse.class);
         when(mockStatusResponseFactory.taggedNo(any(String.class), any(ImapCommand.class), any(HumanReadableText.class))).thenReturn(noResponse);
 
         testee.process(moveRequest, mockResponder, mockImapSession);
 
-        verify(mockMailboxManager).startProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).endProcessingRequest(mockMailboxSession);
-        verify(mockMailboxManager).mailboxExists(inbox, mockMailboxSession);
+        verify(mockMailboxManager).startProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).endProcessingRequest(mailboxSession);
+        verify(mockMailboxManager).mailboxExists(inbox, mailboxSession);
         verify(mockResponder).respond(noResponse);
         verifyNoMoreInteractions(mockMailboxManager, mockResponder, mockNextProcessor);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/NamespaceProcessorTest.java
----------------------------------------------------------------------
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 b6162e6..85bef10 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
@@ -59,7 +59,7 @@ public class NamespaceProcessorTest {
     NamespaceProcessor subject;
     StatusResponseFactory statusResponseStub;
     ImapSession imapSessionStub;
-    MailboxSession mailboxSessionStub;
+    MailboxSession mailboxSession;
     NamespaceRequest namespaceRequest;
     Collection<String> sharedSpaces;
     MailboxManager mailboxManagerStub;
@@ -71,7 +71,7 @@ public class NamespaceProcessorTest {
         mailboxManagerStub = mock(MailboxManager.class);
         subject = new NamespaceProcessor(mock(ImapProcessor.class), mailboxManagerStub, statusResponseStub, new NoopMetricFactory());
         imapSessionStub = mock(ImapSession.class);
-        mailboxSessionStub = mock(MailboxSession.class);
+        mailboxSession = mock(MailboxSession.class);
      
         namespaceRequest = new NamespaceRequest(ImapCommand.anyStateCommand("Name"), "TAG");
        
@@ -80,13 +80,13 @@ public class NamespaceProcessorTest {
     @Test
     public void testNamespaceResponseShouldContainPersonalAndUserSpaces() {
         when(imapSessionStub.supportMultipleNamespaces()).thenReturn(true);
-        when(imapSessionStub.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSessionStub);
+        when(imapSessionStub.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         when(imapSessionStub.getAttribute(EnableProcessor.ENABLED_CAPABILITIES)).thenReturn(null);
 
-        when(mailboxSessionStub.getPersonalSpace()).thenReturn(PERSONAL_PREFIX);
-        when(mailboxSessionStub.getOtherUsersSpace()).thenReturn(USERS_PREFIX);
-        when(mailboxSessionStub.getSharedSpaces()).thenReturn(new ArrayList<>());
-        when(mailboxSessionStub.getPathDelimiter()).thenReturn(MailboxConstants.DEFAULT_DELIMITER);
+        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(statusResponseStub.taggedOk(anyString(), any(ImapCommand.class), any(HumanReadableText.class)))
@@ -105,13 +105,13 @@ public class NamespaceProcessorTest {
     @Test
     public void testNamespaceResponseShouldContainSharedSpaces() {
         when(imapSessionStub.supportMultipleNamespaces()).thenReturn(true);
-        when(imapSessionStub.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSessionStub);
+        when(imapSessionStub.getAttribute(ImapSessionUtils.MAILBOX_SESSION_ATTRIBUTE_SESSION_KEY)).thenReturn(mailboxSession);
         when(imapSessionStub.getAttribute(EnableProcessor.ENABLED_CAPABILITIES)).thenReturn(null);
 
-        when(mailboxSessionStub.getPersonalSpace()).thenReturn(PERSONAL_PREFIX);
-        when(mailboxSessionStub.getOtherUsersSpace()).thenReturn(USERS_PREFIX);
-        when(mailboxSessionStub.getSharedSpaces()).thenReturn(Arrays.asList(SHARED_PREFIX));
-        when(mailboxSessionStub.getPathDelimiter()).thenReturn(MailboxConstants.DEFAULT_DELIMITER);
+        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(statusResponseStub.taggedOk(anyString(), any(ImapCommand.class), any(HumanReadableText.class)))

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/SearchProcessorTest.java
----------------------------------------------------------------------
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 fd9be52..38e0186 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
@@ -122,7 +122,7 @@ public class SearchProcessorTest {
         statusResponse = mock(StatusResponse.class);
         mailbox = mock(MessageManager.class);
         mailboxManager = mock(MailboxManager.class);
-        mailboxSession = mock(MailboxSession.class);
+        mailboxSession = MailboxSession.create("user");
         selectedMailbox = mock(SelectedMailbox.class);
         
         processor = new SearchProcessor(next,  mailboxManager, serverResponseFactory, new NoopMetricFactory());

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/SetACLProcessorTest.java
----------------------------------------------------------------------
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 8f70752..dccd747 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
@@ -40,7 +40,6 @@ import org.apache.james.imap.message.request.SetACLRequest;
 import org.apache.james.imap.message.response.UnpooledStatusResponseFactory;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MailboxSession.User;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageManager.MetaData;
 import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup;
@@ -86,8 +85,7 @@ public class SetACLProcessorTest {
         mailboxManager = mock(MailboxManager.class);
         subject = new SetACLProcessor(mock(ImapProcessor.class), mailboxManager, statusResponseFactory, new NoopMetricFactory());
         imapSession = mock(ImapSession.class);
-        mailboxSession = mock(MailboxSession.class);
-        User user1 = mock(User.class);
+        mailboxSession = MailboxSession.create(USER_1);
         MessageManager messageManager = mock(MessageManager.class);
         MetaData metaData = mock(MetaData.class);
         responder = mock(Responder.class);
@@ -98,10 +96,6 @@ public class SetACLProcessorTest {
             .thenReturn(mailboxSession);
         when(imapSession.getState())
             .thenReturn(ImapSessionState.AUTHENTICATED);
-        when(mailboxSession.getUser())
-            .thenReturn(user1);
-        when(user1.getUserName())
-            .thenReturn(USER_1);
         when(messageManager.getMetaData(anyBoolean(), any(MailboxSession.class), any(FetchGroup.class)))
             .thenReturn(metaData);
         when(mailboxManager.getMailbox(any(MailboxPath.class), any(MailboxSession.class)))

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
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 22b8acb..59cc629 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
@@ -135,7 +135,7 @@ public class MailboxEventAnalyserTest {
     @Test
     public void testShouldBeNoSizeChangeOnOtherEvent() {
         MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(MAILBOX_SESSION.getSessionId(),
-            MAILBOX_SESSION.getUser().getCoreUser(), MAILBOX_PATH, MAILBOX_ID) {};
+            MAILBOX_SESSION.getUser(), MAILBOX_PATH, MAILBOX_ID) {};
       
         testee.event(event);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/88108560/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
index 2943b64..0e69a65 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
@@ -39,7 +39,7 @@ public class DownloadServletTest {
 
     @Test
     public void downloadMayFailWhenUnknownErrorOnAttachmentManager() throws Exception {
-        MailboxSession mailboxSession = mock(MailboxSession.class);
+        MailboxSession mailboxSession = MailboxSession.create("User");
         BlobManager mockedBlobManager = mock(BlobManager.class);
         when(mockedBlobManager.retrieve(any(), eq(mailboxSession)))
             .thenThrow(new MailboxException());


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