You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/10/03 05:38:55 UTC

[1/6] git commit: Add Hamcrest matchers for Files.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 2419dcc21 -> 1ce4c812d


Add Hamcrest matchers for Files.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c95fd1e3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c95fd1e3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c95fd1e3

Branch: refs/heads/master
Commit: c95fd1e3d50f819111df191258981d31533486b7
Parents: 2419dcc
Author: Matt Sicker <ma...@apache.org>
Authored: Thu Oct 2 21:53:33 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Thu Oct 2 21:53:33 2014 -0500

----------------------------------------------------------------------
 .../logging/log4j/junit/FileMatchers.java       | 58 ++++++++++++++++++++
 1 file changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c95fd1e3/log4j-core/src/test/java/org/apache/logging/log4j/junit/FileMatchers.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/FileMatchers.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/FileMatchers.java
new file mode 100644
index 0000000..1b3e516
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/FileMatchers.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.junit;
+
+import java.io.File;
+
+import org.hamcrest.FeatureMatcher;
+import org.hamcrest.Matcher;
+import org.hamcrest.core.Is;
+
+/**
+ * Hamcrest Matchers that operate on File objects.
+ *
+ * @since 2.1
+ */
+public class FileMatchers {
+
+    /**
+     * Returns a File Matcher that matches if the File exists.
+     */
+    public static Matcher<File> exists() {
+        return new FeatureMatcher<File, Boolean>(Is.is(true), "file exists", "file exists") {
+            @Override
+            protected Boolean featureValueOf(final File actual) {
+                return actual.exists();
+            }
+        };
+    }
+
+    /**
+     * Returns a File Matcher that matches a Long Matcher against the file length.
+     *
+     * @param matcher the Matcher to use on the File length.
+     */
+    public static Matcher<File> hasLength(final Matcher<Long> matcher) {
+        return new FeatureMatcher<File, Long>(matcher, "file with size", "file with size") {
+            @Override
+            protected Long featureValueOf(final File actual) {
+                return actual.length();
+            }
+        };
+    }
+
+}


[2/6] git commit: Use more literate assertions.

Posted by ma...@apache.org.
Use more 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/4f2b3d67
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4f2b3d67
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4f2b3d67

Branch: refs/heads/master
Commit: 4f2b3d671b115fd7b0952a51fa65be6781344289
Parents: c95fd1e
Author: Matt Sicker <ma...@apache.org>
Authored: Thu Oct 2 21:55:29 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Thu Oct 2 21:55:29 2014 -0500

----------------------------------------------------------------------
 .../log4j/core/AppenderRefLevelJsonTest.java      | 18 ++++++------------
 .../logging/log4j/core/ExtendedLevelTest.java     |  5 +++--
 .../apache/logging/log4j/core/HostNameTest.java   |  7 ++++---
 .../core/config/CustomConfigurationTest.java      | 11 +++++++----
 4 files changed, 20 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4f2b3d67/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
index 0694f75..119b179 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/AppenderRefLevelJsonTest.java
@@ -16,8 +16,6 @@
  */
 package org.apache.logging.log4j.core;
 
