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:56 UTC
[2/6] git commit: Use more literate assertions.
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)));
}
}