Repository: james-project
Updated Branches:
  refs/heads/master ac3340b73 -> 96aee2c6b


JAMES-1823 Provide tests for MailboxListenerRegistry


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

Branch: refs/heads/master
Commit: 96aee2c6b052ba5e926fa76474b8520958b6e753
Parents: ac3340b
Author: Benoit Tellier <btell...@linagora.com>
Authored: Thu Oct 6 16:10:53 2016 +0200
Committer: Benoit Tellier <btell...@linagora.com>
Committed: Wed Oct 12 09:12:59 2016 +0200

----------------------------------------------------------------------
 .../event/MailboxListenerRegistryTest.java      | 174 +++++++++++++++++++
 1 file changed, 174 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/96aee2c6/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java
new file mode 100644
index 0000000..796e7aa
--- /dev/null
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MailboxListenerRegistryTest.java
@@ -0,0 +1,174 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.event;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.junit.Before;
+import org.junit.Test;
+
+
+public class MailboxListenerRegistryTest {
+
+    private static final MailboxPath MAILBOX_PATH = new 
MailboxPath("#private", "user", "INBOX");
+    private static final MailboxPath OTHER_MAILBOX_PATH = new 
MailboxPath("#private", "user", "other");
+    private MailboxListenerRegistry testee;
+    private MailboxListener mailboxListener;
+    private MailboxListener otherMailboxListener;
+
+    @Before
+    public void setUp() {
+        testee = new MailboxListenerRegistry();
+        mailboxListener = mock(MailboxListener.class);
+        otherMailboxListener = mock(MailboxListener.class);
+    }
+
+    @Test
+    public void getGlobalListenersShouldBeEmpty() {
+        assertThat(testee.getGlobalListeners()).isEmpty();
+    }
+
+    @Test
+    public void getLocalMailboxListenersShouldReturnEmptyList() {
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
+    }
+
+    @Test
+    public void addGlobalListenerShouldAddAGlobalListener() throws Exception {
+        testee.addGlobalListener(mailboxListener);
+
+        assertThat(testee.getGlobalListeners()).containsOnly(mailboxListener);
+    }
+
+    @Test
+    public void addListenerShouldAddAListener() throws Exception {
+        testee.addListener(MAILBOX_PATH, mailboxListener);
+
+        
assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).containsOnly(mailboxListener);
+    }
+
+    @Test
+    public void addListenerTwiceShouldAddAListenerOnlyOnce() throws Exception {
+        testee.addListener(MAILBOX_PATH, mailboxListener);
+        testee.addListener(MAILBOX_PATH, mailboxListener);
+
+        
assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).containsExactly(mailboxListener);
+    }
+
+    @Test
+    public void addListenerShouldAddAListenerOnCorrectPath() throws Exception {
+        testee.addListener(MAILBOX_PATH, mailboxListener);
+
+        
assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).isEmpty();
+    }
+
+    @Test
+    public void removeGlobalListenerShouldWork() throws Exception {
+        testee.addGlobalListener(mailboxListener);
+
+        testee.removeGlobalListener(mailboxListener);
+
+        assertThat(testee.getGlobalListeners()).isEmpty();
+    }
+
+    @Test
+    public void removeListenerShouldWork() throws Exception {
+        testee.addListener(MAILBOX_PATH, mailboxListener);
+
+        testee.removeListener(MAILBOX_PATH, mailboxListener);
+
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
+    }
+
+    @Test
+    public void removeGlobalListenerShouldNotRemoveOtherListeners() throws 
Exception {
+        testee.addGlobalListener(mailboxListener);
+        testee.addGlobalListener(otherMailboxListener);
+
+        testee.removeGlobalListener(mailboxListener);
+
+        
assertThat(testee.getGlobalListeners()).containsOnly(otherMailboxListener);
+    }
+
+    @Test
+    public void removeListenerShouldNotRemoveOtherListeners() throws Exception 
{
+        testee.addListener(MAILBOX_PATH, mailboxListener);
+        testee.addListener(MAILBOX_PATH, otherMailboxListener);
+
+        testee.removeListener(MAILBOX_PATH, mailboxListener);
+
+        
assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).containsOnly(otherMailboxListener);
+    }
+
+    @Test
+    public void deleteRegistryForShouldRemoveAllListeners() throws Exception {
+        testee.addListener(MAILBOX_PATH, mailboxListener);
+        testee.addListener(MAILBOX_PATH, otherMailboxListener);
+
+        testee.deleteRegistryFor(MAILBOX_PATH);
+
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
+    }
+
+    @Test
+    public void handleRenameShouldMoveListeners() throws Exception {
+        testee.addListener(MAILBOX_PATH, mailboxListener);
+        testee.addListener(MAILBOX_PATH, otherMailboxListener);
+
+        testee.handleRename(MAILBOX_PATH, OTHER_MAILBOX_PATH);
+
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
+        
assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).containsOnly(mailboxListener,
 otherMailboxListener);
+    }
+
+    @Test
+    public void handleRenameShouldPreservePreviouslyRegisteredListeners() 
throws Exception {
+        testee.addListener(OTHER_MAILBOX_PATH, mailboxListener);
+
+        testee.handleRename(MAILBOX_PATH, OTHER_MAILBOX_PATH);
+
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
+        
assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).containsOnly(mailboxListener);
+    }
+
+    @Test
+    public void handleRenameShouldMergeListenersIfNeeded() throws Exception {
+        testee.addListener(MAILBOX_PATH, mailboxListener);
+        testee.addListener(OTHER_MAILBOX_PATH, otherMailboxListener);
+
+        testee.handleRename(MAILBOX_PATH, OTHER_MAILBOX_PATH);
+
+        assertThat(testee.getLocalMailboxListeners(MAILBOX_PATH)).isEmpty();
+        
assertThat(testee.getLocalMailboxListeners(OTHER_MAILBOX_PATH)).containsOnly(mailboxListener,
 otherMailboxListener);
+    }
+
+    @Test
+    public void removeGlobalListenerShouldNotThrowOnAbsentListener() throws 
Exception {
+        testee.removeGlobalListener(mailboxListener);
+    }
+
+    @Test
+    public void removeListenerShouldNotThrowOnAbsentListener() throws 
Exception {
+        testee.removeListener(MAILBOX_PATH, mailboxListener);
+    }
+}


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

Reply via email to