-import java.util.List;
-
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.junit.InitialLoggerContext;
@@ -26,6 +24,7 @@ import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.hasSize;
 import static org.junit.Assert.*;
 
 /**
@@ -59,10 +58,8 @@ public class AppenderRefLevelJsonTest {
         logger1.info("Info Message");
         logger1.warn("warn Message");
         logger1.exit();
-        List<LogEvent> events = app1.getEvents();
-        assertEquals("Incorrect number of events. Expected 6, actual " + events.size(), 6, events.size());
-        events = app2.getEvents();
-        assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
+        assertThat(app1.getEvents(), hasSize(6));
+        assertThat(app2.getEvents(), hasSize(1));
     }
 
     @Test
@@ -73,10 +70,8 @@ public class AppenderRefLevelJsonTest {
         logger2.info("Info Message");
         logger2.warn("warn Message");
         logger2.exit();
-        List<LogEvent> events = app1.getEvents();
-        assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), 2, events.size());
-        events = app2.getEvents();
-        assertEquals("Incorrect number of events. Expected 4, actual " + events.size(), 4, events.size());
+        assertThat(app1.getEvents(), hasSize(2));
+        assertThat(app2.getEvents(), hasSize(4));
     }
 
     @Test
@@ -87,8 +82,7 @@ public class AppenderRefLevelJsonTest {
         logger3.info(testMarker, "Info Message");
         logger3.warn("warn Message");
         logger3.exit();
-        final List<LogEvent> events = app1.getEvents();
-        assertEquals("Incorrect number of events. Expected 4, actual " + events.size(), 4, events.size());
+        assertThat(app1.getEvents(), hasSize(4));
     }
 }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4f2b3d67/log4j-core/src/test/java/org/apache/logging/log4j/core/ExtendedLevelTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/ExtendedLevelTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/ExtendedLevelTest.java
index ebd7278..4eaba80 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/ExtendedLevelTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/ExtendedLevelTest.java
@@ -26,6 +26,7 @@ import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.hasSize;
 import static org.junit.Assert.*;
 
 /**
@@ -53,7 +54,7 @@ public class ExtendedLevelTest {
         logger.log(Level.DEBUG, "Debug message");
         List<LogEvent> events = list1.getEvents();
         assertNotNull("No events", events);
-        assertEquals("Incorrect number of events. Expected 1 got " + events.size(), 1, events.size());
+        assertThat(events, hasSize(1));
         LogEvent event = events.get(0);
         assertEquals("Expected level DETAIL, got" + event.getLevel(), "DETAIL", event.getLevel().name());
         logger = context.getLogger("org.apache.logging.log4j.test2");
@@ -61,7 +62,7 @@ public class ExtendedLevelTest {
         logger.log(Level.INFO, "Info message");
         events = list2.getEvents();
         assertNotNull("No events", events);
-        assertEquals("Incorrect number of events. Expected 1 got " + events.size(), 1, events.size());
+        assertThat(events, hasSize(1));
         event = events.get(0);
         assertEquals("Expected level NOTE, got" + event.getLevel(), "NOTE", event.getLevel().name());
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4f2b3d67/log4j-core/src/test/java/org/apache/logging/log4j/core/HostNameTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/HostNameTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/HostNameTest.java
index 8377a01..e303da6 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/HostNameTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/HostNameTest.java
@@ -27,6 +27,8 @@ import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
 
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.hasSize;
 import static org.junit.Assert.*;
 
 /**
@@ -52,10 +54,9 @@ public class HostNameTest {
         final org.apache.logging.log4j.Logger testLogger = context.getLogger("org.apache.logging.log4j.hosttest");
         testLogger.debug("Hello, {}", "World");
         final List<String> msgs = host.getMessages();
-        assertEquals("Incorrect number of events. Expected 1, actual " + msgs.size(), 1, msgs.size());
+        assertThat(msgs, hasSize(1));
         String expected = NetUtils.getLocalHostname() + Constants.LINE_SEPARATOR;
-        assertTrue("Incorrect hostname - expected " + expected + " actual - " + msgs.get(0),
-            msgs.get(0).endsWith(expected));
+        assertThat(msgs.get(0), endsWith(expected));
         assertNotNull("No Host FileAppender file name", hostFile.getFileName());
         expected = "target/" + NetUtils.getLocalHostname() + ".log";
         String name = hostFile.getFileName();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4f2b3d67/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
index 410f333..14af83a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/CustomConfigurationTest.java
@@ -36,6 +36,10 @@ import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
 
+import static org.apache.logging.log4j.junit.FileMatchers.exists;
+import static org.apache.logging.log4j.junit.FileMatchers.hasLength;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.instanceOf;
 import static org.junit.Assert.*;
 
 /**
@@ -65,7 +69,7 @@ public class CustomConfigurationTest {
         final LoggerContext ctx = this.init.getContext();
         ctx.reconfigure();
         final Configuration config = ctx.getConfiguration();
-        assertTrue("Configuration is not an XmlConfiguration", config instanceof XmlConfiguration);
+        assertThat(config, instanceOf(XmlConfiguration.class));
         for (final StatusListener listener : StatusLogger.getLogger().getListeners()) {
             if (listener instanceof StatusConsoleListener) {
                 assertSame(listener.getStatusLevel(), Level.INFO);
@@ -91,8 +95,7 @@ public class CustomConfigurationTest {
         final Logger logger = ctx.getLogger(CustomConfigurationTest.class.getName());
         logger.info("This is a test");
         final File file = new File(LOG_FILE);
-        assertTrue("log file not created", file.exists());
-        assertTrue("No data logged", file.length() > 0);
-
+        assertThat(file, exists());
+        assertThat(file, hasLength(greaterThan(0L)));
     }
 }


[3/6] git commit: More custom Hamcrest matchers.

Posted by ma...@apache.org.
More custom Hamcrest matchers.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3f2566dd
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3f2566dd
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3f2566dd

Branch: refs/heads/master
Commit: 3f2566dd2259892deb069b6da7af6c17326703db
Parents: 4f2b3d6
Author: Matt Sicker <ma...@apache.org>
Authored: Thu Oct 2 22:14:17 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Thu Oct 2 22:14:17 2014 -0500

----------------------------------------------------------------------
 .../logging/log4j/junit/FileMatchers.java       | 10 +++-
 .../apache/logging/log4j/junit/MapMatchers.java | 62 ++++++++++++++++++++
 2 files changed, 69 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3f2566dd/log4j-core/src/test/java/org/apache/logging/log4j/junit/FileMatchers.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/FileMatchers.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/FileMatchers.java
index 1b3e516..3207a4a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/junit/FileMatchers.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/FileMatchers.java
@@ -20,20 +20,21 @@ import java.io.File;
 
 import org.hamcrest.FeatureMatcher;
 import org.hamcrest.Matcher;
-import org.hamcrest.core.Is;
+
+import static org.hamcrest.core.Is.is;
 
 /**
  * Hamcrest Matchers that operate on File objects.
  *
  * @since 2.1
  */
