You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/12/20 06:13:40 UTC

james-project git commit: Cleanup: Avoid using AssertJ Assertions.fail()

Repository: james-project
Updated Branches:
  refs/heads/master cba3030e6 -> a1340b7c0


Cleanup: Avoid using AssertJ Assertions.fail()


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

Branch: refs/heads/master
Commit: a1340b7c022530c9c98881fa5fcf0969568fac8d
Parents: cba3030
Author: benwa <bt...@linagora.com>
Authored: Mon Dec 18 13:05:31 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Dec 20 13:13:02 2017 +0700

----------------------------------------------------------------------
 .../init/CassandraTypeProviderTest.java         |  15 +-
 .../mail/CassandraMailboxMapperTest.java        |  20 +--
 .../store/mail/model/MailboxMapperTest.java     |  45 ++----
 .../mailbox/store/quota/QuotaCheckerTest.java   |  42 ++---
 .../org/apache/james/cli/ServerCmdTest.java     |  44 ++---
 .../utils/InMemoryMailRepositoryStoreTest.java  |  34 ++--
 .../lib/AbstractRecipientRewriteTableTest.java  | 159 +++++++------------
 .../james/rrt/lib/RewriteTablesStepdefs.java    |  15 +-
 .../resources/cucumber/rewrite_tables.feature   |  10 +-
 9 files changed, 137 insertions(+), 247 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a1340b7c/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraTypeProviderTest.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraTypeProviderTest.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraTypeProviderTest.java
index 3517349..4a3212b 100644
--- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraTypeProviderTest.java
+++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/init/CassandraTypeProviderTest.java
@@ -21,7 +21,6 @@ package org.apache.james.backends.cassandra.init;
 
 import static com.datastax.driver.core.DataType.text;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
 
 import java.util.Arrays;
 import java.util.List;
