james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [12/15] james-project git commit: PROTOCOLS-117 Bonus: Remove another "Mock like" MailboxSession implementation
Date Fri, 03 Nov 2017 12:27:35 GMT
PROTOCOLS-117 Bonus: Remove another "Mock like" MailboxSession implementation


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

Branch: refs/heads/master
Commit: b99318ece3bc359ea76e3e2316ab31116a2a5750
Parents: cc5b9f8
Author: benwa <btellier@linagora.com>
Authored: Wed Nov 1 13:55:35 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Nov 3 15:48:40 2017 +0700

----------------------------------------------------------------------
 .../james/mailbox/mock/MockMailboxSession.java  | 34 ++++++++++----------
 .../AbstractMessageIdManagerStorageTest.java    |  3 +-
 .../store/MailboxEventDispatcherTest.java       | 12 ++-----
 .../store/StoreMessageIdManagerTestSystem.java  |  3 +-
 4 files changed, 22 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/b99318ec/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java
b/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java
index 1035687..89b41dc 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/mock/MockMailboxSession.java
@@ -28,27 +28,29 @@ import java.util.Random;
 
 import org.apache.james.mailbox.MailboxSession;
 
-public class MockMailboxSession implements MailboxSession{
-
+public class MockMailboxSession implements MailboxSession {
     private final User user;
-    private boolean close;
     private final Map<Object, Object> attrs = new HashMap<>();
     private final static Random RANDOM = new Random();
-
-    private final long sessionId = RANDOM.nextLong();
-    private SessionType type = SessionType.User;
+    private final long sessionId;
+    private final SessionType type;
+    private boolean open;
     
-    public MockMailboxSession(final String username) {
+    public MockMailboxSession(String username) {
+        this(username, RANDOM.nextLong());
+    }
+
+    public MockMailboxSession(String username, long sessionId) {
         this.user = new User() {
-            
+
             public String getUserName() {
                 return username;
             }
-            
+
             public String getPassword() {
                 return null;
             }
-            
+
             public List<Locale> getLocalePreferences() {
                 return new ArrayList<>();
             }
@@ -61,14 +63,13 @@ public class MockMailboxSession implements MailboxSession{
                 return username.equalsIgnoreCase(other);
             }
         };
+        this.sessionId = sessionId;
+        this.open = true;
+        type = SessionType.User;
     }
 
-    public MockMailboxSession(final String username, SessionType type) {
-        this(username);
-        this.type = type;
-    }
     public void close() {
-        this.close = true;
+        this.open = false;
     }
 
     public Map<Object, Object> getAttributes() {
@@ -96,7 +97,7 @@ public class MockMailboxSession implements MailboxSession{
     }
 
     public boolean isOpen() {
-        return close == false;
+        return open;
     }
 
 	public char getPathDelimiter() {
@@ -106,5 +107,4 @@ public class MockMailboxSession implements MailboxSession{
     public SessionType getType() {
         return type;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b99318ec/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java
index 4a8c069..1e64270 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerStorageTest.java
@@ -30,7 +30,6 @@ import java.util.function.Predicate;
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MailboxSession.SessionType;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.MessageUid;
@@ -76,7 +75,7 @@ public abstract class AbstractMessageIdManagerStorageTest {
     public void setUp() throws Exception {
         aliceSession = new MockMailboxSession(MailboxFixture.ALICE);
         bobSession = new MockMailboxSession(MailboxFixture.BOB);
-        systemSession = new MockMailboxSession("systemuser", SessionType.System);
+        systemSession = new MockMailboxSession("systemuser");
         testingData = createTestingData();
         messageIdManager = testingData.getMessageIdManager();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/b99318ec/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
index 9f45c77..48047b4 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/MailboxEventDispatcherTest.java
@@ -32,7 +32,6 @@ import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.model.UpdatedFlags;
@@ -64,12 +63,7 @@ public class MailboxEventDispatcherTest {
     private MessageResult result;
     private Mailbox mailbox;
 
-    private MailboxSession session = new MockMailboxSession("test") {
-        @Override
-        public long getSessionId() {
-            return sessionId;
-        }
-    };
+    private MailboxSession session = new MockMailboxSession("test", sessionId);
 
     @Before
     public void setUp() throws Exception {
@@ -370,7 +364,7 @@ public class MailboxEventDispatcherTest {
 
     @Test
     public void expungedShouldNotFireEventWhenEmptyMap() {
-        dispatcher.expunged(session, ImmutableMap.<MessageUid, MessageMetaData> of(),
mailbox);
+        dispatcher.expunged(session, ImmutableMap.of(), mailbox);
         assertThat(collector.getEvents()).isEmpty();
     }
 
@@ -383,7 +377,7 @@ public class MailboxEventDispatcherTest {
                 .newFlags(new Flags(Flag.ANSWERED))
                 .build();
         
-        dispatcher.flagsUpdated(session, ImmutableList.<MessageUid> of(), mailbox,
ImmutableList.of(updatedFlags));
+        dispatcher.flagsUpdated(session, ImmutableList.of(), mailbox, ImmutableList.of(updatedFlags));
         assertThat(collector.getEvents()).isEmpty();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/b99318ec/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
index 232ef04..9798ae7 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMessageIdManagerTestSystem.java
@@ -31,7 +31,6 @@ import javax.mail.Flags;
 
 import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MailboxSession.SessionType;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -58,7 +57,7 @@ public class StoreMessageIdManagerTestSystem extends MessageIdManagerTestSystem
 
         this.messageIdFactory = messageIdFactory;
         this.mapperFactory = mapperFactory;
-        this.defaultMailboxSession = new MockMailboxSession("user", SessionType.System);
+        this.defaultMailboxSession = new MockMailboxSession("user");
     }
 
     @Override


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


Mime
View raw message