JAMES-2085 Use ExpectedException where possible
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5da9d3d4 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5da9d3d4 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5da9d3d4 Branch: refs/heads/master Commit: 5da9d3d40abd20e368aa2d22334910cb95384b6e Parents: 550c1c5 Author: benwa <btell...@linagora.com> Authored: Wed Jul 5 09:37:29 2017 +0700 Committer: benwa <btell...@linagora.com> Committed: Wed Jul 5 17:14:08 2017 +0700 ---------------------------------------------------------------------- .../AbstractStateCompositeProcessorTest.java | 87 ++++++++++---------- 1 file changed, 45 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/5da9d3d4/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java index a654b59..9a36ab9 100644 --- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java +++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/lib/AbstractStateCompositeProcessorTest.java @@ -18,10 +18,15 @@ ****************************************************************/ package org.apache.james.mailetcontainer.lib; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.ByteArrayInputStream; import java.util.Arrays; import java.util.List; + import javax.mail.MessagingException; + import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.DefaultConfigurationBuilder; import org.apache.commons.configuration.HierarchicalConfiguration; @@ -29,66 +34,64 @@ import org.apache.james.core.MailImpl; import org.apache.james.mailetcontainer.api.MailProcessor; import org.apache.james.mailetcontainer.api.mock.MockMailProcessor; import org.apache.mailet.Mail; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public abstract class AbstractStateCompositeProcessorTest { - private static final Logger LOGGER = LoggerFactory.getLogger(AbstractStateCompositeProcessorTest.class); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); @Test public void testChooseRightProcessor() throws Exception { - AbstractStateCompositeProcessor processor = new AbstractStateCompositeProcessor() { - - @Override - protected MailProcessor createMailProcessor(final String state, HierarchicalConfiguration config) throws - Exception { - return new MockMailProcessor("") { + AbstractStateCompositeProcessor processor = new AbstractStateCompositeProcessor() { @Override - public void service(Mail mail) throws MessagingException { - // check if the right processor was selected depending on the state - assertEquals(state, mail.getState()); - super.service(mail); + protected MailProcessor createMailProcessor(final String state, HierarchicalConfiguration config) throws + Exception { + return new MockMailProcessor("") { + + @Override + public void service(Mail mail) throws MessagingException { + // check if the right processor was selected depending on the state + assertEquals(state, mail.getState()); + super.service(mail); + } + }; } }; - } - }; - Logger log = LoggerFactory.getLogger("MockLog"); - // slf4j can't set programmatically any log level. It's just a facade - // log.setLevel(SimpleLog.LOG_LEVEL_DEBUG); - processor.setLog(log); - processor.configure(createConfig(Arrays.asList("root", "error", "test"))); - processor.init(); + Logger log = LoggerFactory.getLogger("MockLog"); + // slf4j can't set programmatically any log level. It's just a facade + // log.setLevel(SimpleLog.LOG_LEVEL_DEBUG); + processor.setLog(log); + processor.configure(createConfig(Arrays.asList("root", "error", "test"))); + processor.init(); - try { - Mail mail1 = new MailImpl(); - mail1.setState(Mail.DEFAULT); - Mail mail2 = new MailImpl(); - mail2.setState(Mail.ERROR); + try { + Mail mail1 = new MailImpl(); + mail1.setState(Mail.DEFAULT); + Mail mail2 = new MailImpl(); + mail2.setState(Mail.ERROR); - Mail mail3 = new MailImpl(); - mail3.setState("test"); + Mail mail3 = new MailImpl(); + mail3.setState("test"); - Mail mail4 = new MailImpl(); - mail4.setState("invalid"); + Mail mail4 = new MailImpl(); + mail4.setState("invalid"); - processor.service(mail1); - processor.service(mail2); - processor.service(mail3); + processor.service(mail1); + processor.service(mail2); + processor.service(mail3); - try { - processor.service(mail4); - fail("should fail because of no mapping to a processor for this state"); - } catch (MessagingException e) { - LOGGER.info("Ignored error", e); - } + expectedException.expect(MessagingException.class); - } finally { - processor.dispose(); - } + processor.service(mail4); + } finally { + processor.dispose(); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org