@@ -80,7 +79,8 @@ public class CassandraTypeProviderTest {
 
     @Test
     public void initializeTypesShouldCreateTheTypes() {
-        deleteMailboxBaseType();
+        cassandra.getConf().execute(SchemaBuilder.dropType(TYPE_NAME));
+
         new CassandraTypesCreator(module, cassandra.getConf()).initializeTypes();
         CassandraTypesProvider cassandraTypesProviderTest = new CassandraTypesProvider(module, cassandra.getConf());
         assertThat(cassandraTypesProviderTest.getDefinedUserType(TYPE_NAME))
@@ -94,15 +94,4 @@ public class CassandraTypeProviderTest {
             .isNotNull();
     }
 
-    private void deleteMailboxBaseType() {
-        try {
-            cassandra.getConf().execute(SchemaBuilder.dropType(TYPE_NAME));
-        } catch (Exception exception) {
-            exception.printStackTrace();
-            fail("Exception is thrown on Type deletion");
-        }
-    }
-
-
-
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/a1340b7c/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java
index 2827bf9..b316a99 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java
@@ -20,9 +20,7 @@
 package org.apache.james.mailbox.cassandra.mail;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-
-import java.util.Optional;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.james.backends.cassandra.CassandraCluster;
@@ -30,7 +28,6 @@ import org.apache.james.backends.cassandra.DockerCassandraRule;
 import org.apache.james.backends.cassandra.init.CassandraConfiguration;
 import org.apache.james.backends.cassandra.init.CassandraModuleComposite;
 import org.apache.james.backends.cassandra.utils.CassandraUtils;
-import org.apache.james.mailbox.cassandra.mail.CassandraMailboxPathDAO.CassandraIdAndPath;
 import org.apache.james.mailbox.cassandra.modules.CassandraAclModule;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxModule;
 import org.apache.james.mailbox.exception.TooLongMailboxNameException;
@@ -83,16 +80,13 @@ public class CassandraMailboxMapperTest {
         testee.save(new SimpleMailbox(MAILBOX_PATH, UID_VALIDITY));
         Mailbox mailbox = testee.findMailboxByPath(MAILBOX_PATH);
 
-        try {
-            SimpleMailbox newMailbox = new SimpleMailbox(tooLongMailboxPath(mailbox.generateAssociatedPath()), UID_VALIDITY, mailbox.getMailboxId());
-            testee.save(newMailbox);
-            fail("TooLongMailboxNameException expected");
-        } catch (TooLongMailboxNameException e) {
-            LOGGER.info("Ignored error", e);
-        }
+        SimpleMailbox newMailbox = new SimpleMailbox(tooLongMailboxPath(mailbox.generateAssociatedPath()), UID_VALIDITY, mailbox.getMailboxId());
+        assertThatThrownBy(() ->
+            testee.save(newMailbox))
+            .isInstanceOf(TooLongMailboxNameException.class);
 
-        Optional<CassandraIdAndPath> cassandraIdAndPath = mailboxPathDAO.retrieveId(MAILBOX_PATH).get();
-        assertThat(cassandraIdAndPath.isPresent()).isTrue();
+        assertThat(mailboxPathDAO.retrieveId(MAILBOX_PATH).join())
+            .isPresent();
     }
 
     private MailboxPath tooLongMailboxPath(MailboxPath fromMailboxPath) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/a1340b7c/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java
index d16925d..d3f835b 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java
@@ -21,7 +21,7 @@ package org.apache.james.mailbox.store.mail.model;
 
 import static org.apache.james.mailbox.store.mail.model.ListMailboxAssert.assertMailboxes;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.util.List;
 
@@ -33,9 +33,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.Assume;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 /**
  * Generic purpose tests for your implementation MailboxMapper.
@@ -77,8 +75,6 @@ public abstract class MailboxMapperTest {
     private MailboxPath bobDifferentNamespacePath;
     private Mailbox bobDifferentNamespaceMailbox;
 
-    @Rule
-    public ExpectedException expected = ExpectedException.none();
     private MailboxMapper mailboxMapper;
     private MapperProvider mapperProvider;
 
@@ -95,8 +91,8 @@ public abstract class MailboxMapperTest {
 
     @Test
     public void findMailboxByPathWhenAbsentShouldFail() throws MailboxException {
-        expected.expect(MailboxNotFoundException.class);
-        mailboxMapper.findMailboxByPath(MailboxPath.forUser("benwa", "INBOX"));
+        assertThatThrownBy(() -> mailboxMapper.findMailboxByPath(MailboxPath.forUser("benwa", "INBOX")))
+            .isInstanceOf(MailboxNotFoundException.class);
     }
 
     @Test
@@ -107,14 +103,13 @@ public abstract class MailboxMapperTest {
 
     @Test
     public void saveShouldThrowWhenMailboxAlreadyExist() throws MailboxException{
-        expected.expect(MailboxExistsException.class);
-
         mailboxMapper.save(benwaInboxMailbox);
 
         SimpleMailbox mailbox = new SimpleMailbox(benwaInboxMailbox);
         mailbox.setMailboxId(null);
 
-        mailboxMapper.save(mailbox);
+        assertThatThrownBy(() ->mailboxMapper.save(mailbox))
+            .isInstanceOf(MailboxExistsException.class);
     }
 
     @Test
@@ -176,26 +171,20 @@ public abstract class MailboxMapperTest {
     
     @Test
     public void deleteShouldEraseTheGivenMailbox() throws MailboxException {
-        expected.expect(MailboxNotFoundException.class);
-        try {
-            saveAll();
-            mailboxMapper.delete(benwaInboxMailbox);
-        } catch(MailboxException exception) {
-            fail("Error was not thrown by the appropriate method", exception);
-        }
-        mailboxMapper.findMailboxByPath(benwaInboxPath);
+        saveAll();
+        mailboxMapper.delete(benwaInboxMailbox);
+
+        assertThatThrownBy(() -> mailboxMapper.findMailboxByPath(benwaInboxPath))
+            .isInstanceOf(MailboxNotFoundException.class);
     }
 
     @Test
     public void deleteWithNullUserShouldEraseTheGivenMailbox() throws MailboxException {
-        expected.expect(MailboxNotFoundException.class);
-        try {
-            saveAll();
-            mailboxMapper.delete(esnDevGroupJamesMailbox);
-        } catch(MailboxException exception) {
-            fail("Error was not thrown by the appropriate method", exception);
-        }
-        mailboxMapper.findMailboxByPath(esnDevGroupJamesPath);
+        saveAll();
+        mailboxMapper.delete(esnDevGroupJamesMailbox);
+
+        assertThatThrownBy(() -> mailboxMapper.findMailboxByPath(esnDevGroupJamesPath))
+            .isInstanceOf(MailboxNotFoundException.class);
     }
 
     @Test
@@ -253,11 +242,11 @@ public abstract class MailboxMapperTest {
     
     @Test
     public void findMailboxByIdShouldFailWhenAbsent() throws MailboxException {
-        expected.expect(MailboxNotFoundException.class);
         saveAll();
         MailboxId removed = benwaInboxMailbox.getMailboxId();
         mailboxMapper.delete(benwaInboxMailbox);
-        mailboxMapper.findMailboxById(removed);
+        assertThatThrownBy(() -> mailboxMapper.findMailboxById(removed))
+            .isInstanceOf(MailboxNotFoundException.class);
     }
 
     private void initData() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/a1340b7c/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaCheckerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaCheckerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaCheckerTest.java
index 55a8870..1902e84 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaCheckerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/quota/QuotaCheckerTest.java
@@ -20,7 +20,7 @@
 package org.apache.james.mailbox.store.quota;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -76,34 +76,26 @@ public class QuotaCheckerTest {
         assertThat(quotaChecker.tryAddition(90, 900)).isTrue();
     }
 
-    @Test(expected = OverQuotaException.class)
+    @Test
     public void quotaCheckerShouldThrowOnExceededMessages() throws MailboxException {
-        QuotaChecker quotaChecker;
-        try {
-            when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
-            when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenReturn(QuotaImpl.quota(10, 100));
-            when(mockedQuotaManager.getStorageQuota(QUOTA_ROOT)).thenReturn(QuotaImpl.quota(100, 1000));
-            quotaChecker = new QuotaChecker(mockedQuotaManager, mockedQuotaRootResolver, MAILBOX);
-        } catch(Exception e) {
-            fail("Exception caught : ", e);
-            return;
-        }
-        quotaChecker.tryAddition(91, 899);
+        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+        when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenReturn(QuotaImpl.quota(10, 100));
+        when(mockedQuotaManager.getStorageQuota(QUOTA_ROOT)).thenReturn(QuotaImpl.quota(100, 1000));
+        QuotaChecker quotaChecker = new QuotaChecker(mockedQuotaManager, mockedQuotaRootResolver, MAILBOX);
+
+        assertThatThrownBy(() -> quotaChecker.tryAddition(91, 899))
+            .isInstanceOf(OverQuotaException.class);
     }
 
-    @Test(expected = OverQuotaException.class)
+    @Test
     public void quotaCheckerShouldThrowOnExceededStorage() throws MailboxException {
-        QuotaChecker quotaChecker;
-        try {
-            when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
-            when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenReturn(QuotaImpl.quota(10, 100));
-            when(mockedQuotaManager.getStorageQuota(QUOTA_ROOT)).thenReturn(QuotaImpl.quota(100, 1000));
-            quotaChecker = new QuotaChecker(mockedQuotaManager, mockedQuotaRootResolver, MAILBOX);
-        } catch(Exception e) {
-            fail("Exception caught : ", e);
-            return;
-        }
-        quotaChecker.tryAddition(89, 901);
+        when(mockedQuotaRootResolver.getQuotaRoot(MAILBOX_PATH)).thenReturn(QUOTA_ROOT);
+        when(mockedQuotaManager.getMessageQuota(QUOTA_ROOT)).thenReturn(QuotaImpl.quota(10, 100));
+        when(mockedQuotaManager.getStorageQuota(QUOTA_ROOT)).thenReturn(QuotaImpl.quota(100, 1000));
+        QuotaChecker quotaChecker = new QuotaChecker(mockedQuotaManager, mockedQuotaRootResolver, MAILBOX);
+
+        assertThatThrownBy(() -> quotaChecker.tryAddition(89, 901))
+            .isInstanceOf(OverQuotaException.class);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/a1340b7c/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
----------------------------------------------------------------------
diff --git a/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java b/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
index efe9d19..b797683 100644
--- a/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
+++ b/server/container/cli/src/test/java/org/apache/james/cli/ServerCmdTest.java
@@ -20,7 +20,7 @@
 package org.apache.james.cli;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.easymock.EasyMock.createControl;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
@@ -1358,43 +1358,31 @@ public class ServerCmdTest {
         assertThat(ServerCmd.getPort(commandLine)).isEqualTo(9999);
     }
 
-    @Test(expected = InvalidPortException.class)
+    @Test
     public void getPortShouldThrowOnNullPortValueOption() throws Exception {
         String[] arguments = { "-h", "127.0.0.1", "-p", "0", "command", "arg1", "arg2", "arg3" };
-        CommandLine commandLine;
-        try {
-            commandLine = ServerCmd.parseCommandLine(arguments);
-        } catch (Exception e) {
-            fail("Exception received", e);
-            return;
-        }
-        ServerCmd.getPort(commandLine);
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        assertThatThrownBy(() -> ServerCmd.getPort(commandLine))
+            .isInstanceOf(InvalidPortException.class);
     }
 
-    @Test(expected = InvalidPortException.class)
+    @Test
     public void getPortShouldThrowOnNegativePortValueOption() throws Exception {
         String[] arguments = { "-h", "127.0.0.1", "-p", "-1", "command", "arg1", "arg2", "arg3" };
-        CommandLine commandLine;
-        try {
-            commandLine = ServerCmd.parseCommandLine(arguments);
-        } catch (Exception e) {
-            fail("Exception received", e);
-            return;
-        }
-        ServerCmd.getPort(commandLine);
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        assertThatThrownBy(() -> ServerCmd.getPort(commandLine))
+            .isInstanceOf(InvalidPortException.class);
     }
 
-    @Test(expected = InvalidPortException.class)
+    @Test
     public void getPortShouldThrowOnTooHighPortValueOption() throws Exception {
         String[] arguments = { "-h", "127.0.0.1", "-p", "99999", "command", "arg1", "arg2", "arg3" };
-        CommandLine commandLine;
-        try {
-            commandLine = ServerCmd.parseCommandLine(arguments);
-        } catch (Exception e) {
-            fail("Exception received", e);
-            return;
-        }
-        ServerCmd.getPort(commandLine);
+        CommandLine commandLine = ServerCmd.parseCommandLine(arguments);
+
+        assertThatThrownBy(() -> ServerCmd.getPort(commandLine))
+            .isInstanceOf(InvalidPortException.class);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/a1340b7c/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java
index 8c4e309..6aa89a2 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java
@@ -20,16 +20,16 @@
 package org.apache.james.utils;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.james.server.core.JamesServerResourceLoader;
-import org.apache.james.server.core.filesystem.FileSystemImpl;
 import org.apache.james.filesystem.api.FileSystem;
 import org.apache.james.mailrepository.api.MailRepositoryStore;
 import org.apache.james.mailrepository.file.FileMailRepository;
 import org.apache.james.modules.server.MailStoreRepositoryModule;
+import org.apache.james.server.core.JamesServerResourceLoader;
+import org.apache.james.server.core.filesystem.FileSystemImpl;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -71,28 +71,22 @@ public class InMemoryMailRepositoryStoreTest {
         assertThat(repositoryStore.select("file://repo")).isNotEqualTo(repositoryStore.select("file://repo1"));
     }
 
-    @Test(expected = ConfigurationException.class)
+    @Test
     public void configureShouldThrowWhenNonValidClassesAreProvided() throws Exception {
-        try {
-            repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet(
-                    new MailStoreRepositoryModule.FileMailRepositoryProvider(
-                            fileSystem)));
-            repositoryStore.configure(new FileConfigurationProvider(fileSystem, FileSystem.CLASSPATH_PROTOCOL).getConfiguration("fakemailrepositorystore"));
-        } catch (ConfigurationException e) {
-            fail("Unexpected failure : ", e);
-        }
-        repositoryStore.init();
+        repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet(
+            new MailStoreRepositoryModule.FileMailRepositoryProvider(
+                fileSystem)));
+        repositoryStore.configure(new FileConfigurationProvider(fileSystem, FileSystem.CLASSPATH_PROTOCOL).getConfiguration("fakemailrepositorystore"));
+
+        assertThatThrownBy(() -> repositoryStore.init())
+            .isInstanceOf(ConfigurationException.class);
     }
 
     @Test
     public void configureShouldNotThrowOnEmptyConfiguration() throws Exception {
-        try {
-            repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet(
-                new MailStoreRepositoryModule.FileMailRepositoryProvider(
-                    fileSystem)));
-        } catch (Exception e) {
-            fail("Unexpected failure : ", e);
-        }
+        repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet(
+            new MailStoreRepositoryModule.FileMailRepositoryProvider(
+                fileSystem)));
         repositoryStore.configure(new HierarchicalConfiguration());
 
         repositoryStore.init();

http://git-wip-us.apache.org/repos/asf/james-project/blob/a1340b7c/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
index 35d8172..eaefd1d 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/AbstractRecipientRewriteTableTest.java
@@ -19,7 +19,7 @@
 package org.apache.james.rrt.lib;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.util.Map;
 
@@ -77,7 +77,6 @@ public abstract class AbstractRecipientRewriteTableTest {
 
     @Test
     public void testStoreAndGetMappings() throws ErrorMappingException, RecipientRewriteTableException {
-
         String user = "*";
         String domain = "test";
         String regex = "prefix_.*:admin@test";
@@ -87,7 +86,6 @@ public abstract class AbstractRecipientRewriteTableTest {
 
     @Test
     public void testStoreAndRetrieveRegexMapping() throws ErrorMappingException, RecipientRewriteTableException {
-
         String user = "test";
         String domain = "localhost";
         // String regex = "(.*):{$1}@localhost";
@@ -95,36 +93,25 @@ public abstract class AbstractRecipientRewriteTableTest {
         String regex = "(.*)@localhost";
         String regex2 = "(.+)@test";
         String invalidRegex = ".*):";
-        boolean catched = false;
 
-        try {
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
 
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
+        addMapping(user, domain, regex, REGEX_TYPE);
+        addMapping(user, domain, regex2, REGEX_TYPE);
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2);
+        assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
+        removeMapping(user, domain, regex, REGEX_TYPE);
 
-            addMapping(user, domain, regex, REGEX_TYPE);
-            addMapping(user, domain, regex2, REGEX_TYPE);
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2);
-            assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
-            removeMapping(user, domain, regex, REGEX_TYPE);
-            
-            try {
-                virtualUserTable.addRegexMapping(user, domain, invalidRegex);
-            } catch (RecipientRewriteTableException e) {
-                catched = true;
-            }
-            
-            assertThat(catched).describedAs("Invalid Mapping throw exception").isTrue();
-            removeMapping(user, domain, regex2, REGEX_TYPE);
+        assertThatThrownBy(() -> virtualUserTable.addRegexMapping(user, domain, invalidRegex))
+            .describedAs("Invalid Mapping throw exception")
+            .isInstanceOf(RecipientRewriteTableException.class);
 
-            
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
-            assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
 
-        } catch (IllegalArgumentException e) {
-            e.printStackTrace();
-            fail("Storing failed");
-        }
+        removeMapping(user, domain, regex2, REGEX_TYPE);
 
+
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
+        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
     }
 
     @Test
@@ -135,17 +122,15 @@ public abstract class AbstractRecipientRewriteTableTest {
         String address = "test@localhost2";
         String address2 = "test@james";
 
-        try {
-
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
 
-            addMapping(user, domain, address, ADDRESS_TYPE);
-            addMapping(user, domain, address2, ADDRESS_TYPE);
+        addMapping(user, domain, address, ADDRESS_TYPE);
+        addMapping(user, domain, address2, ADDRESS_TYPE);
 
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2);
-            assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2);
+        assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
 
-            removeMapping(user, domain, address, ADDRESS_TYPE);
+        removeMapping(user, domain, address, ADDRESS_TYPE);
 
             /*
              * TEMPORARILY REMOVE JDBC specific test String invalidAddress=
@@ -157,94 +142,69 @@ public abstract class AbstractRecipientRewriteTableTest {
              * assertTrue("Invalid Mapping throw exception" , catched); }
              */
 
-            
-            removeMapping(user, domain, address2, ADDRESS_TYPE);
-
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
-            assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
 
-        } catch (IllegalArgumentException e) {
-            fail("Storing failed");
-        }
+        removeMapping(user, domain, address2, ADDRESS_TYPE);
 
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
+        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
     }
 
     @Test
     public void testStoreAndRetrieveErrorMapping() throws ErrorMappingException, RecipientRewriteTableException {
-
         String user = "test";
         String domain = "localhost";
         String error = "bounce!";
-        boolean catched = false;
 
-        try {
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
 
-            addMapping(user, domain, error, ERROR_TYPE);
-            assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
+        addMapping(user, domain, error, ERROR_TYPE);
+        assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1);
 
-            try {
-                virtualUserTable.getMappings(user, domain);
-            } catch (ErrorMappingException e) {
-                catched = true;
-            }
-            assertThat(catched).describedAs("Error Mapping throw exception").isTrue();
+        assertThatThrownBy(() ->
+            virtualUserTable.getMappings(user, domain))
+            .describedAs("Exception thrown on to many mappings")
+            .isInstanceOf(ErrorMappingException.class);
 
-            removeMapping(user, domain, error, ERROR_TYPE);
-
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
-            assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
-        } catch (IllegalArgumentException e) {
-            fail("Storing failed");
-        }
+        removeMapping(user, domain, error, ERROR_TYPE);
 
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
+        assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
     }
 
     @Test
     public void testStoreAndRetrieveWildCardAddressMapping() throws ErrorMappingException, RecipientRewriteTableException {
-
         String user = "test";
         String user2 = "test2";
         String domain = "localhost";
         String address = "test@localhost2";
         String address2 = "test@james";
 
-        try {
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
 
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
+        addMapping(RecipientRewriteTable.WILDCARD, domain, address, ADDRESS_TYPE);
+        addMapping(user, domain, address2, ADDRESS_TYPE);
 
-            addMapping(RecipientRewriteTable.WILDCARD, domain, address, ADDRESS_TYPE);
-            addMapping(user, domain, address2, ADDRESS_TYPE);
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("One mappings").hasSize(1);
+        assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("One mappings").hasSize(1);
 
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("One mappings").hasSize(1);
-            assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("One mappings").hasSize(1);
-
-            removeMapping(user, domain, address2, ADDRESS_TYPE);
-            removeMapping(RecipientRewriteTable.WILDCARD, domain, address, ADDRESS_TYPE);
-            
-            assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
-            assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("No mapping").isNull();
-
-        } catch (IllegalArgumentException e) {
-            fail("Storing failed");
-        }
+        removeMapping(user, domain, address2, ADDRESS_TYPE);
+        removeMapping(RecipientRewriteTable.WILDCARD, domain, address, ADDRESS_TYPE);
 
+        assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping").isNull();
+        assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("No mapping").isNull();
     }
 
     @Test
     public void testRecursiveMapping() throws ErrorMappingException, RecipientRewriteTableException {
-
         String user1 = "user1";
         String user2 = "user2";
         String user3 = "user3";
         String domain1 = "domain1";
         String domain2 = "domain2";
         String domain3 = "domain3";
-        boolean exception1 = false;
 
         virtualUserTable.setRecursiveMapping(true);
 
-        try {
             assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isNull();
 
             addMapping(user1, domain1, user2 + "@" + domain2, ADDRESS_TYPE);
@@ -252,20 +212,14 @@ public abstract class AbstractRecipientRewriteTableTest {
             assertThat(virtualUserTable.getMappings(user1, domain1)).containsOnly(MappingImpl.address(user3 + "@" + domain3));
             addMapping(user3, domain3, user1 + "@" + domain1, ADDRESS_TYPE);
             
-            try {
-                virtualUserTable.getMappings(user1, domain1);
-            } catch (ErrorMappingException e) {
-                exception1 = true;
-            }
-            assertThat(exception1).describedAs("Exception thrown on to many mappings").isTrue();
+            assertThatThrownBy(() ->
+                virtualUserTable.getMappings(user1, domain1))
+                .describedAs("Exception thrown on to many mappings")
+                .isInstanceOf(ErrorMappingException.class);
 
             // disable recursive mapping
             virtualUserTable.setRecursiveMapping(false);
             assertThat(virtualUserTable.getMappings(user1, domain1)).describedAs("Not recursive mapped").containsExactly(MappingImpl.address(user2 + "@" + domain2));
-
-        } catch (IllegalArgumentException e) {
-            fail("Storing failed");
-        }
     }
 
     @Test
@@ -278,23 +232,16 @@ public abstract class AbstractRecipientRewriteTableTest {
 
         assertThat(virtualUserTable.getAllMappings()).describedAs("No mappings").isNull();
 
-        try {
+        addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE);
+        addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, domain, ALIASDOMAIN_TYPE);
 
-            addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE);
-            addMapping(RecipientRewriteTable.WILDCARD, aliasDomain, domain, ALIASDOMAIN_TYPE);
+        assertThat(virtualUserTable.getMappings(user, aliasDomain))
+            .describedAs("Domain mapped as first, Address mapped as second")
+            .containsExactly(MappingImpl.address(user + "@" + domain), MappingImpl.address(user2 + "@" + domain));
 