-public class FileMatchers {
+public final class FileMatchers {
 
     /**
      * Returns a File Matcher that matches if the File exists.
      */
     public static Matcher<File> exists() {
-        return new FeatureMatcher<File, Boolean>(Is.is(true), "file exists", "file exists") {
+        return new FeatureMatcher<File, Boolean>(is(true), "file exists", "file exists") {
             @Override
             protected Boolean featureValueOf(final File actual) {
                 return actual.exists();
@@ -55,4 +56,7 @@ public class FileMatchers {
         };
     }
 
+    private FileMatchers() {
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3f2566dd/log4j-core/src/test/java/org/apache/logging/log4j/junit/MapMatchers.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/MapMatchers.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/MapMatchers.java
new file mode 100644
index 0000000..7fd19a8
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/MapMatchers.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.junit;
+
+import java.util.Map;
+
+import org.hamcrest.FeatureMatcher;
+import org.hamcrest.Matcher;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+
+/**
+ * Hamcrest Matchers for Maps.
+ *
+ * @since 2.1
+ */
+public final class MapMatchers {
+
+    /**
+     * Returns a Map Matcher matching on the size of a Map.
+     *
+     * @param matcher the Matcher to match against the Map size.
+     * @param <K>     the key type.
+     * @param <V>     the value type.
+     */
+    public static <K, V> Matcher<Map<? extends K, ? extends V>> hasSize(final Matcher<Integer> matcher) {
+        return new FeatureMatcher<Map<? extends K, ? extends V>, Integer>(matcher, "map with size", "map with size") {
+            @Override
+            protected Integer featureValueOf(final Map<? extends K, ? extends V> actual) {
+                return actual.size();
+            }
+        };
+    }
+
+    /**
+     * Returns a Map Matcher matching on the exact size of a Map.
+     *
+     * @param size the number of entries to match the Map against.
+     * @param <K>  the key type.
+     * @param <V>  the value type.
+     */
+    public static <K, V> Matcher<Map<? extends K, ? extends V>> hasSize(final int size) {
+        return hasSize(equalTo(size));
+    }
+
+    private MapMatchers() {
+    }
+}


[4/6] git commit: More literate unit test assertions.

Posted by ma...@apache.org.
More literate unit test 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/53266c96
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/53266c96
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/53266c96

Branch: refs/heads/master
Commit: 53266c96f311c34f3e826c66f2c16c12788c1dc6
Parents: 3f2566d
Author: Matt Sicker <ma...@apache.org>
Authored: Thu Oct 2 22:27:16 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Thu Oct 2 22:27:16 2014 -0500

----------------------------------------------------------------------
 .../log4j/core/config/FileOutputTest.java       |  7 ++-
 .../core/config/MissingRootLoggerTest.java      | 24 +++++---
 .../log4j/core/config/TestConfigurator.java     | 64 ++++++++++----------
 .../logging/log4j/core/config/XIncludeTest.java | 10 ++-
 4 files changed, 59 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/53266c96/log4j-core/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java
index 3357a08..df9383a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/FileOutputTest.java
@@ -24,6 +24,9 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.RuleChain;
 
+import static org.apache.logging.log4j.junit.FileMatchers.exists;
+import static org.apache.logging.log4j.junit.FileMatchers.hasLength;
+import static org.hamcrest.Matchers.greaterThan;
 import static org.junit.Assert.*;
 
 /**
@@ -40,8 +43,8 @@ public class FileOutputTest {
     @Test
     public void testConfig() {
         final File file = new File(STATUS_LOG);
-        assertTrue("Status output file does not exist", file.exists());
-        assertTrue("File is empty", file.length() > 0);
+        assertThat("Status output file does not exist", file, exists());
+        assertThat("File is empty", file, hasLength(greaterThan(0L)));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/53266c96/log4j-core/src/test/java/org/apache/logging/log4j/core/config/MissingRootLoggerTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/MissingRootLoggerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/MissingRootLoggerTest.java
index b87ce72..14067a5 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/MissingRootLoggerTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/MissingRootLoggerTest.java
@@ -28,6 +28,10 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
+import static org.apache.logging.log4j.junit.MapMatchers.hasSize;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.*;
 
 @RunWith(JUnit4.class)
@@ -49,28 +53,28 @@ public class MissingRootLoggerTest {
 //                MISSINGROOT.equals(config.getName()));
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders not null", map);
-        assertEquals("There should only be two appenders", 2, map.size());
-        assertTrue("Contains List", map.containsKey("List"));
-        assertTrue("Contains Console", map.containsKey("Console"));
+        assertThat("There should only be two appenders", map, hasSize(2));
+        assertThat(map, hasKey("List"));
+        assertThat(map, hasKey("Console"));
 
         final Map<String, LoggerConfig> loggerMap = config.getLoggers();
         assertNotNull("loggerMap not null", loggerMap);
-        assertEquals("There should only be one configured logger", 1, loggerMap.size());
+        assertThat("There should only be one configured logger", loggerMap, hasSize(1));
         // only the sample logger, no root logger in loggerMap!
-        assertTrue("contains key=sample", loggerMap.containsKey("sample"));
+        assertThat("contains key=sample", loggerMap, hasKey("sample"));
 
         final LoggerConfig sample = loggerMap.get("sample");
         final Map<String, Appender> sampleAppenders = sample.getAppenders();
-        assertEquals("The sample logger should only have one appender", 1, sampleAppenders.size());
+        assertThat("The sample logger should only have one appender", sampleAppenders, hasSize(1));
         // sample only has List appender, not Console!
-        assertTrue("The sample appender should be a ListAppender", sampleAppenders.containsKey("List"));
-
+        assertThat("The sample appender should be a ListAppender", sampleAppenders, hasKey("List"));
+        assertThat(config, is(instanceOf(AbstractConfiguration.class)));
         final AbstractConfiguration baseConfig = (AbstractConfiguration) config;
         final LoggerConfig root = baseConfig.getRootLogger();
         final Map<String, Appender> rootAppenders = root.getAppenders();
-        assertEquals("The root logger should only have one appender", 1, rootAppenders.size());
+        assertThat("The root logger should only have one appender", rootAppenders, hasSize(1));
         // root only has Console appender!
-        assertTrue("The root appender should be a ConsoleAppender", rootAppenders.containsKey("Console"));
+        assertThat("The root appender should be a ConsoleAppender", rootAppenders, hasKey("Console"));
         assertEquals(Level.ERROR, root.getLevel());
     }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/53266c96/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
index aa97a38..22908ac 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
@@ -36,6 +36,14 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
+import static org.apache.logging.log4j.junit.MapMatchers.hasSize;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.theInstance;
 import static org.junit.Assert.*;
 
 /**
@@ -86,8 +94,8 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        assertTrue("Wrong configuration", map.containsKey("List"));
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
@@ -105,8 +113,8 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        assertTrue("Wrong configuration", map.containsKey("List"));
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
@@ -124,8 +132,8 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        assertTrue("Wrong configuration", map.containsKey("List"));
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
@@ -140,8 +148,8 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        assertTrue("Wrong configuration", map.containsKey("List"));
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
@@ -157,8 +165,8 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        assertTrue("Wrong configuration", map.containsKey("List"));
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
@@ -173,8 +181,8 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        assertTrue("Wrong configuration", map.containsKey("List"));
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertEquals("Incorrect Configuration.", NullConfiguration.NULL_NAME, config.getName());
@@ -189,8 +197,8 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        assertTrue("Wrong configuration", map.containsKey("List"));
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertEquals("Incorrect Configuration.", NullConfiguration.NULL_NAME, config.getName());
@@ -205,8 +213,8 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        assertTrue("Wrong configuration", map.containsKey("List"));
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
@@ -223,8 +231,8 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        assertTrue("Wrong configuration", map.containsKey("List"));
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("Wrong configuration", map, hasKey("List"));
 
         Thread.sleep(500);
         assertTrue("setLastModified should have succeeded.", file.setLastModified(System.currentTimeMillis()));
@@ -233,7 +241,7 @@ public class TestConfigurator {
         }
         Thread.sleep(100);
         final Configuration newConfig = ctx.getConfiguration();
-        assertTrue("Configuration not reset", newConfig != config);
+        assertThat("Configuration not reset", newConfig, is(not(theInstance(config))));
         Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertEquals("Unexpected Configuration.", NullConfiguration.NULL_NAME, config.getName());
@@ -249,18 +257,12 @@ public class TestConfigurator {
         assertEquals("Incorrect Configuration.", CONFIG_NAME, config.getName());
         final Map<String, Appender> map = config.getAppenders();
         assertNotNull("Appenders map should not be null.", map);
-        assertTrue("Appenders map should not be empty.", map.size() > 0);
-        Appender app = null;
-        for (final Map.Entry<String, Appender> entry: map.entrySet()) {
-            if (entry.getKey().equals("List2")) {
-                app = entry.getValue();
-                break;
-            }
-        }
-        assertNotNull("No ListAppender named List2", app);
+        assertThat(map, hasSize(greaterThan(0)));
+        assertThat("No ListAppender named List2", map, hasKey("List2"));
+        Appender app = map.get("List2");
         final Layout<? extends Serializable> layout = app.getLayout();
         assertNotNull("Appender List2 does not have a Layout", layout);
-        assertTrue("Appender List2 is not configured with a PatternLayout", layout instanceof PatternLayout);
+        assertThat("Appender List2 is not configured with a PatternLayout", layout, instanceOf(PatternLayout.class));
         final String pattern = ((PatternLayout) layout).getConversionPattern();
         assertNotNull("No conversion pattern for List2 PatternLayout", pattern);
         assertFalse("Environment variable was not substituted", pattern.startsWith("${env:PATH}"));
@@ -311,7 +313,7 @@ public class TestConfigurator {
         assertNotNull("No Logger", lcfg);
         final Filter filter = lcfg.getFilter();
         assertNotNull("No Filter", filter);
-        assertTrue("Incorrect filter", filter instanceof CompositeFilter);
+        assertThat(filter, instanceOf(CompositeFilter.class));
         assertTrue("Unexpected filters", ((CompositeFilter) filter).isEmpty());
     }
 
@@ -339,7 +341,7 @@ public class TestConfigurator {
         final Configuration config = ctx.getConfiguration();
         assertNotNull("No configuration", config);
         assertEquals("Unexpected Configuration", "XMLConfigTest", config.getName());
-        assertTrue("Create bad appender", config.getAppenders().size() == 2);
+        assertThat(config.getAppenders(), hasSize(equalTo(2)));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/53266c96/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java
index 873a77d..f2c9579 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/XIncludeTest.java
@@ -43,8 +43,12 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
-import static org.hamcrest.CoreMatchers.*;
-
+import static org.apache.logging.log4j.junit.MapMatchers.hasSize;
+import static org.hamcrest.Matchers.endsWith;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
 import static org.junit.Assert.*;
 
 /**
@@ -109,7 +113,7 @@ public class XIncludeTest {
         assertThat(filter, is(instanceOf(ThreadContextMapFilter.class)));
         final Map<String, Appender> appenders = l.getAppenders();
         assertThat(appenders, is(notNullValue()));
-        assertThat(appenders.size(), is(equalTo(1)));
+        assertThat(appenders, hasSize(1));
         final Appender appender = appenders.get(APPENDER_NAME);
         assertThat(appender, is(notNullValue()));
         assertThat(appender.getName(), is(equalTo("STDOUT")));


[5/6] git commit: Remove empty test class.

Posted by ma...@apache.org.
Remove empty test class.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b0779433
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b0779433
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b0779433

Branch: refs/heads/master
Commit: b07794338fb530b475a8880c19b4c97f5ab3cb12
Parents: 53266c9
Author: Matt Sicker <ma...@apache.org>
Authored: Thu Oct 2 22:37:07 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Thu Oct 2 22:37:07 2014 -0500

----------------------------------------------------------------------
 .../log4j/core/config/json/JsonConfigTest.java  | 23 --------------------
 1 file changed, 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b0779433/log4j-core/src/test/java/org/apache/logging/log4j/core/config/json/JsonConfigTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/json/JsonConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/json/JsonConfigTest.java
deleted file mode 100644
index 28f2b73..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/json/JsonConfigTest.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.config.json;
-
-/**
- *
- */
-public class JsonConfigTest {
-}


Re: [6/6] git commit: Use ILC and literate assertions.

Posted by Remko Popma <re...@gmail.com>.
+1 Makes sense to me... 

Sent from my iPhone

> On 2014/10/03, at 15:31, Matt Sicker <bo...@gmail.com> wrote:
> 
> I think we should add static org.hamcrest.Matchers.*
> 
>> On 3 October 2014 00:46, Remko Popma <re...@gmail.com> wrote:
>> Should hamcrest static imports not also be wildcart imports?
>> 
>> Sent from my iPhone
>> 
>> > On 2014/10/03, at 12:39, mattsicker@apache.org 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 <ma...@apache.org>
>> > Authored: Thu Oct 2 22:38:48 2014 -0500
>> > Committer: Matt Sicker <ma...@apache.org>
>> > 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: log4j-dev-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>

Re: [6/6] git commit: Use ILC and literate assertions.

Posted by Matt Sicker <bo...@gmail.com>.
I think we should add static org.hamcrest.Matchers.*

On 3 October 2014 00:46, Remko Popma <re...@gmail.com> wrote:

> Should hamcrest static imports not also be wildcart imports?
>
> Sent from my iPhone
>
> > On 2014/10/03, at 12:39, mattsicker@apache.org 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 <ma...@apache.org>
> > Authored: Thu Oct 2 22:38:48 2014 -0500
> > Committer: Matt Sicker <ma...@apache.org>
> > 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: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
>
>


-- 
Matt Sicker <bo...@gmail.com>

Re: [6/6] git commit: Use ILC and literate assertions.

Posted by Remko Popma <re...@gmail.com>.
Should hamcrest static imports not also be wildcart imports?

Sent from my iPhone

> On 2014/10/03, at 12:39, mattsicker@apache.org 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 <ma...@apache.org>
> Authored: Thu Oct 2 22:38:48 2014 -0500
> Committer: Matt Sicker <ma...@apache.org>
> 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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[6/6] git commit: Use ILC and literate assertions.

Posted by ma...@apache.org.
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 <ma...@apache.org>
Authored: Thu Oct 2 22:38:48 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
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");
         }