I think we should add static org.hamcrest.Matchers.* On 3 October 2014 00:46, Remko Popma <[email protected]> wrote:
> Should hamcrest static imports not also be wildcart imports? > > Sent from my iPhone > > > On 2014/10/03, at 12:39, [email protected] wrote: > > > > Use ILC and literate assertions. > > > > > > Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo > > Commit: > http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1ce4c812 > > Tree: > http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1ce4c812 > > Diff: > http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1ce4c812 > > > > Branch: refs/heads/master > > Commit: 1ce4c812d916c73dfc991412dd37fe9d99b02dbf > > Parents: b077943 > > Author: Matt Sicker <[email protected]> > > Authored: Thu Oct 2 22:38:48 2014 -0500 > > Committer: Matt Sicker <[email protected]> > > Committed: Thu Oct 2 22:38:48 2014 -0500 > > > > ---------------------------------------------------------------------- > > .../core/config/xml/XmlLoggerPropsTest.java | 67 ++++++++++---------- > > 1 file changed, 32 insertions(+), 35 deletions(-) > > ---------------------------------------------------------------------- > > > > > > > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1ce4c812/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlLoggerPropsTest.java > > ---------------------------------------------------------------------- > > diff --git > a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlLoggerPropsTest.java > b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlLoggerPropsTest.java > > index a17e06a..2aa0456 100644 > > --- > a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlLoggerPropsTest.java > > +++ > b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/xml/XmlLoggerPropsTest.java > > @@ -18,69 +18,66 @@ package org.apache.logging.log4j.core.config.xml; > > > > import java.util.List; > > > > -import static org.junit.Assert.assertNotNull; > > -import static org.junit.Assert.assertTrue; > > - > > import org.apache.logging.log4j.LogManager; > > import org.apache.logging.log4j.Logger; > > -import org.apache.logging.log4j.core.LoggerContext; > > -import org.apache.logging.log4j.core.config.Configuration; > > -import org.apache.logging.log4j.core.config.ConfigurationFactory; > > -import org.apache.logging.log4j.status.StatusLogger; > > +import org.apache.logging.log4j.junit.InitialLoggerContext; > > import org.apache.logging.log4j.test.appender.ListAppender; > > -import org.junit.AfterClass; > > import org.junit.BeforeClass; > > +import org.junit.Rule; > > import org.junit.Test; > > > > +import static org.hamcrest.Matchers.allOf; > > +import static org.hamcrest.Matchers.both; > > +import static org.hamcrest.Matchers.containsString; > > +import static org.hamcrest.Matchers.equalTo; > > +import static org.hamcrest.Matchers.greaterThan; > > +import static org.hamcrest.Matchers.hasSize; > > +import static org.hamcrest.Matchers.instanceOf; > > +import static org.hamcrest.Matchers.is; > > +import static org.junit.Assert.*; > > + > > /** > > * > > */ > > public class XmlLoggerPropsTest { > > > > private static final String CONFIG = "log4j-loggerprops.xml"; > > - private static Configuration config; > > - private static ListAppender listAppender; > > - private static LoggerContext ctx; > > + > > + @Rule > > + public final InitialLoggerContext context = new > InitialLoggerContext(CONFIG); > > > > @BeforeClass > > public static void setupClass() { > > - > System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, > CONFIG); > > System.setProperty("test", "test"); > > - ctx = (LoggerContext) LogManager.getContext(false); > > - config = ctx.getConfiguration(); > > - listAppender = (ListAppender) config.getAppender("List"); > > - } > > - > > - @AfterClass > > - public static void cleanupClass() { > > - > System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY); > > - ctx.reconfigure(); > > - StatusLogger.getLogger().reset(); > > } > > > > @Test > > public void testWithProps() { > > + final ListAppender listAppender = > context.getListAppender("List"); > > assertNotNull("No List Appender", listAppender); > > > > try { > > - assertTrue("Configuration is not an XmlConfiguration", > config instanceof XmlConfiguration); > > + assertThat(context.getConfiguration(), > is(instanceOf(XmlConfiguration.class))); > > Logger logger = > LogManager.getLogger(XmlLoggerPropsTest.class); > > logger.debug("Test with props"); > > logger = LogManager.getLogger("tiny.bubbles"); > > logger.debug("Test on root"); > > final List<String> events = listAppender.getMessages(); > > - assertTrue("No events", events.size() > 0); > > - assertTrue("Incorrect number of events", events.size() == > 2); > > - assertTrue("Incorrect value", > events.get(0).contains("user=")); > > - assertTrue("Incorrect value", > events.get(0).contains("phrasex=****")); > > - assertTrue("Incorrect value", > events.get(0).contains("test=test")); > > - assertTrue("Incorrect value", > events.get(0).contains("test2=test2default")); > > - assertTrue("Incorrect value", > events.get(0).contains("test3=Unknown")); > > - assertTrue("Incorrect value", > events.get(1).contains("user=")); > > - assertTrue("Incorrect value", > events.get(1).contains("phrasex=****")); > > - assertTrue("Incorrect value", > events.get(1).contains("test=test")); > > - assertTrue("Incorrect value", > events.get(1).contains("test2=test2default")); > > - assertTrue("Incorrect value", > events.get(1).contains("test3=Unknown")); > > + assertThat("Incorrect number of events", events, > both(hasSize(greaterThan(0))).and(hasSize(equalTo(2)))); > > + assertThat(events.get(0), allOf( > > + containsString("user="), > > + containsString("phrasex=****"), > > + containsString("test=test"), > > + containsString("test2=test2default"), > > + containsString("test3=Unknown") > > + )); > > + assertThat(events.get(1), allOf( > > + containsString("user="), > > + containsString("phrasex=****"), > > + containsString("test=test"), > > + containsString("test2=test2default"), > > + containsString("test3=Unknown") > > + )); > > } finally { > > System.clearProperty("test"); > > } > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- Matt Sicker <[email protected]>
