From b77def4371a4d0768389c6ff1cf983a1ed470d9c Mon Sep 17 00:00:00 2001 From: Kenneth McFarland Date: Mon, 31 Jul 2017 20:12:33 -0700 Subject: [PATCH 1/4] Cleanup of deprecated methods, warnings and use of try-with-resource to remove resource leaks. --- .../log4j/core/LoggerSerializationTest.java | 3 +- .../apache/logging/log4j/core/LoggerTest.java | 3 +- .../log4j/core/StrictXmlConfigTest.java | 2 +- .../log4j/core/appender/HangingAppender.java | 4 + .../log4j/core/appender/HttpAppenderTest.java | 1 - .../appender/RandomAccessFileManagerTest.java | 75 +++++++++---------- .../log4j/core/appender/SmtpAppenderTest.java | 10 ++- 7 files changed, 53 insertions(+), 45 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerSerializationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerSerializationTest.java index 2637de537aa..74e39cd45a5 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerSerializationTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerSerializationTest.java @@ -26,7 +26,8 @@ public class LoggerSerializationTest extends AbstractSerializationTest { - @Parameters + @SuppressWarnings("resource") + @Parameters public static Collection data() { return Arrays.asList(new Object[][] { { new LoggerContext("").getLogger("", null) }, diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java index ba213ff5654..7bac967c165 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java @@ -103,7 +103,8 @@ public void simpleFlow() { assertEventCount(events, 2); } - @Test + @SuppressWarnings("deprecation") + @Test public void simpleFlowDepreacted() { logger.entry(CONFIG); logger.exit(0); diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java index c9af2c97733..3f8ff056619 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java @@ -69,7 +69,7 @@ public void basicFlowDeprecated() { @Test public void simpleFlow() { logger.entry(CONFIG); - logger.exit(0); + logger.traceExit(0); final List events = app.getEvents(); assertEquals("Incorrect number of events. Expected 2, actual " + events.size(), 2, events.size()); } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java index 1c7b2375863..e4ebfc6dc2d 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java @@ -90,4 +90,8 @@ public boolean stop(final long timeout, final TimeUnit timeUnit) { setStopped(); return true; } + + public static long getSerialversionuid() { + return serialVersionUID; + } } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java index 1e145f06f18..9351bde158d 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HttpAppenderTest.java @@ -30,7 +30,6 @@ import org.apache.logging.log4j.status.StatusData; import org.apache.logging.log4j.status.StatusListener; import org.apache.logging.log4j.status.StatusLogger; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java index fac31717bc2..7dc7352090e 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileManagerTest.java @@ -16,6 +16,9 @@ */ package org.apache.logging.log4j.core.appender; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -27,8 +30,6 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static org.junit.Assert.*; - /** * Tests the RandomAccessFileManager class. */ @@ -45,18 +46,18 @@ public class RandomAccessFileManagerTest { @Test public void testWrite_multiplesOfBufferSize() throws IOException { final File file = folder.newFile(); - try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { + try (final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStream os = NullOutputStream.getInstance(); final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), - os, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true); - + os, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true)) { final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3; final byte[] data = new byte[size]; manager.write(data); // no buffer overflow exception - + manager.flush(); // ensure data is written // all data is written if exceeds buffer size assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3, raf.length()); - }} + } + } /** * Test method for @@ -66,74 +67,72 @@ public void testWrite_multiplesOfBufferSize() throws IOException { @Test public void testWrite_dataExceedingBufferSize() throws IOException { final File file = folder.newFile(); - try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { + try (final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStream os = NullOutputStream.getInstance(); final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), - os, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true); - + os, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, true)) { final int size = RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1; final byte[] data = new byte[size]; manager.write(data); // no exception // all data is written if exceeds buffer size assertEquals(RandomAccessFileManager.DEFAULT_BUFFER_SIZE * 3 + 1, raf.length()); - + // ensure data is written manager.flush(); - assertEquals(size, raf.length()); // all data written to file now - }} + assertEquals(size, raf.length()); // assert that all data was written to file + } + } @Test public void testConfigurableBufferSize() throws IOException { final File file = folder.newFile(); - try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { + final int bufferSize = 4096; + + try (final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStream os = NullOutputStream.getInstance(); - final int bufferSize = 4 * 1024; + final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), + os, bufferSize, null, null, true)) { assertNotEquals(bufferSize, RandomAccessFileManager.DEFAULT_BUFFER_SIZE); - - final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), - os, bufferSize, null, null, true); - // check the resulting buffer size is what was requested assertEquals(bufferSize, manager.getBufferSize()); - }} - + } + } + @Test public void testWrite_dataExceedingMinBufferSize() throws IOException { final File file = folder.newFile(); - try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { + final int bufferSize = 1; + try (final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStream os = NullOutputStream.getInstance(); - final int bufferSize = 1; final RandomAccessFileManager manager = new RandomAccessFileManager(null, raf, file.getName(), - os, bufferSize, null, null, true); - + os, bufferSize, null, null, true)) { final int size = bufferSize * 3 + 1; final byte[] data = new byte[size]; manager.write(data); // no exception // all data is written if exceeds buffer size - assertEquals(bufferSize * 3 + 1, raf.length()); - + assertEquals(size, raf.length()); manager.flush(); assertEquals(size, raf.length()); // all data written to file now - }} - + } + } + @Test public void testAppendDoesNotOverwriteExistingFile() throws IOException { final boolean isAppend = true; final File file = folder.newFile(); + final byte[] bytes = new byte[4096]; + final int expected = bytes.length * 2; assertEquals(0, file.length()); - - final byte[] bytes = new byte[4 * 1024]; - // create existing file try (FileOutputStream fos = new FileOutputStream(file)) { fos.write(bytes, 0, bytes.length); fos.flush(); } assertEquals("all flushed to disk", bytes.length, file.length()); - - final RandomAccessFileManager manager = RandomAccessFileManager.getFileManager( - file.getAbsolutePath(), isAppend, true, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, null); - manager.write(bytes, 0, bytes.length, true); - final int expected = bytes.length * 2; - assertEquals("appended, not overwritten", expected, file.length()); + try(final RandomAccessFileManager manager = RandomAccessFileManager.getFileManager( + file.getAbsolutePath(), isAppend, true, RandomAccessFileManager.DEFAULT_BUFFER_SIZE, null, null, null)) { + manager.write(bytes, 0, bytes.length, true); + + assertEquals("appended, not overwritten", expected, file.length()); + } } } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SmtpAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SmtpAppenderTest.java index 8425d18bbdb..e83263387fe 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SmtpAppenderTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SmtpAppenderTest.java @@ -16,7 +16,14 @@ */ package org.apache.logging.log4j.core.appender; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.Iterator; + import javax.mail.Address; import javax.mail.Message; import javax.mail.MessagingException; @@ -30,13 +37,10 @@ import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.LoggerContext; import org.apache.logging.log4j.core.net.MimeMessageBuilder; -import org.apache.logging.log4j.core.util.CyclicBuffer; import org.apache.logging.log4j.test.AvailablePortFinder; import org.junit.Test; import org.junit.experimental.categories.Category; -import static org.junit.Assert.*; - @Category(Appenders.Smtp.class) public class SmtpAppenderTest { From fb37955837b84aefe70a7c532a3d00835e5f6622 Mon Sep 17 00:00:00 2001 From: Kenneth Date: Wed, 2 Aug 2017 09:19:06 -0700 Subject: [PATCH 2/4] remove getSerrialIdVersion() and add suppress warnings instead --- .../logging/log4j/core/appender/HangingAppender.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java index e4ebfc6dc2d..d82da9cd3f8 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java @@ -33,7 +33,8 @@ @Plugin(name = "Hanging", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true) public class HangingAppender extends AbstractAppender { - private static final long serialVersionUID = 1L; + @SuppressWarnings("unused") + private static final long serialVersionUID = 1L; private final long delay; private final long startupDelay; @@ -90,8 +91,4 @@ public boolean stop(final long timeout, final TimeUnit timeUnit) { setStopped(); return true; } - - public static long getSerialversionuid() { - return serialVersionUID; - } } From 5529267cfc9f6672fb1373083572e155286ae1b7 Mon Sep 17 00:00:00 2001 From: Kenneth Date: Wed, 2 Aug 2017 16:54:56 -0700 Subject: [PATCH 3/4] Simple formatting changes, mostly seperation of import statements --- .../test/java/org/apache/logging/log4j/LogRolloverTest.java | 2 +- .../java/org/apache/logging/log4j/LogbackSubstitution.java | 1 + .../test/java/org/apache/logging/log4j/MarkerMixInTest.java | 2 ++ .../java/org/apache/logging/log4j/MarkerMixInXmlTest.java | 1 + .../java/org/apache/logging/log4j/MarkerMixInYamlTest.java | 1 + .../apache/logging/log4j/core/net/SocketReconnectTest.java | 6 ++++-- .../java/org/apache/logging/log4j/core/net/SocketTest.java | 4 ++-- 7 files changed, 12 insertions(+), 5 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java index f1739dd36c4..b3ef4a6da98 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java @@ -33,7 +33,7 @@ public static void main(final String[] args) throws Exception { try (final LoggerContext ctx = Configurator.initialize("LogTest", LogRolloverTest.class.getClassLoader(), file.toURI())) { final Logger logger = LogManager.getLogger("TestLogger"); - + // whats up with this loop?? for (long i = 0;; i += 1) { logger.debug("Sequence: " + i); Thread.sleep(250); diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/LogbackSubstitution.java b/log4j-core/src/test/java/org/apache/logging/log4j/LogbackSubstitution.java index 4f46efd045d..0bd4d8b499a 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/LogbackSubstitution.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/LogbackSubstitution.java @@ -19,6 +19,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; + import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInTest.java index d8bbae8088f..a5616d474c3 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInTest.java @@ -22,7 +22,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.ObjectWriter; + import org.apache.logging.log4j.MarkerManager.Log4jMarker; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInXmlTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInXmlTest.java index 963d3f6d068..726c017df1c 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInXmlTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInXmlTest.java @@ -21,6 +21,7 @@ import org.apache.logging.log4j.core.jackson.Log4jXmlObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper; + import org.junit.experimental.categories.Category; @Category(Layouts.Xml.class) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInYamlTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInYamlTest.java index 2d14b6b308f..18fb04d24b0 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInYamlTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/MarkerMixInYamlTest.java @@ -21,6 +21,7 @@ import org.apache.logging.log4j.core.jackson.Log4jYamlObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper; + import org.junit.experimental.categories.Category; @Category(Layouts.Yaml.class) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java index 151d4442e7b..967b569e9df 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketReconnectTest.java @@ -16,6 +16,10 @@ */ package org.apache.logging.log4j.core.net; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.ServerSocket; @@ -32,8 +36,6 @@ import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; - @Ignore("Currently needs better port choosing support") public class SocketReconnectTest { private static final int SOCKET_PORT = AvailablePortFinder.getNextAvailable(); diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java index bcc207c55bb..d13f0df5809 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/net/SocketTest.java @@ -16,6 +16,8 @@ */ package org.apache.logging.log4j.core.net; +import static org.junit.Assert.fail; + import java.io.IOException; import java.io.InputStream; import java.net.ServerSocket; @@ -30,8 +32,6 @@ import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; - @Ignore("Currently needs better port choosing support") public class SocketTest { private static final int SOCKET_PORT = AvailablePortFinder.getNextAvailable(); From a9f45ec0be43e02bbd1f932c7d9ce2a50e19898c Mon Sep 17 00:00:00 2001 From: Kenneth Date: Wed, 2 Aug 2017 20:00:40 -0700 Subject: [PATCH 4/4] Fix up import wildcards, introduce consistent spacing and make other somewhat minor changes to clean things up. --- .../log4j/FormatterLoggerManualExample.java | 2 +- .../apache/logging/log4j/LogRolloverTest.java | 6 +-- .../logging/log4j/core/Log4j1222Test.java | 7 ++- .../log4j/core/LogEventFactoryTest.java | 2 +- .../logging/log4j/core/LogEventTest.java | 46 +++++++++---------- .../logging/log4j/core/LoggerDateTest.java | 4 +- .../apache/logging/log4j/core/LoggerTest.java | 4 +- .../logging/log4j/core/LoggerUpdateTest.java | 2 +- .../apache/logging/log4j/core/LookupTest.java | 5 +- .../log4j/core/PatternSelectorTest.java | 6 ++- .../log4j/core/PropertiesFileConfigTest.java | 2 +- .../log4j/core/ShutdownDisabledTest.java | 9 ++-- .../ShutdownTimeoutConfigurationTest.java | 7 +-- .../log4j/core/StrictXmlConfigTest.java | 4 +- .../log4j/core/TimestampMessageTest.java | 6 ++- .../src/test/resources/rollover-test.xml | 4 +- 16 files changed, 63 insertions(+), 53 deletions(-) diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java b/log4j-core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java index d5a14389d98..a6fb48b89fa 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/FormatterLoggerManualExample.java @@ -34,7 +34,7 @@ String getName() { } } - public static Logger logger = LogManager.getFormatterLogger("Foo"); + public static final Logger logger = LogManager.getFormatterLogger("Foo"); /** * @param args diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java index b3ef4a6da98..eb5fa8395c5 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/LogRolloverTest.java @@ -25,7 +25,7 @@ * */ public class LogRolloverTest { - + private static final String CONFIG = "src/test/resources/rollover-test.xml"; public static void main(final String[] args) throws Exception { @@ -33,8 +33,8 @@ public static void main(final String[] args) throws Exception { try (final LoggerContext ctx = Configurator.initialize("LogTest", LogRolloverTest.class.getClassLoader(), file.toURI())) { final Logger logger = LogManager.getLogger("TestLogger"); - // whats up with this loop?? - for (long i = 0;; i += 1) { + + for (long i = 0; ; i++) { logger.debug("Sequence: " + i); Thread.sleep(250); } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/Log4j1222Test.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/Log4j1222Test.java index 1e3f5d56112..4ae64cbaf7a 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/Log4j1222Test.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/Log4j1222Test.java @@ -55,8 +55,11 @@ private void trigger() { if (((TestLogger) Holder.LOGGER).getEntries().size() == 0) { System.out.println("Logger contains no messages"); } - for (final String msg : ((TestLogger) Holder.LOGGER).getEntries()) { - System.out.println(msg); + // use else to avoid entering a for loop if we already know the message entries are empty + else { + for (final String msg : ((TestLogger) Holder.LOGGER).getEntries()) { + System.out.println(msg); + } } } } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventFactoryTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventFactoryTest.java index d2e971c42ba..461e2d28c62 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventFactoryTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventFactoryTest.java @@ -52,7 +52,7 @@ public class LogEventFactoryTest { private ListAppender app; - // this would look so cool using lambdas + // consider using lambdas @ClassRule public static RuleChain chain = RuleChain.outerRule(new TestRule() { @Override diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java index 8a02d5302d1..fa583b306c2 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LogEventTest.java @@ -37,7 +37,7 @@ */ public class LogEventTest { - private static Message MESSAGE = new SimpleMessage("This is a test"); + private static Message MESSAGE = new SimpleMessage("This is a test message"); private static TestClass TESTER = new TestClass(); @Test @@ -84,7 +84,7 @@ public void testNanoTimeIsNotSerialized1() throws Exception { .setLoggerFqcn("org.apache.logging.log4j.core.Logger") // .setLevel(Level.INFO) // .setMessage(new SimpleMessage("Hello, world!")) // - .setThreadName("this must be initialized or the test fails") // + .setThreadName("this must be initialized or the test will fail") // .setNanoTime(12345678L) // .build(); final LogEvent copy = new Log4jLogEvent.Builder(event1).build(); @@ -99,20 +99,20 @@ public void testNanoTimeIsNotSerialized1() throws Exception { final LogEvent actual = (LogEvent) ois.readObject(); assertNotEquals("Different event: nanoTime", copy, actual); assertNotEquals("Different nanoTime", copy.getNanoTime(), actual.getNanoTime()); - assertEquals("deserialized nanoTime is zero", 0, actual.getNanoTime()); + assertEquals("Deserialized nanoTime is zero", 0, actual.getNanoTime()); } @Test public void testNanoTimeIsNotSerialized2() throws Exception { - final LogEvent event1 = Log4jLogEvent.newBuilder() // - .setLoggerName(this.getClass().getName()) // - .setLoggerFqcn("org.apache.logging.log4j.core.Logger") // - .setLevel(Level.INFO) // - .setMessage(new SimpleMessage("Hello, world!")) // + final LogEvent event1 = Log4jLogEvent.newBuilder() + .setLoggerName(this.getClass().getName()) + .setLoggerFqcn("org.apache.logging.log4j.core.Logger") + .setLevel(Level.INFO) + .setMessage(new SimpleMessage("Hello, world!")) .setThreadId(1) // this must be initialized or the test fails - .setThreadName("this must be initialized or the test fails") // + .setThreadName("this must be initialized or the test fails") .setThreadPriority(2) // this must be initialized or the test fails - .setNanoTime(0) // + .setNanoTime(0) .build(); final LogEvent event2 = new Log4jLogEvent.Builder(event1).build(); @@ -130,23 +130,23 @@ public void testNanoTimeIsNotSerialized2() throws Exception { @Test @Ignore public void testEquals() { - final LogEvent event1 = Log4jLogEvent.newBuilder() // - .setLoggerName(this.getClass().getName()) // - .setLoggerFqcn("org.apache.logging.log4j.core.Logger") // - .setLevel(Level.INFO) // - .setMessage(new SimpleMessage("Hello, world!")) // + final LogEvent event1 = Log4jLogEvent.newBuilder() + .setLoggerName(this.getClass().getName()) + .setLoggerFqcn("org.apache.logging.log4j.core.Logger") + .setLevel(Level.INFO) + .setMessage(new SimpleMessage("Hello, world!")) .build(); - final LogEvent event2 = Log4jLogEvent.newBuilder() // - .setLoggerName(this.getClass().getName()) // - .setLoggerFqcn("org.apache.logging.log4j.core.Logger") // + final LogEvent event2 = Log4jLogEvent.newBuilder() + .setLoggerName(this.getClass().getName()) + .setLoggerFqcn("org.apache.logging.log4j.core.Logger") .setLevel(Level.INFO) // - .setMessage(new SimpleMessage("Hello, world!")) // + .setMessage(new SimpleMessage("Hello, world!")) .build(); - final LogEvent event3 = Log4jLogEvent.newBuilder() // - .setLoggerName(this.getClass().getName()) // - .setLoggerFqcn("org.apache.logging.log4j.core.Logger") // + final LogEvent event3 = Log4jLogEvent.newBuilder() + .setLoggerName(this.getClass().getName()) + .setLoggerFqcn("org.apache.logging.log4j.core.Logger") .setLevel(Level.INFO) // - .setMessage(new SimpleMessage("Hello, world!")) // + .setMessage(new SimpleMessage("Hello, world!")) .build(); assertNotEquals("Events should not be equal", event1, event2); assertEquals("Events should be equal", event2, event3); diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerDateTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerDateTest.java index a6a5ca26f34..51b7b44bd48 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerDateTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerDateTest.java @@ -16,6 +16,8 @@ */ package org.apache.logging.log4j.core; +import static org.junit.Assert.assertTrue; + import java.util.Calendar; import org.apache.logging.log4j.core.appender.FileAppender; @@ -24,8 +26,6 @@ import org.junit.ClassRule; import org.junit.Test; -import static org.junit.Assert.*; - /** * */ diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java index 7bac967c165..0caa3b5df3e 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java @@ -152,7 +152,7 @@ public void debugChangeLevel() { @Test public void debugChangeLevelAllChildrenLoggers() { - // Use logger AND child loggers + // Use logger and child loggers logger.debug("Debug message 1"); loggerChild.debug("Debug message 1 child"); loggerGrandchild.debug("Debug message 1 grandchild"); @@ -172,7 +172,7 @@ public void debugChangeLevelAllChildrenLoggers() { @Test public void debugChangeLevelChildLogger() { - // Use logger AND child loggers + // Use logger and child loggers logger.debug("Debug message 1"); loggerChild.debug("Debug message 1 child"); loggerGrandchild.debug("Debug message 1 grandchild"); diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java index 572e392cc3e..a97b58cae26 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerUpdateTest.java @@ -58,7 +58,7 @@ public void resetLevel() { final Configuration config = ctx.getConfiguration(); final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME); /* You could also specify the actual logger name as below and it will return the LoggerConfig used by the Logger. - LoggerConfig loggerConfig = getLoggerConfig("com.apache.test"); + eg: LoggerConfig loggerConfig = getLoggerConfig("com.apache.test"); */ loggerConfig.setLevel(Level.DEBUG); ctx.updateLoggers(); // This causes all Loggers to refetch information from their LoggerConfig. diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/LookupTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/LookupTest.java index 42c7f3c727b..da9bc9699d3 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/LookupTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/LookupTest.java @@ -16,14 +16,15 @@ */ package org.apache.logging.log4j.core; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import org.apache.logging.log4j.core.appender.ConsoleAppender; import org.apache.logging.log4j.core.layout.PatternLayout; import org.apache.logging.log4j.junit.LoggerContextRule; import org.junit.ClassRule; import org.junit.Test; -import static org.junit.Assert.*; - /** * */ diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java index c1df3f8158b..0214bb11656 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java @@ -16,6 +16,10 @@ */ package org.apache.logging.log4j.core; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.util.List; import org.apache.logging.log4j.LogManager; @@ -24,8 +28,6 @@ import org.apache.logging.log4j.util.Strings; import org.junit.ClassRule; import org.junit.Test; - -import static org.junit.Assert.*; /** * */ diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java index 389c095a4cf..5347f076f15 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java @@ -63,7 +63,7 @@ public void testReconfiguration() throws Exception { Thread.sleep(100); newConfig = context.getConfiguration(); } while (newConfig == oldConfig && loopCount < 5); - assertNotSame("Reconfiguration failed", newConfig, oldConfig); + assertNotSame("Reconfiguration failed.", newConfig, oldConfig); } } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java index 5fcecd44762..3dcf888b929 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/ShutdownDisabledTest.java @@ -16,13 +16,14 @@ */ package org.apache.logging.log4j.core; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.junit.LoggerContextRule; import org.junit.ClassRule; import org.junit.Test; -import static org.junit.Assert.*; - /** * */ @@ -36,8 +37,8 @@ public class ShutdownDisabledTest { @Test public void testShutdownFlag() { final Configuration config = context.getConfiguration(); - assertNotNull("No configuration", config); - assertFalse("Shutdown hook is enabled", config.isShutdownHookEnabled()); + assertNotNull("No configuration.", config); + assertFalse("Shutdown hook is enabled.", config.isShutdownHookEnabled()); } } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/ShutdownTimeoutConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/ShutdownTimeoutConfigurationTest.java index 5e0734c75e1..534d92250b3 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/ShutdownTimeoutConfigurationTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/ShutdownTimeoutConfigurationTest.java @@ -16,13 +16,14 @@ */ package org.apache.logging.log4j.core; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.junit.LoggerContextRule; import org.junit.ClassRule; import org.junit.Test; -import static org.junit.Assert.*; - /** * */ @@ -36,7 +37,7 @@ public class ShutdownTimeoutConfigurationTest { @Test public void testShutdownFlag() { final Configuration config = context.getConfiguration(); - assertNotNull("No configuration", config); + assertNotNull("No configuration.", config); assertEquals(5000, config.getShutdownTimeoutMillis()); } diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java index 3f8ff056619..81ccbecad05 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/StrictXmlConfigTest.java @@ -16,6 +16,8 @@ */ package org.apache.logging.log4j.core; +import static org.junit.Assert.assertEquals; + import java.util.Date; import java.util.List; import java.util.Locale; @@ -30,8 +32,6 @@ import org.junit.ClassRule; import org.junit.Test; -import static org.junit.Assert.*; - /** * */ diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java index 60d643b2a31..4e346bc112a 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/TimestampMessageTest.java @@ -16,6 +16,9 @@ */ package org.apache.logging.log4j.core; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.util.List; import org.apache.logging.log4j.Logger; @@ -29,14 +32,13 @@ import org.apache.logging.log4j.message.TimestampMessage; import org.apache.logging.log4j.test.appender.ListAppender; import org.apache.logging.log4j.util.Strings; + import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; -import static org.junit.Assert.*; - /** * Confirms that if you log a {@link TimestampMessage} then there are no unnecessary calls to {@link Clock}. *

diff --git a/log4j-core/src/test/resources/rollover-test.xml b/log4j-core/src/test/resources/rollover-test.xml index 809239fc540..320e3b55988 100644 --- a/log4j-core/src/test/resources/rollover-test.xml +++ b/log4j-core/src/test/resources/rollover-test.xml @@ -4,7 +4,7 @@ - + @@ -15,4 +15,4 @@ - \ No newline at end of file +