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 5be4ba8c974dca892564501f129753f843d0e8c6 Author: Rene Cordier <rcord...@linagora.com> AuthorDate: Fri Nov 15 14:32:12 2019 +0700 [Refactoring] Move second batch of tests in mailbox cassandra with other dependant implementations to JUnit 5 --- .../cassandra/CassandraCombinationManagerTest.java | 32 +--- .../CassandraMessageIdManagerQuotaTest.java | 36 ++-- .../CassandraMessageIdManagerSideEffectTest.java | 32 +--- .../CassandraMessageIdManagerStorageTest.java | 32 +--- .../user/CassandraSubscriptionMapperTest.java | 32 +--- .../inmemory/InMemoryCombinationManagerTest.java | 9 +- .../InMemoryMessageIdManagerStorageTest.java | 9 +- .../InMemoryMessageIdManagerSideEffectTest.java | 9 +- .../user/InMemorySubscriptionMapperTest.java | 2 +- .../store/AbstractCombinationManagerTest.java | 68 ++++---- .../store/AbstractMessageIdManagerQuotaTest.java | 42 ++--- .../AbstractMessageIdManagerSideEffectTest.java | 64 ++++--- .../store/AbstractMessageIdManagerStorageTest.java | 185 +++++++++++---------- .../mailbox/store/user/SubscriptionMapperTest.java | 24 +-- 14 files changed, 246 insertions(+), 330 deletions(-) diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java index 8860dd0..68679a8 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraCombinationManagerTest.java @@ -19,8 +19,8 @@ package org.apache.james.mailbox.cassandra; -import org.apache.james.backends.cassandra.CassandraCluster; -import org.apache.james.backends.cassandra.DockerCassandraRule; +import org.apache.james.backends.cassandra.CassandraClusterExtension; +import org.apache.james.backends.cassandra.CassandraRestartExtension; import org.apache.james.mailbox.cassandra.mail.MailboxAggregateModule; import org.apache.james.mailbox.events.InVMEventBus; import org.apache.james.mailbox.events.delivery.InVmEventDelivery; @@ -28,33 +28,19 @@ import org.apache.james.mailbox.store.AbstractCombinationManagerTest; import org.apache.james.mailbox.store.CombinationManagerTestSystem; import org.apache.james.mailbox.store.quota.NoQuotaManager; import org.apache.james.metrics.api.NoopMetricFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; -public class CassandraCombinationManagerTest extends AbstractCombinationManagerTest { +@ExtendWith(CassandraRestartExtension.class) +class CassandraCombinationManagerTest extends AbstractCombinationManagerTest { - @Rule public DockerCassandraRule cassandraServer = new DockerCassandraRule().allowRestart(); - - private CassandraCluster cassandra; - - @Override - @Before - public void setUp() throws Exception { - cassandra = CassandraCluster.create(MailboxAggregateModule.MODULE, cassandraServer.getHost()); - super.setUp(); - } - - @After - public void tearDown() { - cassandra.clearTables(); - cassandra.closeCluster(); - } + @RegisterExtension + static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(MailboxAggregateModule.MODULE); @Override public CombinationManagerTestSystem createTestingData() { InVMEventBus eventBus = new InVMEventBus(new InVmEventDelivery(new NoopMetricFactory())); - return CassandraCombinationManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), eventBus); + return CassandraCombinationManagerTestSystem.createTestingData(cassandraCluster.getCassandraCluster(), new NoQuotaManager(), eventBus); } } diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerQuotaTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerQuotaTest.java index 720855f..4c693f8 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerQuotaTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerQuotaTest.java @@ -19,8 +19,8 @@ package org.apache.james.mailbox.cassandra; -import org.apache.james.backends.cassandra.CassandraCluster; -import org.apache.james.backends.cassandra.DockerCassandraRule; +import org.apache.james.backends.cassandra.CassandraClusterExtension; +import org.apache.james.backends.cassandra.CassandraRestartExtension; import org.apache.james.mailbox.cassandra.mail.MailboxAggregateModule; import org.apache.james.mailbox.quota.CurrentQuotaManager; import org.apache.james.mailbox.quota.MaxQuotaManager; @@ -28,37 +28,23 @@ import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.store.AbstractMessageIdManagerQuotaTest; import org.apache.james.mailbox.store.MessageIdManagerTestSystem; import org.apache.james.mailbox.store.quota.StoreQuotaManager; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; -public class CassandraMessageIdManagerQuotaTest extends AbstractMessageIdManagerQuotaTest { +@ExtendWith(CassandraRestartExtension.class) +class CassandraMessageIdManagerQuotaTest extends AbstractMessageIdManagerQuotaTest { - @Rule public DockerCassandraRule cassandraServer = new DockerCassandraRule().allowRestart(); - - private CassandraCluster cassandra; - - @Override - @Before - public void setUp() throws Exception { - cassandra = CassandraCluster.create(MailboxAggregateModule.MODULE_WITH_QUOTA, cassandraServer.getHost()); - super.setUp(); - } - - @After - public void tearDown() { - cassandra.clearTables(); - cassandra.closeCluster(); - } + @RegisterExtension + static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(MailboxAggregateModule.MODULE_WITH_QUOTA); @Override protected MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, CurrentQuotaManager currentQuotaManager) throws Exception { - return CassandraMessageIdManagerTestSystem.createTestingDataWithQuota(cassandra, quotaManager, currentQuotaManager); + return CassandraMessageIdManagerTestSystem.createTestingDataWithQuota(cassandraCluster.getCassandraCluster(), quotaManager, currentQuotaManager); } @Override protected MaxQuotaManager createMaxQuotaManager() { - return CassandraTestSystemFixture.createMaxQuotaManager(cassandra); + return CassandraTestSystemFixture.createMaxQuotaManager(cassandraCluster.getCassandraCluster()); } @Override @@ -68,6 +54,6 @@ public class CassandraMessageIdManagerQuotaTest extends AbstractMessageIdManager @Override protected CurrentQuotaManager createCurrentQuotaManager() { - return CassandraTestSystemFixture.createCurrentQuotaManager(cassandra); + return CassandraTestSystemFixture.createCurrentQuotaManager(cassandraCluster.getCassandraCluster()); } } diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerSideEffectTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerSideEffectTest.java index 8536d80..cfea4ad 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerSideEffectTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerSideEffectTest.java @@ -21,39 +21,25 @@ package org.apache.james.mailbox.cassandra; import java.util.Set; -import org.apache.james.backends.cassandra.CassandraCluster; -import org.apache.james.backends.cassandra.DockerCassandraRule; +import org.apache.james.backends.cassandra.CassandraClusterExtension; +import org.apache.james.backends.cassandra.CassandraRestartExtension; import org.apache.james.mailbox.cassandra.mail.MailboxAggregateModule; import org.apache.james.mailbox.events.EventBus; import org.apache.james.mailbox.extension.PreDeletionHook; import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.store.AbstractMessageIdManagerSideEffectTest; import org.apache.james.mailbox.store.MessageIdManagerTestSystem; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; -public class CassandraMessageIdManagerSideEffectTest extends AbstractMessageIdManagerSideEffectTest { +@ExtendWith(CassandraRestartExtension.class) +class CassandraMessageIdManagerSideEffectTest extends AbstractMessageIdManagerSideEffectTest { - @Rule public DockerCassandraRule cassandraServer = new DockerCassandraRule().allowRestart(); - - private CassandraCluster cassandra; - - @Override - @Before - public void setUp() throws Exception { - cassandra = CassandraCluster.create(MailboxAggregateModule.MODULE, cassandraServer.getHost()); - super.setUp(); - } - - @After - public void tearDown() { - cassandra.clearTables(); - cassandra.closeCluster(); - } + @RegisterExtension + static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(MailboxAggregateModule.MODULE); @Override protected MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, EventBus eventBus, Set<PreDeletionHook> preDeletionHooks) { - return CassandraMessageIdManagerTestSystem.createTestingData(cassandra, quotaManager, eventBus, preDeletionHooks); + return CassandraMessageIdManagerTestSystem.createTestingData(cassandraCluster.getCassandraCluster(), quotaManager, eventBus, preDeletionHooks); } } diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java index 0b7d71c..1a9c4d5 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/CassandraMessageIdManagerStorageTest.java @@ -19,8 +19,8 @@ package org.apache.james.mailbox.cassandra; -import org.apache.james.backends.cassandra.CassandraCluster; -import org.apache.james.backends.cassandra.DockerCassandraRule; +import org.apache.james.backends.cassandra.CassandraClusterExtension; +import org.apache.james.backends.cassandra.CassandraRestartExtension; import org.apache.james.mailbox.cassandra.mail.MailboxAggregateModule; import org.apache.james.mailbox.events.InVMEventBus; import org.apache.james.mailbox.events.delivery.InVmEventDelivery; @@ -29,32 +29,18 @@ import org.apache.james.mailbox.store.AbstractMessageIdManagerStorageTest; import org.apache.james.mailbox.store.MessageIdManagerTestSystem; import org.apache.james.mailbox.store.quota.NoQuotaManager; import org.apache.james.metrics.api.NoopMetricFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; -public class CassandraMessageIdManagerStorageTest extends AbstractMessageIdManagerStorageTest { +@ExtendWith(CassandraRestartExtension.class) +class CassandraMessageIdManagerStorageTest extends AbstractMessageIdManagerStorageTest { - @Rule public DockerCassandraRule cassandraServer = new DockerCassandraRule().allowRestart(); - - private CassandraCluster cassandra; - - @Override - @Before - public void setUp() throws Exception { - cassandra = CassandraCluster.create(MailboxAggregateModule.MODULE, cassandraServer.getHost()); - super.setUp(); - } - - @After - public void tearDown() { - cassandra.clearTables(); - cassandra.closeCluster(); - } + @RegisterExtension + static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(MailboxAggregateModule.MODULE); @Override protected MessageIdManagerTestSystem createTestingData() { InVMEventBus eventBus = new InVMEventBus(new InVmEventDelivery(new NoopMetricFactory())); - return CassandraMessageIdManagerTestSystem.createTestingData(cassandra, new NoQuotaManager(), eventBus, PreDeletionHook.NO_PRE_DELETION_HOOK); + return CassandraMessageIdManagerTestSystem.createTestingData(cassandraCluster.getCassandraCluster(), new NoQuotaManager(), eventBus, PreDeletionHook.NO_PRE_DELETION_HOOK); } } diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/user/CassandraSubscriptionMapperTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/user/CassandraSubscriptionMapperTest.java index 681ec3a..61923ee 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/user/CassandraSubscriptionMapperTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/user/CassandraSubscriptionMapperTest.java @@ -18,38 +18,24 @@ ****************************************************************/ package org.apache.james.mailbox.cassandra.user; -import org.apache.james.backends.cassandra.CassandraCluster; -import org.apache.james.backends.cassandra.DockerCassandraRule; +import org.apache.james.backends.cassandra.CassandraClusterExtension; +import org.apache.james.backends.cassandra.CassandraRestartExtension; import org.apache.james.backends.cassandra.utils.CassandraUtils; import org.apache.james.mailbox.cassandra.modules.CassandraSubscriptionModule; import org.apache.james.mailbox.store.user.SubscriptionMapper; import org.apache.james.mailbox.store.user.SubscriptionMapperTest; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; -public class CassandraSubscriptionMapperTest extends SubscriptionMapperTest { +@ExtendWith(CassandraRestartExtension.class) +class CassandraSubscriptionMapperTest extends SubscriptionMapperTest { - @Rule public DockerCassandraRule cassandraServer = new DockerCassandraRule().allowRestart(); - - private CassandraCluster cassandra; - - @Override - @Before - public void setUp() { - cassandra = CassandraCluster.create(CassandraSubscriptionModule.MODULE, cassandraServer.getHost()); - super.setUp(); - } + @RegisterExtension + static CassandraClusterExtension cassandraCluster = new CassandraClusterExtension(CassandraSubscriptionModule.MODULE); @Override protected SubscriptionMapper createSubscriptionMapper() { - return new CassandraSubscriptionMapper(cassandra.getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION); - } - - @After - public void tearDown() { - cassandra.clearTables(); - cassandra.closeCluster(); + return new CassandraSubscriptionMapper(cassandraCluster.getCassandraCluster().getConf(), CassandraUtils.WITH_DEFAULT_CONFIGURATION); } } diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryCombinationManagerTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryCombinationManagerTest.java index 3aa7c86..bc4bcc8 100644 --- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryCombinationManagerTest.java +++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryCombinationManagerTest.java @@ -21,15 +21,8 @@ package org.apache.james.mailbox.inmemory; import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources; import org.apache.james.mailbox.store.AbstractCombinationManagerTest; import org.apache.james.mailbox.store.CombinationManagerTestSystem; -import org.junit.Before; -public class InMemoryCombinationManagerTest extends AbstractCombinationManagerTest { - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - } +class InMemoryCombinationManagerTest extends AbstractCombinationManagerTest { @Override public CombinationManagerTestSystem createTestingData() { diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerStorageTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerStorageTest.java index 9f0087a..9853c3f 100644 --- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerStorageTest.java +++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerStorageTest.java @@ -22,15 +22,8 @@ import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources; import org.apache.james.mailbox.store.AbstractMessageIdManagerStorageTest; import org.apache.james.mailbox.store.MessageIdManagerTestSystem; import org.apache.james.mailbox.store.StoreMailboxManager; -import org.junit.Before; -public class InMemoryMessageIdManagerStorageTest extends AbstractMessageIdManagerStorageTest { - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - } +class InMemoryMessageIdManagerStorageTest extends AbstractMessageIdManagerStorageTest { @Override protected MessageIdManagerTestSystem createTestingData() { diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java index b0ea823..fc8f774 100644 --- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java +++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/manager/InMemoryMessageIdManagerSideEffectTest.java @@ -27,15 +27,8 @@ import org.apache.james.mailbox.inmemory.InMemoryMessageId; import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.store.AbstractMessageIdManagerSideEffectTest; import org.apache.james.mailbox.store.MessageIdManagerTestSystem; -import org.junit.Before; -public class InMemoryMessageIdManagerSideEffectTest extends AbstractMessageIdManagerSideEffectTest { - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - } +class InMemoryMessageIdManagerSideEffectTest extends AbstractMessageIdManagerSideEffectTest { @Override protected MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, EventBus eventBus, Set<PreDeletionHook> preDeletionHooks) { diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/user/InMemorySubscriptionMapperTest.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/user/InMemorySubscriptionMapperTest.java index d9f227d..873f7c0 100644 --- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/user/InMemorySubscriptionMapperTest.java +++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/user/InMemorySubscriptionMapperTest.java @@ -22,7 +22,7 @@ package org.apache.james.mailbox.inmemory.user; import org.apache.james.mailbox.store.user.SubscriptionMapper; import org.apache.james.mailbox.store.user.SubscriptionMapperTest; -public class InMemorySubscriptionMapperTest extends SubscriptionMapperTest { +class InMemorySubscriptionMapperTest extends SubscriptionMapperTest { @Override protected SubscriptionMapper createSubscriptionMapper() { diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java index 8f8349b..c817e8c 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java @@ -48,7 +48,8 @@ import org.apache.james.mailbox.model.MessageResult; import org.apache.james.mailbox.model.MultimailboxesSearchQuery; import org.apache.james.mailbox.model.SearchQuery; import org.apache.james.mime4j.dom.Message; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableList; @@ -71,9 +72,10 @@ public abstract class AbstractCombinationManagerTest { private CombinationManagerTestSystem testingData; private Message mailContent; - public abstract CombinationManagerTestSystem createTestingData() throws Exception; + protected abstract CombinationManagerTestSystem createTestingData() throws Exception; - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { session = MailboxSessionUtil.create(MailboxFixture.ALICE); testingData = createTestingData(); @@ -93,7 +95,7 @@ public abstract class AbstractCombinationManagerTest { @Test - public void getMessageCountFromMessageManagerShouldReturnDataSetInMailboxesFromMessageIdManager() throws Exception { + void getMessageCountFromMessageManagerShouldReturnDataSetInMailboxesFromMessageIdManager() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -103,7 +105,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void searchFromMessageManagerShouldReturnMessagesUsingSetInMailboxesFromMessageIdManager() throws Exception { + void searchFromMessageManagerShouldReturnMessagesUsingSetInMailboxesFromMessageIdManager() throws Exception { SearchQuery query = new SearchQuery(); query.andCriteria(SearchQuery.all()); @@ -116,7 +118,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void searchFromMessageManagerShouldReturnMessagesUsingSetInMailboxesFromMessageIdManagerWhenSearchByMailboxQueryWithMailboxPath() throws Exception { + void searchFromMessageManagerShouldReturnMessagesUsingSetInMailboxesFromMessageIdManagerWhenSearchByMailboxQueryWithMailboxPath() throws Exception { SearchQuery query = new SearchQuery(); query.andCriteria(SearchQuery.all()); @@ -135,7 +137,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void searchFromMessageManagerShouldReturnMessagesUsingSetInMailboxesFromMessageIdManagerWhenSearchByMailboxQueryWithUsername() throws Exception { + void searchFromMessageManagerShouldReturnMessagesUsingSetInMailboxesFromMessageIdManagerWhenSearchByMailboxQueryWithUsername() throws Exception { SearchQuery query = new SearchQuery(); query.andCriteria(SearchQuery.all()); @@ -149,7 +151,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void searchFromMailboxManagerShouldReturnMessagesUsingSetInMailboxesFromMessageIdManagerWhenSearchByMultiMailboxes() throws Exception { + void searchFromMailboxManagerShouldReturnMessagesUsingSetInMailboxesFromMessageIdManagerWhenSearchByMultiMailboxes() throws Exception { SearchQuery query = new SearchQuery(); query.andCriteria(SearchQuery.all()); @@ -166,7 +168,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void setFlagsToDeleteThenExpungeFromMessageManagerThenGetMessageFromMessageIdManagerShouldNotReturnAnything() throws Exception { + void setFlagsToDeleteThenExpungeFromMessageManagerThenGetMessageFromMessageIdManagerShouldNotReturnAnything() throws Exception { Flags deleted = new Flags(Flag.DELETED); MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -178,7 +180,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void expungeFromMessageManagerShouldWorkWhenSetFlagsToDeletedWithMessageIdManager() throws Exception { + void expungeFromMessageManagerShouldWorkWhenSetFlagsToDeletedWithMessageIdManager() throws Exception { Flags deleted = new Flags(Flag.DELETED); ComposedMessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session); @@ -190,7 +192,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void expungeFromMessageManagerShouldWorkWhenSetInMailboxesAMessageWithDeletedFlag() throws Exception { //I can mark as DELETED + expunge an mail with setInMbxs + void expungeFromMessageManagerShouldWorkWhenSetInMailboxesAMessageWithDeletedFlag() throws Exception { //I can mark as DELETED + expunge an mail with setInMbxs Flags deleted = new Flags(Flag.DELETED); ComposedMessageId messageId = messageManager1.appendMessage( MessageManager.AppendCommand.builder() @@ -205,7 +207,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMessageFromMessageIdManagerShouldReturnMessageWhenAppendMessageFromMessageManager() throws Exception { + void getMessageFromMessageIdManagerShouldReturnMessageWhenAppendMessageFromMessageManager() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -213,7 +215,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMessageFromMessageIdManagerShouldReturnMessageWhenCopyMessageWithMailboxIdFromMailboxManager() throws Exception { + void getMessageFromMessageIdManagerShouldReturnMessageWhenCopyMessageWithMailboxIdFromMailboxManager() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -227,7 +229,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMessageFromMessageIdManagerShouldReturnMessageWhenCopyMessageWithMailboxPathFromMailboxManager() throws Exception { + void getMessageFromMessageIdManagerShouldReturnMessageWhenCopyMessageWithMailboxPathFromMailboxManager() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -241,7 +243,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMessageFromMessageIdManagerShouldReturnMessageWhenMoveMessageWithMailboxIdFromMailboxManager() throws Exception { + void getMessageFromMessageIdManagerShouldReturnMessageWhenMoveMessageWithMailboxIdFromMailboxManager() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -255,7 +257,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMessagesFromMessageManagerShouldReturnMessagesCreatedBySetInMailboxesFromMessageIdManager() throws Exception { + void getMessagesFromMessageManagerShouldReturnMessagesCreatedBySetInMailboxesFromMessageIdManager() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -267,7 +269,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMetadataFromMessageManagerShouldReturnRecentMessageWhenSetInMailboxesFromMessageIdManager() throws Exception { + void getMetadataFromMessageManagerShouldReturnRecentMessageWhenSetInMailboxesFromMessageIdManager() throws Exception { Flags recent = new Flags(Flag.RECENT); ComposedMessageId messageId = messageManager1.appendMessage( MessageManager.AppendCommand.builder() @@ -284,7 +286,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMetadataFromMessageManagerShouldReturnNumberOfRecentMessageWhenSetInMailboxesFromMessageIdManager() throws Exception { + void getMetadataFromMessageManagerShouldReturnNumberOfRecentMessageWhenSetInMailboxesFromMessageIdManager() throws Exception { Flags recent = new Flags(Flag.RECENT); MessageId messageId = messageManager1.appendMessage( MessageManager.AppendCommand.builder() @@ -298,7 +300,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMetadataFromMessageManagerShouldReturnUidNextWhenSetInMailboxesFromMessageIdManager() throws Exception { + void getMetadataFromMessageManagerShouldReturnUidNextWhenSetInMailboxesFromMessageIdManager() throws Exception { Flags recent = new Flags(Flag.RECENT); ComposedMessageId messageId = messageManager1.appendMessage( MessageManager.AppendCommand.builder() @@ -321,7 +323,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMetadataFromMessageManagerShouldReturnHighestModSeqWhenSetInMailboxesFromMessageIdManager() throws Exception { + void getMetadataFromMessageManagerShouldReturnHighestModSeqWhenSetInMailboxesFromMessageIdManager() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -331,7 +333,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMetadataFromMessageManagerShouldReturnMessageCountWhenSetInMailboxesFromMessageIdManager() throws Exception { + void getMetadataFromMessageManagerShouldReturnMessageCountWhenSetInMailboxesFromMessageIdManager() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -341,7 +343,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMetadataFromMessageManagerShouldReturnNumberOfUnseenMessageWhenSetInMailboxesFromMessageIdManager() throws Exception { + void getMetadataFromMessageManagerShouldReturnNumberOfUnseenMessageWhenSetInMailboxesFromMessageIdManager() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -351,7 +353,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMetadataFromMessageManagerShouldReturnFirstUnseenMessageWhenSetInMailboxesFromMessageIdManager() throws Exception { + void getMetadataFromMessageManagerShouldReturnFirstUnseenMessageWhenSetInMailboxesFromMessageIdManager() throws Exception { ComposedMessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session); messageIdManager.setInMailboxes(messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session); @@ -360,7 +362,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMetadataFromMessageManagerShouldReturnNumberOfUnseenMessageWhenSetFlagsFromMessageIdManager() throws Exception { + void getMetadataFromMessageManagerShouldReturnNumberOfUnseenMessageWhenSetFlagsFromMessageIdManager() throws Exception { Flags newFlag = new Flags(Flag.RECENT); MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -371,7 +373,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getMetadataFromMessageManagerShouldReturnFirstUnseenMessageWhenSetFlagsFromMessageIdManager() throws Exception { + void getMetadataFromMessageManagerShouldReturnFirstUnseenMessageWhenSetFlagsFromMessageIdManager() throws Exception { Flags newFlag = new Flags(Flag.USER); ComposedMessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session); @@ -381,7 +383,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void setInMailboxesFromMessageIdManagerShouldMoveMessage() throws Exception { + void setInMailboxesFromMessageIdManagerShouldMoveMessage() throws Exception { MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -398,7 +400,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void appendMessageFromMessageManagerAndSetInMailboxFromMessageIdManagerShouldUpdateApplicableFlag() throws Exception { + void appendMessageFromMessageManagerAndSetInMailboxFromMessageIdManagerShouldUpdateApplicableFlag() throws Exception { Flags messageFlag = new FlagsBuilder() .add(Flag.ANSWERED) .add(USER_FLAGS_VALUE) @@ -424,7 +426,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void appendMessageFromMessageManagerAndSetFlagsFromMessageIdManagerShouldUnionApplicableFlag() throws Exception { + void appendMessageFromMessageManagerAndSetFlagsFromMessageIdManagerShouldUnionApplicableFlag() throws Exception { Flags messageFlag = new FlagsBuilder() .add(Flag.ANSWERED) .add(USER_FLAGS_VALUE) @@ -450,7 +452,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void setFlagsFromMessageManagerAndSetFlagsFromMessageIdManagerShouldUpdateSameApplicableFlag() throws Exception { + void setFlagsFromMessageManagerAndSetFlagsFromMessageIdManagerShouldUpdateSameApplicableFlag() throws Exception { Flags customFlag1 = new Flags(Flag.ANSWERED); Flags customFlag2 = new Flags("customFlag2"); MessageId messageId = messageManager1.appendMessage( @@ -472,7 +474,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void setInMailboxFromMessageIdManagerAndSetFlagsFromMessageManagerShouldUnionApplicableFlag() throws Exception { + void setInMailboxFromMessageIdManagerAndSetFlagsFromMessageManagerShouldUnionApplicableFlag() throws Exception { Flags custom1 = new Flags("custom1"); Flags custom2 = new Flags("custom2"); MessageId messageId = messageManager1.appendMessage( @@ -493,7 +495,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getUidsShouldInteractWellWithSetInMailboxes() throws Exception { + void getUidsShouldInteractWellWithSetInMailboxes() throws Exception { MessageId messageId = messageManager1 .appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -514,7 +516,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getUidsShouldInteractWellWithDelete() throws Exception { + void getUidsShouldInteractWellWithDelete() throws Exception { MessageId messageId = messageManager1 .appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); @@ -526,7 +528,7 @@ public abstract class AbstractCombinationManagerTest { } @Test - public void getUidsShouldInteractWellWithDeletes() throws Exception { + void getUidsShouldInteractWellWithDeletes() throws Exception { MessageId messageId1 = messageManager1 .appendMessage(MessageManager.AppendCommand.from(mailContent), session) .getMessageId(); diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerQuotaTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerQuotaTest.java index 0ab3809..82190d9 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerQuotaTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerQuotaTest.java @@ -20,6 +20,7 @@ package org.apache.james.mailbox.store; import static org.apache.james.mailbox.fixture.MailboxFixture.ALICE; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import javax.mail.Flags; @@ -36,10 +37,8 @@ import org.apache.james.mailbox.model.MessageId; import org.apache.james.mailbox.quota.CurrentQuotaManager; import org.apache.james.mailbox.quota.MaxQuotaManager; import org.apache.james.mailbox.quota.QuotaManager; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.google.common.collect.ImmutableList; @@ -48,9 +47,6 @@ public abstract class AbstractMessageIdManagerQuotaTest { public static final Flags FLAGS = new Flags(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private MessageIdManager messageIdManager; private MailboxSession session; private Mailbox mailbox1; @@ -67,8 +63,8 @@ public abstract class AbstractMessageIdManagerQuotaTest { protected abstract QuotaManager createQuotaManager(MaxQuotaManager maxQuotaManager, CurrentQuotaManager currentQuotaManager); - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { maxQuotaManager = createMaxQuotaManager(); CurrentQuotaManager currentQuotaManager = createCurrentQuotaManager(); QuotaManager quotaManager = createQuotaManager(maxQuotaManager, currentQuotaManager); @@ -83,7 +79,7 @@ public abstract class AbstractMessageIdManagerQuotaTest { } @Test - public void setInMailboxesShouldNotThrowWhenMessageQuotaNotExceeded() throws Exception { + void setInMailboxesShouldNotThrowWhenMessageQuotaNotExceeded() throws Exception { maxQuotaManager.setGlobalMaxMessage(QuotaCount.count(1)); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session); @@ -92,7 +88,7 @@ public abstract class AbstractMessageIdManagerQuotaTest { } @Test - public void setInMailboxesShouldNotThrowWhenStorageQuotaNotExceeded() throws Exception { + void setInMailboxesShouldNotThrowWhenStorageQuotaNotExceeded() throws Exception { maxQuotaManager.setGlobalMaxStorage(QuotaSize.size(testingData.getConstantMessageSize())); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session); @@ -101,34 +97,40 @@ public abstract class AbstractMessageIdManagerQuotaTest { } @Test - public void setInMailboxesShouldThrowWhenStorageQuotaExceeded() throws Exception { + void setInMailboxesShouldThrowWhenStorageQuotaExceeded() throws Exception { maxQuotaManager.setGlobalMaxStorage(QuotaSize.size(2 * testingData.getConstantMessageSize())); testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session); - expectedException.expect(OverQuotaException.class); - messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session); + assertThatThrownBy(() -> messageIdManager.setInMailboxes(messageId, + ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), + session)) + .isInstanceOf(OverQuotaException.class); } @Test - public void setInMailboxesShouldThrowWhenStorageQuotaExceededWhenCopiedToMultipleMailboxes() throws Exception { + void setInMailboxesShouldThrowWhenStorageQuotaExceededWhenCopiedToMultipleMailboxes() throws Exception { maxQuotaManager.setGlobalMaxStorage(QuotaSize.size(2 * testingData.getConstantMessageSize())); MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); - expectedException.expect(OverQuotaException.class); - messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId(), mailbox3.getMailboxId()), session); + assertThatThrownBy(() -> messageIdManager.setInMailboxes(messageId, + ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId(), mailbox3.getMailboxId()), + session)) + .isInstanceOf(OverQuotaException.class); } @Test - public void setInMailboxesShouldThrowWhenStorageMessageExceeded() throws Exception { + void setInMailboxesShouldThrowWhenStorageMessageExceeded() throws Exception { maxQuotaManager.setGlobalMaxMessage(QuotaCount.count(2)); testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session); - expectedException.expect(OverQuotaException.class); - messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId(), mailbox3.getMailboxId()), session); + assertThatThrownBy(() -> messageIdManager.setInMailboxes(messageId, + ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId(), mailbox3.getMailboxId()), + session)) + .isInstanceOf(OverQuotaException.class); } } diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java index 592281b..0a87367 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMessageIdManagerSideEffectTest.java @@ -66,9 +66,8 @@ import org.apache.james.metrics.api.NoopMetricFactory; import org.assertj.core.api.AbstractListAssert; import org.assertj.core.api.ObjectAssert; import org.assertj.core.api.SoftAssertions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import com.google.common.collect.ImmutableList; @@ -87,9 +86,6 @@ public abstract class AbstractMessageIdManagerSideEffectTest { private static final Flags FLAGS = new Flags(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private MessageIdManager messageIdManager; private MailboxSession session; private Mailbox mailbox1; @@ -104,7 +100,8 @@ public abstract class AbstractMessageIdManagerSideEffectTest { protected abstract MessageIdManagerTestSystem createTestSystem(QuotaManager quotaManager, EventBus eventBus, Set<PreDeletionHook> preDeletionHooks) throws Exception; - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { eventBus = new InVMEventBus(new InVmEventDelivery(new NoopMetricFactory())); eventCollector = new EventCollector(); quotaManager = mock(QuotaManager.class); @@ -130,7 +127,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void deleteShouldCallEventDispatcher() throws Exception { + void deleteShouldCallEventDispatcher() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); @@ -153,7 +150,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { @SuppressWarnings("unchecked") @Test - public void deletesShouldCallEventDispatcher() throws Exception { + void deletesShouldCallEventDispatcher() throws Exception { givenUnlimitedQuota(); MessageId messageId1 = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); MessageId messageId2 = testingData.persist(mailbox1.getMailboxId(), messageUid2, FLAGS, session); @@ -178,7 +175,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void deleteShouldNotCallEventDispatcherWhenMessageIsInWrongMailbox() throws Exception { + void deleteShouldNotCallEventDispatcherWhenMessageIsInWrongMailbox() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session); @@ -189,7 +186,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void deletesShouldCallAllPreDeletionHooks() throws Exception { + void deletesShouldCallAllPreDeletionHooks() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); @@ -212,7 +209,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void deletesShouldCallAllPreDeletionHooksOnEachMessageDeletionCall() throws Exception { + void deletesShouldCallAllPreDeletionHooksOnEachMessageDeletionCall() throws Exception { givenUnlimitedQuota(); MessageId messageId1 = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); @@ -239,7 +236,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void deletesShouldCallAllPreDeletionHooksOnEachMessageDeletionOnDifferentMailboxes() throws Exception { + void deletesShouldCallAllPreDeletionHooksOnEachMessageDeletionOnDifferentMailboxes() throws Exception { givenUnlimitedQuota(); MessageId messageId1 = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); @@ -266,7 +263,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void deletesShouldNotBeExecutedWhenOneOfPreDeleteHooksFails() throws Exception { + void deletesShouldNotBeExecutedWhenOneOfPreDeleteHooksFails() throws Exception { givenUnlimitedQuota(); when(preDeletionHook1.notifyDelete(any(PreDeletionHook.DeleteOperation.class))) .thenThrow(new RuntimeException("throw at hook 1")); @@ -283,7 +280,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void deletesShouldBeExecutedAfterAllHooksFinish() throws Exception { + void deletesShouldBeExecutedAfterAllHooksFinish() throws Exception { givenUnlimitedQuota(); CountDownLatch latchForHook1 = new CountDownLatch(1); @@ -311,7 +308,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setInMailboxesShouldNotCallDispatcherWhenMessageAlreadyInMailbox() throws Exception { + void setInMailboxesShouldNotCallDispatcherWhenMessageAlreadyInMailbox() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); @@ -322,7 +319,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setInMailboxesShouldCallDispatcher() throws Exception { + void setInMailboxesShouldCallDispatcher() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session); @@ -336,7 +333,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setInMailboxesShouldCallDispatcherWithMultipleMailboxes() throws Exception { + void setInMailboxesShouldCallDispatcherWithMultipleMailboxes() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session); @@ -352,7 +349,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setInMailboxesShouldThrowExceptionWhenOverQuota() throws Exception { + void setInMailboxesShouldThrowExceptionWhenOverQuota() throws Exception { MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); when(quotaManager.getStorageQuota(any(QuotaRoot.class))).thenReturn( @@ -361,13 +358,14 @@ public abstract class AbstractMessageIdManagerSideEffectTest { when(quotaManager.getStorageQuota(any(QuotaRoot.class))).thenReturn( Quota.<QuotaSize>builder().used(QuotaSize.size(2)).computedLimit(QuotaSize.unlimited()).build()); - expectedException.expect(OverQuotaException.class); - - messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session); + assertThatThrownBy(() -> messageIdManager.setInMailboxes(messageId, + ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), + session)) + .isInstanceOf(OverQuotaException.class); } @Test - public void setInMailboxesShouldCallDispatchForOnlyAddedAndRemovedMailboxes() throws Exception { + void setInMailboxesShouldCallDispatchForOnlyAddedAndRemovedMailboxes() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session); @@ -388,7 +386,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setFlagsShouldNotDispatchWhenFlagAlreadySet() throws Exception { + void setFlagsShouldNotDispatchWhenFlagAlreadySet() throws Exception { givenUnlimitedQuota(); Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, newFlags, session); @@ -400,7 +398,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setFlagsShouldNotDispatchWhenMessageAlreadyInMailbox() throws Exception { + void setFlagsShouldNotDispatchWhenMessageAlreadyInMailbox() throws Exception { givenUnlimitedQuota(); Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, newFlags, session); @@ -413,7 +411,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setFlagsShouldNotDispatchWhenMessageDoesNotBelongToMailbox() throws Exception { + void setFlagsShouldNotDispatchWhenMessageDoesNotBelongToMailbox() throws Exception { givenUnlimitedQuota(); Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); @@ -425,7 +423,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setFlagsShouldNotDispatchWhenEmptyMailboxes() throws Exception { + void setFlagsShouldNotDispatchWhenEmptyMailboxes() throws Exception { givenUnlimitedQuota(); Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); @@ -437,7 +435,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setFlagsShouldDispatchWhenMessageBelongsToAllMailboxes() throws Exception { + void setFlagsShouldDispatchWhenMessageBelongsToAllMailboxes() throws Exception { givenUnlimitedQuota(); Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session); @@ -450,7 +448,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setFlagsShouldDispatchWhenMessageBelongsToTheMailboxes() throws Exception { + void setFlagsShouldDispatchWhenMessageBelongsToTheMailboxes() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.persist(mailbox2.getMailboxId(), messageUid1, FLAGS, session); @@ -479,7 +477,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void deleteShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception { + void deleteShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.createNotUsedMessageId(); @@ -490,7 +488,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void deletesShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception { + void deletesShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.createNotUsedMessageId(); @@ -501,7 +499,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setFlagsShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception { + void setFlagsShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.createNotUsedMessageId(); @@ -512,7 +510,7 @@ public abstract class AbstractMessageIdManagerSideEffectTest { } @Test - public void setInMailboxesShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception { + void setInMailboxesShouldNotDispatchEventWhenMessageDoesNotExist() throws Exception { givenUnlimitedQuota(); MessageId messageId = testingData.createNotUsedMessageId(); 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 3ea3167..966ff22 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 @@ -47,9 +47,8 @@ import org.apache.james.mailbox.model.MailboxACL.Right; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MessageId; import org.apache.james.mailbox.model.MessageResult; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.github.steveash.guavate.Guavate; import com.google.common.collect.ImmutableList; @@ -70,12 +69,10 @@ public abstract class AbstractMessageIdManagerStorageTest { private MailboxSession bobSession; private MailboxSession systemSession; - @Rule - public ExpectedException expectedException = ExpectedException.none(); - protected abstract MessageIdManagerTestSystem createTestingData() throws Exception; - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { aliceSession = MailboxSessionUtil.create(MailboxFixture.ALICE); bobSession = MailboxSessionUtil.create(MailboxFixture.BOB); systemSession = MailboxSessionUtil.create(Username.of("systemuser")); @@ -89,7 +86,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void getMessagesShouldReturnEmptyListWhenMessageIdNotUsed() throws Exception { + void getMessagesShouldReturnEmptyListWhenMessageIdNotUsed() throws Exception { MessageId messageId = testingData.createNotUsedMessageId(); assertThat(messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, aliceSession)) @@ -97,14 +94,14 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldNotFailWhenMessageDoesNotExist() throws Exception { + void setFlagsShouldNotFailWhenMessageDoesNotExist() throws Exception { MessageId messageId = testingData.createNotUsedMessageId(); messageIdManager.setFlags(FLAGS, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), aliceSession); } @Test - public void deleteMessageShouldReturnNotFoundWhenMessageDoesNotExist() throws MailboxException { + void deleteMessageShouldReturnNotFoundWhenMessageDoesNotExist() throws MailboxException { MessageId messageId = testingData.createNotUsedMessageId(); assertThat(messageIdManager.delete(messageId, bobSession)) @@ -112,14 +109,14 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldNotFailWhenMessageDoesNotExist() throws Exception { + void setInMailboxesShouldNotFailWhenMessageDoesNotExist() throws Exception { MessageId messageId = testingData.createNotUsedMessageId(); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), aliceSession); } @Test - public void getMessagesShouldReturnStoredResults() throws Exception { + void getMessagesShouldReturnStoredResults() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); assertThat(messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, aliceSession)) @@ -127,7 +124,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void getMessageShouldReturnOnlyMessageBelongingToCurrentUser() throws Exception { + void getMessageShouldReturnOnlyMessageBelongingToCurrentUser() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); assertThat(messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, aliceSession)).hasSize(1); @@ -135,7 +132,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldSetMessageInBothMailboxes() throws Exception { + void setInMailboxesShouldSetMessageInBothMailboxes() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), aliceMailbox2.getMailboxId()), aliceSession); @@ -145,7 +142,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldNotDuplicateMessageIfSameMailbox() throws Exception { + void setInMailboxesShouldNotDuplicateMessageIfSameMailbox() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), aliceSession); @@ -155,7 +152,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldSetHighestUidInNewMailbox() throws Exception { + void setInMailboxesShouldSetHighestUidInNewMailbox() throws Exception { MessageId messageId1 = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); MessageId messageId2 = testingData.persist(aliceMailbox2.getMailboxId(), messageUid2, FLAGS, aliceSession); @@ -175,7 +172,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldSetHighestModSeqInNewMailbox() throws Exception { + void setInMailboxesShouldSetHighestModSeqInNewMailbox() throws Exception { MessageId messageId1 = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); MessageId messageId2 = testingData.persist(aliceMailbox2.getMailboxId(), messageUid2, FLAGS, aliceSession); @@ -195,7 +192,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldNotChangeUidAndModSeqInOriginalMailbox() throws Exception { + void setInMailboxesShouldNotChangeUidAndModSeqInOriginalMailbox() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); MessageResult messageResult1 = messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, aliceSession).get(0); MessageUid messageUid1 = messageResult1.getUid(); @@ -216,7 +213,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldAddAndRemoveMailboxes() throws Exception { + void setInMailboxesShouldAddAndRemoveMailboxes() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), aliceMailbox2.getMailboxId()), aliceSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), aliceMailbox3.getMailboxId()), aliceSession); @@ -230,7 +227,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldReplaceFlagsOfMessageInAddedMailboxes() throws Exception { + void setInMailboxesShouldReplaceFlagsOfMessageInAddedMailboxes() throws Exception { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), aliceMailbox2.getMailboxId()), aliceSession); @@ -247,25 +244,27 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldThrowExceptionWhenSetInMailboxesInAnotherSession() throws Exception { - expectedException.expect(MailboxNotFoundException.class); - + void setInMailboxesShouldThrowExceptionWhenSetInMailboxesInAnotherSession() { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); - messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), aliceMailbox2.getMailboxId()), bobSession); + assertThatThrownBy(() -> messageIdManager.setInMailboxes(messageId, + ImmutableList.of(aliceMailbox1.getMailboxId(), aliceMailbox2.getMailboxId()), + bobSession)) + .isInstanceOf(MailboxNotFoundException.class); } @Test - public void setInMailboxesShouldThrowExceptionWhenOneMailboxDoesNotBelongToMailboxSession() throws Exception { - expectedException.expect(MailboxNotFoundException.class); - + void setInMailboxesShouldThrowExceptionWhenOneMailboxDoesNotBelongToMailboxSession() { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); - messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), bobMailbox1.getMailboxId()), aliceSession); + assertThatThrownBy(() -> messageIdManager.setInMailboxes(messageId, + ImmutableList.of(aliceMailbox1.getMailboxId(), bobMailbox1.getMailboxId()), + aliceSession)) + .isInstanceOf(MailboxNotFoundException.class); } @Test - public void setInMailboxesShouldIgnoreMessagesBelongingToOtherUsers() throws Exception { + void setInMailboxesShouldIgnoreMessagesBelongingToOtherUsers() throws Exception { MessageId messageId = testingData.persist(bobMailbox1.getMailboxId(), messageUid1, FLAGS, bobSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), aliceSession); @@ -274,7 +273,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void deleteMessageShouldRemoveMessageFromMailbox() throws Exception { + void deleteMessageShouldRemoveMessageFromMailbox() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.delete(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), aliceSession); @@ -283,7 +282,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void deleteAllMessageShouldRemoveMessageFromMailbox() throws Exception { + void deleteAllMessageShouldRemoveMessageFromMailbox() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.delete(messageId, aliceSession); @@ -292,7 +291,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void deleteMessageShouldRemoveMessageOnlyFromMailbox() throws Exception { + void deleteMessageShouldRemoveMessageOnlyFromMailbox() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), aliceMailbox2.getMailboxId()), aliceSession); @@ -304,7 +303,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void deleteAllShouldRemoveMessageFromAllMailbox() throws Exception { + void deleteAllShouldRemoveMessageFromAllMailbox() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), aliceMailbox2.getMailboxId()), aliceSession); @@ -314,7 +313,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void deleteMessageShouldNotRemoveMessageOnAnotherMailbox() throws Exception { + void deleteMessageShouldNotRemoveMessageOnAnotherMailbox() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.delete(messageId, ImmutableList.of(aliceMailbox2.getMailboxId()), aliceSession); @@ -325,16 +324,15 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void deleteMessageShouldThrowExceptionWhenDeletingOnOtherSession() throws Exception { - expectedException.expect(MailboxNotFoundException.class); - + void deleteMessageShouldThrowExceptionWhenDeletingOnOtherSession() { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); - messageIdManager.delete(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), bobSession); + assertThatThrownBy(() -> messageIdManager.delete(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), bobSession)) + .isInstanceOf(MailboxNotFoundException.class); } @Test - public void deleteAllShouldReturnNotFoundWhenDeletingOnOtherSession() throws Exception { + void deleteAllShouldReturnNotFoundWhenDeletingOnOtherSession() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); assertThat(messageIdManager.delete(messageId, bobSession)) @@ -342,25 +340,23 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void deleteMessageShouldThrowExceptionWhenDeletingOnSystemSession() throws Exception { - expectedException.expect(MailboxNotFoundException.class); - + void deleteMessageShouldThrowExceptionWhenDeletingOnSystemSession() { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); - messageIdManager.delete(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), systemSession); + assertThatThrownBy(() -> messageIdManager.delete(messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), systemSession)) + .isInstanceOf(MailboxNotFoundException.class); } @Test - public void deleteMessageShouldThrowExceptionWhenOneMailboxDoesNotBelongToUser() throws Exception { - expectedException.expect(MailboxNotFoundException.class); - + void deleteMessageShouldThrowExceptionWhenOneMailboxDoesNotBelongToUser() { MessageId messageId = testingData.persist(bobMailbox1.getMailboxId(), messageUid1, FLAGS, bobSession); - messageIdManager.delete(messageId, ImmutableList.of(bobMailbox1.getMailboxId()), aliceSession); + assertThatThrownBy(() -> messageIdManager.delete(messageId, ImmutableList.of(bobMailbox1.getMailboxId()), aliceSession)) + .isInstanceOf(MailboxNotFoundException.class); } @Test - public void setFlagsShouldUpdateFlags() throws Exception { + void setFlagsShouldUpdateFlags() throws Exception { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); @@ -371,7 +367,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldNotChangeTheUid() throws Exception { + void setFlagsShouldNotChangeTheUid() throws Exception { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); @@ -387,7 +383,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldChangeTheModSeq() throws Exception { + void setFlagsShouldChangeTheModSeq() throws Exception { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); @@ -403,7 +399,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldChangeFlagsInAllMailboxes() throws Exception { + void setFlagsShouldChangeFlagsInAllMailboxes() throws Exception { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), aliceMailbox2.getMailboxId()), aliceSession); @@ -421,7 +417,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldNotChangeFlagsOfAnotherMessageInSameMailbox() throws Exception { + void setFlagsShouldNotChangeFlagsOfAnotherMessageInSameMailbox() throws Exception { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId1 = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); MessageId messageId2 = testingData.persist(aliceMailbox1.getMailboxId(), messageUid2, FLAGS, aliceSession); @@ -438,7 +434,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldNotChangeFlagsWhenEmptyMailboxes() throws Exception { + void setFlagsShouldNotChangeFlagsWhenEmptyMailboxes() throws Exception { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId1 = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); @@ -454,7 +450,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldNotChangeFlagsWhenMessageDoesNotBelongToTheMailboxes() throws Exception { + void setFlagsShouldNotChangeFlagsWhenMessageDoesNotBelongToTheMailboxes() throws Exception { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId1 = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); @@ -470,7 +466,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldChangeFlagsWhenMessageBelongsToTheMailboxes() throws Exception { + void setFlagsShouldChangeFlagsWhenMessageBelongsToTheMailboxes() throws Exception { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId1 = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); MessageId messageId2 = testingData.persist(aliceMailbox2.getMailboxId(), messageUid2, FLAGS, aliceSession); @@ -487,37 +483,46 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldThrowExceptionWhenSetFlagsOnOtherSession() throws Exception { - expectedException.expect(MailboxNotFoundException.class); - + void setFlagsShouldThrowExceptionWhenSetFlagsOnOtherSession() { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); - messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), bobSession); + assertThatThrownBy(() -> messageIdManager.setFlags(newFlags, + MessageManager.FlagsUpdateMode.ADD, + messageId, + ImmutableList.of(aliceMailbox1.getMailboxId()), + bobSession)) + .isInstanceOf(MailboxNotFoundException.class); } @Test - public void setFlagsShouldThrowExceptionWhenSetFlagsOnSystemSession() throws Exception { - expectedException.expect(MailboxNotFoundException.class); - + void setFlagsShouldThrowExceptionWhenSetFlagsOnSystemSession() { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); - messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(aliceMailbox1.getMailboxId()), systemSession); + assertThatThrownBy(() -> messageIdManager.setFlags(newFlags, + MessageManager.FlagsUpdateMode.ADD, + messageId, + ImmutableList.of(aliceMailbox1.getMailboxId()), + systemSession)) + .isInstanceOf(MailboxNotFoundException.class); } @Test - public void setFlagsShouldThrowExceptionWhenMailboxDoesNotBelongToMailboxSession() throws Exception { - expectedException.expect(MailboxNotFoundException.class); + void setFlagsShouldThrowExceptionWhenMailboxDoesNotBelongToMailboxSession() { Flags newFlags = new Flags(Flags.Flag.SEEN); MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); - messageIdManager.setFlags(newFlags, MessageManager.FlagsUpdateMode.ADD, messageId, ImmutableList.of(aliceMailbox1.getMailboxId(), bobMailbox1.getMailboxId()), aliceSession); - + assertThatThrownBy(() -> messageIdManager.setFlags(newFlags, + MessageManager.FlagsUpdateMode.ADD, + messageId, + ImmutableList.of(aliceMailbox1.getMailboxId(), bobMailbox1.getMailboxId()), + aliceSession)) + .isInstanceOf(MailboxNotFoundException.class); } @Test - public void getMessageShouldBeEmptyWhenMessageHasNoMoreMailboxes() throws Exception { + void getMessageShouldBeEmptyWhenMessageHasNoMoreMailboxes() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); testingData.deleteMailbox(aliceMailbox1.getMailboxId(), aliceSession); @@ -526,7 +531,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldPreserveMessageFromOneMailboxDeletion() throws Exception { + void setInMailboxesShouldPreserveMessageFromOneMailboxDeletion() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); messageIdManager.setInMailboxes(messageId, ImmutableList.of(aliceMailbox2.getMailboxId()), aliceSession); @@ -538,7 +543,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void accessibleMessagesShouldReturnMessageIdsThatBelongsToTheUser() throws Exception { + void accessibleMessagesShouldReturnMessageIdsThatBelongsToTheUser() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); assertThat(messageIdManager.accessibleMessages(ImmutableList.of(messageId), aliceSession)) @@ -546,19 +551,19 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void accessibleMessagesShouldReturnEmptyWhenSuppliedMessageIdsAreEmpty() throws Exception { + void accessibleMessagesShouldReturnEmptyWhenSuppliedMessageIdsAreEmpty() throws Exception { assertThat(messageIdManager.accessibleMessages(ImmutableList.of(), aliceSession)) .isEmpty(); } @Test - public void accessibleMessagesShouldFilterOutMessageIdsWhenNotExisting() throws Exception { + void accessibleMessagesShouldFilterOutMessageIdsWhenNotExisting() throws Exception { assertThat(messageIdManager.accessibleMessages(ImmutableList.of(testingData.createNotUsedMessageId()), aliceSession)) .isEmpty(); } @Test - public void accessibleMessagesShouldFilterOutMessageIdsWhenNotBelongingToTheUser() throws Exception { + void accessibleMessagesShouldFilterOutMessageIdsWhenNotBelongingToTheUser() throws Exception { MessageId messageId = testingData.persist(aliceMailbox1.getMailboxId(), messageUid1, FLAGS, aliceSession); assertThat(messageIdManager.accessibleMessages(ImmutableList.of(messageId), bobSession)) @@ -570,7 +575,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void getMessagesShouldReturnMessagesWhenReadDelegated() throws Exception { + void getMessagesShouldReturnMessagesWhenReadDelegated() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() @@ -589,7 +594,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void getMessagesShouldNotReturnMessagesWhenNotReadDelegated() throws Exception { + void getMessagesShouldNotReturnMessagesWhenNotReadDelegated() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() @@ -606,7 +611,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldUpdateFlagsWhenWriteDelegated() throws Exception { + void setFlagsShouldUpdateFlagsWhenWriteDelegated() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() @@ -627,7 +632,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setFlagsShouldNotUpdateFlagsWhenNotWriteDelegated() throws Exception { + void setFlagsShouldNotUpdateFlagsWhenNotWriteDelegated() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() @@ -649,7 +654,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldAllowCopyingMessageFromReadOnlySharedMailbox() throws Exception { + void setInMailboxesShouldAllowCopyingMessageFromReadOnlySharedMailbox() throws Exception { //Given testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( @@ -674,7 +679,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldDenyCopyingMessageFromNotReadSharedMailbox() throws Exception { + void setInMailboxesShouldDenyCopyingMessageFromNotReadSharedMailbox() throws Exception { //Given testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( @@ -702,7 +707,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldAllowCopyingToAInsertSharedMailbox() throws Exception { + void setInMailboxesShouldAllowCopyingToAInsertSharedMailbox() throws Exception { //Given testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( @@ -730,7 +735,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldDenyCopyingToANonInsertSharedMailbox() throws Exception { + void setInMailboxesShouldDenyCopyingToANonInsertSharedMailbox() throws Exception { //Given testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( @@ -762,7 +767,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldAllowMovingMessagesFromASharedMailboxWhenDeleteRight() throws Exception { + void setInMailboxesShouldAllowMovingMessagesFromASharedMailboxWhenDeleteRight() throws Exception { //Given testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( @@ -790,7 +795,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldDenyMovingMessagesFromASharedMailboxWhenNoDeleteRight() throws Exception { + void setInMailboxesShouldDenyMovingMessagesFromASharedMailboxWhenNoDeleteRight() throws Exception { //Given testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( @@ -822,7 +827,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxShouldAllowDistinctMailboxSetForShareeAndOwner() throws Exception { + void setInMailboxShouldAllowDistinctMailboxSetForShareeAndOwner() throws Exception { //Given testingData.setACL(aliceMailbox2.getMailboxId(), MailboxACL.EMPTY.apply( @@ -864,7 +869,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void deleteShouldRemoveMessagesFromSharedMailboxWhenAllowed() throws Exception { + void deleteShouldRemoveMessagesFromSharedMailboxWhenAllowed() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() @@ -882,7 +887,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void deleteShouldNotRemoveMessagesFromSharedMailboxWhenNotAllowed() throws Exception { + void deleteShouldNotRemoveMessagesFromSharedMailboxWhenNotAllowed() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() @@ -903,7 +908,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void accessibleMessagesShouldReturnMessagesWhenReadDelegated() throws Exception { + void accessibleMessagesShouldReturnMessagesWhenReadDelegated() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() @@ -920,7 +925,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void accessibleMessagesShouldNotReturnMessagesWhenNotReadDelegated() throws Exception { + void accessibleMessagesShouldNotReturnMessagesWhenNotReadDelegated() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() @@ -937,7 +942,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldSanitizeFlagsWhenNoWriteRight() throws Exception { + void setInMailboxesShouldSanitizeFlagsWhenNoWriteRight() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() @@ -957,7 +962,7 @@ public abstract class AbstractMessageIdManagerStorageTest { } @Test - public void setInMailboxesShouldPreserveFlagsWhenWriteRight() throws Exception { + void setInMailboxesShouldPreserveFlagsWhenWriteRight() throws Exception { testingData.setACL(aliceMailbox1.getMailboxId(), MailboxACL.EMPTY.apply( MailboxACL.command() diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/user/SubscriptionMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/user/SubscriptionMapperTest.java index e4feba0..f085ff8 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/user/SubscriptionMapperTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/user/SubscriptionMapperTest.java @@ -26,8 +26,8 @@ import java.util.List; import org.apache.james.mailbox.exception.SubscriptionException; import org.apache.james.mailbox.store.user.model.Subscription; import org.apache.james.mailbox.store.user.model.impl.SimpleSubscription; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public abstract class SubscriptionMapperTest { private static final String USER_1 = "user1"; @@ -39,27 +39,27 @@ public abstract class SubscriptionMapperTest { protected abstract SubscriptionMapper createSubscriptionMapper(); - @Before - public void setUp() { + @BeforeEach + void setUp() { testee = createSubscriptionMapper(); } @Test - public void findSubscriptionsForUserShouldBeEmptyByDefault() throws SubscriptionException { + void findSubscriptionsForUserShouldBeEmptyByDefault() throws SubscriptionException { List<Subscription> subscriptions = testee.findSubscriptionsForUser(USER_1); assertThat(subscriptions).isEmpty(); } @Test - public void findMailboxSubscriptionForUserShouldReturnNullByDefault() throws SubscriptionException { + void findMailboxSubscriptionForUserShouldReturnNullByDefault() throws SubscriptionException { Subscription subscriptions = testee.findMailboxSubscriptionForUser(USER_1,MAILBOX_1); assertThat(subscriptions).isNull(); } @Test - public void findMailboxSubscriptionForUserShouldReturnSubscription() throws SubscriptionException { + void findMailboxSubscriptionForUserShouldReturnSubscription() throws SubscriptionException { SimpleSubscription subscription = new SimpleSubscription(USER_1, MAILBOX_1); testee.save(subscription); @@ -69,7 +69,7 @@ public abstract class SubscriptionMapperTest { } @Test - public void findSubscriptionsForUserShouldReturnSubscriptions() throws SubscriptionException { + void findSubscriptionsForUserShouldReturnSubscriptions() throws SubscriptionException { SimpleSubscription subscription1 = new SimpleSubscription(USER_1, MAILBOX_1); SimpleSubscription subscription2 = new SimpleSubscription(USER_1, MAILBOX_2); testee.save(subscription1); @@ -81,7 +81,7 @@ public abstract class SubscriptionMapperTest { } @Test - public void findSubscriptionsForUserShouldReturnOnlyUserSubscriptions() throws SubscriptionException { + void findSubscriptionsForUserShouldReturnOnlyUserSubscriptions() throws SubscriptionException { SimpleSubscription subscription1 = new SimpleSubscription(USER_1,MAILBOX_1); SimpleSubscription subscription2 = new SimpleSubscription(USER_2,MAILBOX_2); testee.save(subscription1); @@ -93,7 +93,7 @@ public abstract class SubscriptionMapperTest { } @Test - public void findMailboxSubscriptionForUserShouldReturnOnlyUserSubscriptions() throws SubscriptionException { + void findMailboxSubscriptionForUserShouldReturnOnlyUserSubscriptions() throws SubscriptionException { SimpleSubscription subscription1 = new SimpleSubscription(USER_1,MAILBOX_1); SimpleSubscription subscription2 = new SimpleSubscription(USER_2,MAILBOX_1); testee.save(subscription1); @@ -105,7 +105,7 @@ public abstract class SubscriptionMapperTest { } @Test - public void findMailboxSubscriptionForUserShouldReturnSubscriptionConcerningTheMailbox() throws SubscriptionException { + void findMailboxSubscriptionForUserShouldReturnSubscriptionConcerningTheMailbox() throws SubscriptionException { SimpleSubscription subscription1 = new SimpleSubscription(USER_1,MAILBOX_1); SimpleSubscription subscription2 = new SimpleSubscription(USER_1,MAILBOX_2); testee.save(subscription1); @@ -117,7 +117,7 @@ public abstract class SubscriptionMapperTest { } @Test - public void deleteShouldRemoveSubscription() throws SubscriptionException { + void deleteShouldRemoveSubscription() throws SubscriptionException { SimpleSubscription subscription = new SimpleSubscription(USER_1, MAILBOX_1); testee.save(subscription); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org