-            assertThat(virtualUserTable.getMappings(user, aliasDomain))
-                .describedAs("Domain mapped as first, Address mapped as second")
-                .containsExactly(MappingImpl.address(user + "@" + domain), MappingImpl.address(user2 + "@" + domain));
-
-            removeMapping(RecipientRewriteTable.WILDCARD, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE);
-
-            removeMapping(RecipientRewriteTable.WILDCARD, aliasDomain, domain, ALIASDOMAIN_TYPE);
-
-        } catch (IllegalArgumentException e) {
-            fail("Storing failed");
-        }
+        removeMapping(RecipientRewriteTable.WILDCARD, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE);
 
+        removeMapping(RecipientRewriteTable.WILDCARD, aliasDomain, domain, ALIASDOMAIN_TYPE);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/a1340b7c/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
index b27bcb3..5825492 100644
--- a/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
+++ b/server/data/data-library/src/test/java/org/apache/james/rrt/lib/RewriteTablesStepdefs.java
@@ -19,7 +19,7 @@
 package org.apache.james.rrt.lib;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.util.List;
 
@@ -125,13 +125,10 @@ public class RewriteTablesStepdefs {
         assertThat(exception.getClass().getSimpleName()).isEqualTo(exceptionClass);
     }
 
-    @Then("retrieving mappings for user \"([^\"]*)\" at domain \"([^\"]*)\" should raise a \"([^\"]*)\" exception with message \"([^\"]*)\"")
-    public void retrievingMappingsForUserAtDomainShouldRaiseAnException(String user, String domain, String exception, String message) throws Exception {
-        try {
-            rewriteTable.getMappings(user, domain);
-            fail(String.format("Expecting an exception '%s' with message '%s' to be thrown", exception, message));
-        } catch (ErrorMappingException e) {
-            assertThat(e).hasMessage(message);
-        }
+    @Then("retrieving mappings for user \"([^\"]*)\" at domain \"([^\"]*)\" should raise an ErrorMappingException with message \"([^\"]*)\"")
+    public void retrievingMappingsForUserAtDomainShouldRaiseAnException(String user, String domain, String message) throws Exception {
+        assertThatThrownBy(() -> rewriteTable.getMappings(user, domain))
+            .isInstanceOf(ErrorMappingException.class)
+            .hasMessage(message);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/a1340b7c/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature b/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
index dc3458b..5ce3ec8 100644
--- a/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
+++ b/server/data/data-library/src/test/resources/cucumber/rewrite_tables.feature
@@ -57,12 +57,12 @@ Feature: Rewrite Tables tests
 
   Scenario: stored error mapping should be retrieved when one mapping matching
     Given store "bounce!" error mapping for user "test" at domain "localhost"
-    Then retrieving mappings for user "test" at domain "localhost" should raise a "ErrorMappingException" exception with message "bounce!"
+    Then retrieving mappings for user "test" at domain "localhost" should raise an ErrorMappingException with message "bounce!"
 
   Scenario: stored error mapping should be retrieved when two mappings matching
     Given store "bounce!" error mapping for user "test" at domain "localhost"
     And store "error" error mapping for user "test" at domain "localhost"
-    Then retrieving mappings for user "test" at domain "localhost" should raise a "ErrorMappingException" exception with message "bounce!"
+    Then retrieving mappings for user "test" at domain "localhost" should raise an ErrorMappingException with message "bounce!"
 
   Scenario: stored error mapping should not be retrieved by another user
     Given store "bounce!" error mapping for user "test" at domain "localhost"
@@ -77,12 +77,12 @@ Feature: Rewrite Tables tests
   Scenario: an exception should be thrown when an error mapping is not the first stored
     Given store "test@localhost2" address mapping for user "test" at domain "localhost"
     And store "bounce!" error mapping for user "test" at domain "localhost"
-    Then retrieving mappings for user "test" at domain "localhost" should raise a "ErrorMappingException" exception with message "bounce!"
+    Then retrieving mappings for user "test" at domain "localhost" should raise an ErrorMappingException with message "bounce!"
 
   Scenario: an exception should be thrown when an error mapping is the first stored
     Given store "bounce!" error mapping for user "test" at domain "localhost"
     And store "test@localhost2" address mapping for user "test" at domain "localhost"
-    Then retrieving mappings for user "test" at domain "localhost" should raise a "ErrorMappingException" exception with message "bounce!"
+    Then retrieving mappings for user "test" at domain "localhost" should raise an ErrorMappingException with message "bounce!"
 
 # Wildcard mapping
 
@@ -204,7 +204,7 @@ Feature: Rewrite Tables tests
     And store "user2@domain2" address mapping for user "user1" at domain "domain1"
     And store "user3@domain3" address mapping for user "user2" at domain "domain2"
     And store "user1@domain1" address mapping for user "user3" at domain "domain3"
-    Then retrieving mappings for user "user1" at domain "domain1" should raise a "ErrorMappingException" exception with message "554 Too many mappings to process"
+    Then retrieving mappings for user "user1" at domain "domain1" should raise an ErrorMappingException with message "554 Too many mappings to process"
 
   Scenario: recursive mapping should work when a level is removed
     Given recursive mapping is enable


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