http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java ---------------------------------------------------------------------- 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 7a2e01e..ba213ff 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 @@ -191,7 +191,7 @@ public class LoggerTest { @Test public void debugChangeLevelsChildLoggers() { - org.apache.logging.log4j.Logger loggerChild = context.getLogger(logger.getName() + ".child"); + final org.apache.logging.log4j.Logger loggerChild = context.getLogger(logger.getName() + ".child"); // Use logger AND loggerChild logger.debug("Debug message 1"); loggerChild.debug("Debug message 1 child"); @@ -213,7 +213,7 @@ public class LoggerTest { logger.debug("Debug message 1"); final List<LogEvent> events = app.getEvents(); assertEventCount(events, 1); - Map<String, Level> map = new HashMap<>(); + final Map<String, Level> map = new HashMap<>(); map.put(logger.getName(), Level.OFF); Configurator.setLevel(map); logger.debug("Debug message 2"); @@ -231,7 +231,7 @@ public class LoggerTest { loggerGrandchild.debug("Debug message 1 GC"); final List<LogEvent> events = app.getEvents(); assertEventCount(events, 3); - Map<String, Level> map = new HashMap<>(); + final Map<String, Level> map = new HashMap<>(); map.put(logger.getName(), Level.OFF); map.put(loggerChild.getName(), Level.DEBUG); map.put(loggerGrandchild.getName(), Level.WARN); @@ -413,13 +413,13 @@ public class LoggerTest { @Test public void paramWithExceptionTest() throws Exception { logger.error("Throwing with parameters {}", "TestParam", new NullPointerException("Test Exception")); - List<LogEvent> events = app.getEvents(); + final List<LogEvent> events = app.getEvents(); assertNotNull("Log event list not returned", events); assertTrue("Incorrect number of log events: expected 1, actual " + events.size(), events.size() == 1); - LogEvent event = events.get(0); - Throwable thrown = event.getThrown(); + final LogEvent event = events.get(0); + final Throwable thrown = event.getThrown(); assertNotNull("No throwable present in log event", thrown); - Message msg = event.getMessage(); + final Message msg = event.getMessage(); assertTrue("Incorrect message type. Expected ParameterizedMessage/ReusableParameterizedMessage, actual " + msg.getClass().getSimpleName(), msg instanceof ParameterizedMessage || msg instanceof ReusableParameterizedMessage);
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/PatternSelectorTest.java ---------------------------------------------------------------------- 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 1214e4e..572ce4c 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 @@ -39,13 +39,13 @@ public class PatternSelectorTest { @Test public void testMarkerPatternSelector() throws Exception { - org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestMarkerPatternSelector"); + final org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestMarkerPatternSelector"); logger.traceEntry(); logger.info("Hello World"); logger.traceExit(); final ListAppender app = (ListAppender) context.getRequiredAppender("List"); assertNotNull("No ListAppender", app); - List<String> messages = app.getMessages(); + final List<String> messages = app.getMessages(); assertNotNull("No Messages", messages); assertTrue("Incorrect number of messages. Expected 3, Actual " + messages.size() + ": " + messages, messages.size() == 3); final String expect = String.format("[TRACE] TestMarkerPatternSelector ====== " @@ -57,15 +57,15 @@ public class PatternSelectorTest { @Test public void testScriptPatternSelector() throws Exception { - org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestScriptPatternSelector"); - org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("NoLocation"); + final org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestScriptPatternSelector"); + final org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("NoLocation"); logger.traceEntry(); logger.info("Hello World"); logger2.info("No location information"); logger.traceExit(); final ListAppender app = (ListAppender) context.getRequiredAppender("List2"); assertNotNull("No ListAppender", app); - List<String> messages = app.getMessages(); + final List<String> messages = app.getMessages(); assertNotNull("No Messages", messages); assertTrue("Incorrect number of messages. Expected 4, Actual " + messages.size() + ": " + messages, messages.size() == 4); String expect = "[TRACE] TestScriptPatternSelector ====== " + @@ -80,15 +80,15 @@ public class PatternSelectorTest { @Test public void testJavaScriptPatternSelector() throws Exception { - org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestJavaScriptPatternSelector"); - org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("JavascriptNoLocation"); + final org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestJavaScriptPatternSelector"); + final org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("JavascriptNoLocation"); logger.traceEntry(); logger.info("Hello World"); logger2.info("No location information"); logger.traceExit(); final ListAppender app = (ListAppender) context.getRequiredAppender("List3"); assertNotNull("No ListAppender", app); - List<String> messages = app.getMessages(); + final List<String> messages = app.getMessages(); assertNotNull("No Messages", messages); assertTrue("Incorrect number of messages. Expected 4, Actual " + messages.size() + ": " + messages, messages.size() == 4); String expect = "[TRACE] TestJavaScriptPatternSelector ====== " + http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/PropertiesFileConfigTest.java ---------------------------------------------------------------------- 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 d943c5e..389c095 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 @@ -57,7 +57,7 @@ public class PropertiesFileConfigTest { for (int i = 0; i < 17; ++i) { logger.debug("Reconfigure"); } - int loopCount = 0; + final int loopCount = 0; Configuration newConfig; do { Thread.sleep(100); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java index c64e7a0..b271d70 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderQueueFullPolicyTest.java @@ -84,12 +84,12 @@ public class AsyncAppenderQueueFullPolicyTest { assertEquals("queue remaining capacity", 0, asyncAppender.getQueueRemainingCapacity()); assertEquals("EventRouter invocations", 0, CountingAsyncQueueFullPolicy.queueFull.get()); - Thread release = new Thread("AsyncAppenderReleaser") { + final Thread release = new Thread("AsyncAppenderReleaser") { public void run() { while (CountingAsyncQueueFullPolicy.queueFull.get() == 0) { try { Thread.sleep(10L); - } catch (InterruptedException ignored) { + } catch (final InterruptedException ignored) { //ignored } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/HangingAppender.java ---------------------------------------------------------------------- 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 3d456f2..36a652e 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 @@ -47,7 +47,7 @@ public class HangingAppender extends AbstractAppender { public void append(final LogEvent event) { try { Thread.sleep(delay); - } catch (InterruptedException ignore) { + } catch (final InterruptedException ignore) { // ignore } } @@ -69,7 +69,7 @@ public class HangingAppender extends AbstractAppender { public void start() { try { Thread.sleep(startupDelay); - } catch (InterruptedException ignore) { + } catch (final InterruptedException ignore) { // ignore } super.start(); @@ -80,7 +80,7 @@ public class HangingAppender extends AbstractAppender { super.stop(); try { Thread.sleep(shutdownDelay); - } catch (InterruptedException ignore) { + } catch (final InterruptedException ignore) { // ignore } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java index 9564dd9..cbb01d4 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java @@ -151,7 +151,7 @@ public class SocketAppenderTest { public void testUdpAppender() throws Exception { try { udpServer.latch.await(); - } catch (InterruptedException ex) { + } catch (final InterruptedException ex) { ex.printStackTrace(); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java index 2b7fc92..ae772f2 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/XmlCompleteFileAppenderTest.java @@ -112,7 +112,7 @@ public class XmlCompleteFileAppenderTest { log.info(secondLogMsg); CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread - String[] lines = new String[9]; + final String[] lines = new String[9]; try (final BufferedReader reader = new BufferedReader(new FileReader(file))) { http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java index 83f2476..dfa416c 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/mom/kafka/KafkaAppenderTest.java @@ -49,7 +49,7 @@ public class KafkaAppenderTest { public void close() { try { Thread.sleep(3000); - } catch (InterruptedException ignore) { + } catch (final InterruptedException ignore) { } } @@ -57,7 +57,7 @@ public class KafkaAppenderTest { public void close(final long timeout, final TimeUnit timeUnit) { try { Thread.sleep(timeUnit.toMillis(timeout)); - } catch (InterruptedException ignore) { + } catch (final InterruptedException ignore) { } } }; @@ -121,7 +121,7 @@ public class KafkaAppenderTest { @Test public void testAppendWithSerializedLayout() throws Exception { final Appender appender = ctx.getRequiredAppender("KafkaAppenderWithSerializedLayout"); - LogEvent logEvent = createLogEvent(); + final LogEvent logEvent = createLogEvent(); appender.append(logEvent); final List<ProducerRecord<byte[], byte[]>> history = kafka.history(); assertEquals(1, history.size()); @@ -133,7 +133,7 @@ public class KafkaAppenderTest { } private LogEvent deserializeLogEvent(final byte[] data) throws IOException, ClassNotFoundException { - ByteArrayInputStream bis = new ByteArrayInputStream(data); + final ByteArrayInputStream bis = new ByteArrayInputStream(data); try (ObjectInput ois = new ObjectInputStream(bis)) { return (LogEvent) ois.readObject(); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronTest.java index dcdb9fd..7ea8854 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronTest.java @@ -80,8 +80,8 @@ public class RollingAppenderCronTest { if (!succeeded) { fail("No compressed files found"); } - Path src = FileSystems.getDefault().getPath("target/test-classes/log4j-rolling-cron2.xml"); - OutputStream os = new FileOutputStream("target/test-classes/log4j-rolling-cron.xml"); + final Path src = FileSystems.getDefault().getPath("target/test-classes/log4j-rolling-cron2.xml"); + final OutputStream os = new FileOutputStream("target/test-classes/log4j-rolling-cron.xml"); Files.copy(src, os); Thread.sleep(5000); // force a reconfiguration @@ -89,11 +89,11 @@ public class RollingAppenderCronTest { logger.debug("Adding new event {}", i); } Thread.sleep(1000); - RollingFileAppender app = (RollingFileAppender) ctx.getContext().getConfiguration().getAppender("RollingFile"); - TriggeringPolicy policy = app.getManager().getTriggeringPolicy(); + final RollingFileAppender app = (RollingFileAppender) ctx.getContext().getConfiguration().getAppender("RollingFile"); + final TriggeringPolicy policy = app.getManager().getTriggeringPolicy(); assertNotNull("No triggering policy", policy); assertTrue("Incorrect policy type", policy instanceof CronTriggeringPolicy); - CronExpression expression = ((CronTriggeringPolicy) policy).getCronExpression(); + final CronExpression expression = ((CronTriggeringPolicy) policy).getCronExpression(); assertTrue("Incorrect triggering policy", expression.getCronExpression().equals("* * * ? * *")); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java index 56bb8c5..cabd93c 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCustomDeleteActionTest.java @@ -64,11 +64,11 @@ public class RollingAppenderCustomDeleteActionTest { final int MAX_TRIES = 20; for (int i = 0; i < MAX_TRIES; i++) { final File[] files = dir.listFiles(); - for (File file : files) { + for (final File file : files) { System.out.println(file); } if (files.length == 3) { - for (File file : files) { + for (final File file : files) { assertTrue("test-4.log should have been deleted", Arrays.asList("test-1.log", "test-2.log", "test-3.log").contains(file.getName())); } @@ -92,10 +92,10 @@ public class RollingAppenderCustomDeleteActionTest { } public static void main(final String[] args) { - Pattern p = Pattern.compile("test-.?[2,4,6,8,0]\\.log\\.gz"); + final Pattern p = Pattern.compile("test-.?[2,4,6,8,0]\\.log\\.gz"); for (int i = 0; i < 16; i++) { - String str = "test-" + i + ".log.gz"; - java.util.regex.Matcher m = p.matcher(str); + final String str = "test-" + i + ".log.gz"; + final java.util.regex.Matcher m = p.matcher(str); System.out.println(m.matches() + ": " + str); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java index 4595b59..b40d022 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount1Test.java @@ -58,11 +58,11 @@ public class RollingAppenderDeleteAccumulatedCount1Test { @Test public void testAppender() throws Exception { - Path p1 = writeTextTo(DIR + "/my-1.log"); // glob="test-*.log" - Path p2 = writeTextTo(DIR + "/my-2.log"); - Path p3 = writeTextTo(DIR + "/my-3.log"); - Path p4 = writeTextTo(DIR + "/my-4.log"); - Path p5 = writeTextTo(DIR + "/my-5.log"); + final Path p1 = writeTextTo(DIR + "/my-1.log"); // glob="test-*.log" + final Path p2 = writeTextTo(DIR + "/my-2.log"); + final Path p3 = writeTextTo(DIR + "/my-3.log"); + final Path p4 = writeTextTo(DIR + "/my-4.log"); + final Path p5 = writeTextTo(DIR + "/my-5.log"); final Logger logger = ctx.getLogger(); for (int i = 0; i < 10; ++i) { @@ -78,13 +78,13 @@ public class RollingAppenderDeleteAccumulatedCount1Test { assertTrue("Dir " + DIR + " should contain files", dir.listFiles().length > 0); final File[] files = dir.listFiles(); - for (File file : files) { + for (final File file : files) { System.out.println(file + " (" + file.length() + "B) " + FixedDateFormat.create(FixedFormat.ABSOLUTE).format(file.lastModified())); } - List<String> expected = Arrays.asList("my-1.log", "my-2.log", "my-3.log", "my-4.log", "my-5.log"); + final List<String> expected = Arrays.asList("my-1.log", "my-2.log", "my-3.log", "my-4.log", "my-5.log"); assertEquals(Arrays.toString(files), expected.size() + 6, files.length); - for (File file : files) { + for (final File file : files) { if (!expected.contains(file.getName()) && !file.getName().startsWith("test-")) { fail("unexpected file" + file); } @@ -92,13 +92,13 @@ public class RollingAppenderDeleteAccumulatedCount1Test { } private void updateLastModified(final Path... paths) throws IOException { - for (Path path : paths) { + for (final Path path : paths) { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis() + 2000)); } } private Path writeTextTo(final String location) throws IOException { - Path path = Paths.get(location); + final Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { buffy.write("some text"); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java index 5d3e736..67a2ccf 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedCount2Test.java @@ -58,11 +58,11 @@ public class RollingAppenderDeleteAccumulatedCount2Test { @Test public void testAppender() throws Exception { - Path p1 = writeTextTo(DIR + "/my-1.log"); // glob="test-*.log" - Path p2 = writeTextTo(DIR + "/my-2.log"); - Path p3 = writeTextTo(DIR + "/my-3.log"); - Path p4 = writeTextTo(DIR + "/my-4.log"); - Path p5 = writeTextTo(DIR + "/my-5.log"); + final Path p1 = writeTextTo(DIR + "/my-1.log"); // glob="test-*.log" + final Path p2 = writeTextTo(DIR + "/my-2.log"); + final Path p3 = writeTextTo(DIR + "/my-3.log"); + final Path p4 = writeTextTo(DIR + "/my-4.log"); + final Path p5 = writeTextTo(DIR + "/my-5.log"); final Logger logger = ctx.getLogger(); for (int i = 0; i < 10; ++i) { @@ -78,14 +78,14 @@ public class RollingAppenderDeleteAccumulatedCount2Test { assertTrue("Dir " + DIR + " should contain files", dir.listFiles().length > 0); final File[] files = dir.listFiles(); - for (File file : files) { + for (final File file : files) { System.out.println(file + " (" + file.length() + "B) " + FixedDateFormat.create(FixedFormat.ABSOLUTE).format(file.lastModified())); } // sometimes "test-9.log", sometimes "test-10.log" remains - List<String> expected = Arrays.asList("my-1.log", "my-2.log", "my-3.log", "my-4.log", "my-5.log"); + final List<String> expected = Arrays.asList("my-1.log", "my-2.log", "my-3.log", "my-4.log", "my-5.log"); assertEquals(Arrays.toString(files), expected.size() + 1, files.length); - for (File file : files) { + for (final File file : files) { if (!expected.contains(file.getName()) && !file.getName().startsWith("test-")) { fail("unexpected file" + file); } @@ -93,13 +93,13 @@ public class RollingAppenderDeleteAccumulatedCount2Test { } private void updateLastModified(final Path... paths) throws IOException { - for (Path path : paths) { + for (final Path path : paths) { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis() + 2000)); } } private Path writeTextTo(final String location) throws IOException { - Path path = Paths.get(location); + final Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { buffy.write("some text"); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedSizeTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedSizeTest.java index 96b9357..7f3ae76 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedSizeTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteAccumulatedSizeTest.java @@ -62,13 +62,13 @@ public class RollingAppenderDeleteAccumulatedSizeTest { assertTrue("Dir " + DIR + " should contain files", dir.listFiles().length > 0); final File[] files = dir.listFiles(); - for (File file : files) { + for (final File file : files) { System.out.println(file + " (" + file.length() + "B) " + FixedDateFormat.create(FixedFormat.ABSOLUTE).format(file.lastModified())); } assertEquals(Arrays.toString(files), 4, files.length); long total = 0; - for (File file : files) { + for (final File file : files) { // sometimes test-6.log remains assertTrue("unexpected file " + file, file.getName().startsWith("test-")); total += file.length(); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java index e185d58..a11cff6 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteMaxDepthTest.java @@ -57,10 +57,10 @@ public class RollingAppenderDeleteMaxDepthTest { @Test public void testAppender() throws Exception { // create some files that match the glob but exceed maxDepth - Path p1 = writeTextTo(DIR + "/1/test-4.log"); // glob="**/test-4.log" - Path p2 = writeTextTo(DIR + "/2/test-4.log"); - Path p3 = writeTextTo(DIR + "/1/2/test-4.log"); - Path p4 = writeTextTo(DIR + "/1/2/3/test-4.log"); + final Path p1 = writeTextTo(DIR + "/1/test-4.log"); // glob="**/test-4.log" + final Path p2 = writeTextTo(DIR + "/2/test-4.log"); + final Path p3 = writeTextTo(DIR + "/1/2/test-4.log"); + final Path p4 = writeTextTo(DIR + "/1/2/3/test-4.log"); final Logger logger = ctx.getLogger(); for (int i = 0; i < 10; ++i) { @@ -74,9 +74,9 @@ public class RollingAppenderDeleteMaxDepthTest { assertTrue("Dir " + DIR + " should contain files", dir.listFiles().length > 0); final File[] files = dir.listFiles(); - List<String> expected = Arrays.asList("1", "2", "test-1.log", "test-2.log", "test-3.log"); + final List<String> expected = Arrays.asList("1", "2", "test-1.log", "test-2.log", "test-3.log"); assertEquals(Arrays.toString(files), expected.size(), files.length); - for (File file : files) { + for (final File file : files) { assertTrue("test-4.log should have been deleted", expected.contains(file.getName())); } @@ -88,7 +88,7 @@ public class RollingAppenderDeleteMaxDepthTest { } private Path writeTextTo(final String location) throws IOException { - Path path = Paths.get(location); + final Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { buffy.write("some text"); @@ -110,10 +110,10 @@ public class RollingAppenderDeleteMaxDepthTest { } public static void main(final String[] args) { - Pattern p = Pattern.compile("test-.?[2,4,6,8,0]\\.log\\.gz"); + final Pattern p = Pattern.compile("test-.?[2,4,6,8,0]\\.log\\.gz"); for (int i = 0; i < 16; i++) { - String str = "test-" + i + ".log.gz"; - java.util.regex.Matcher m = p.matcher(str); + final String str = "test-" + i + ".log.gz"; + final java.util.regex.Matcher m = p.matcher(str); System.out.println(m.matches() + ": " + str); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java index 4fde77e..3022668 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteNestedTest.java @@ -57,11 +57,11 @@ public class RollingAppenderDeleteNestedTest { @Test public void testAppender() throws Exception { - Path p1 = writeTextTo(DIR + "/my-1.log"); // glob="test-*.log" - Path p2 = writeTextTo(DIR + "/my-2.log"); - Path p3 = writeTextTo(DIR + "/my-3.log"); - Path p4 = writeTextTo(DIR + "/my-4.log"); - Path p5 = writeTextTo(DIR + "/my-5.log"); + final Path p1 = writeTextTo(DIR + "/my-1.log"); // glob="test-*.log" + final Path p2 = writeTextTo(DIR + "/my-2.log"); + final Path p3 = writeTextTo(DIR + "/my-3.log"); + final Path p4 = writeTextTo(DIR + "/my-4.log"); + final Path p5 = writeTextTo(DIR + "/my-5.log"); final Logger logger = ctx.getLogger(); for (int i = 0; i < 10; ++i) { @@ -77,14 +77,14 @@ public class RollingAppenderDeleteNestedTest { assertTrue("Dir " + DIR + " should contain files", dir.listFiles().length > 0); final File[] files = dir.listFiles(); - for (File file : files) { + for (final File file : files) { System.out.println(file + " (" + file.length() + "B) " + FixedDateFormat.create(FixedFormat.ABSOLUTE).format(file.lastModified())); } - List<String> expected = Arrays.asList("my-1.log", "my-2.log", "my-3.log", "my-4.log", "my-5.log"); + final List<String> expected = Arrays.asList("my-1.log", "my-2.log", "my-3.log", "my-4.log", "my-5.log"); assertEquals(Arrays.toString(files), expected.size() + 3, files.length); - for (File file : files) { + for (final File file : files) { if (!expected.contains(file.getName()) && !file.getName().startsWith("test-")) { fail("unexpected file" + file); } @@ -92,13 +92,13 @@ public class RollingAppenderDeleteNestedTest { } private void updateLastModified(final Path... paths) throws IOException { - for (Path path : paths) { + for (final Path path : paths) { Files.setLastModifiedTime(path, FileTime.fromMillis(System.currentTimeMillis() + 2000)); } } private Path writeTextTo(final String location) throws IOException { - Path path = Paths.get(location); + final Path path = Paths.get(location); Files.createDirectories(path.getParent()); try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) { buffy.write("some text"); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptFri13thTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptFri13thTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptFri13thTest.java index 8bb3f7e..652c00d 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptFri13thTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptFri13thTest.java @@ -50,7 +50,7 @@ public class RollingAppenderDeleteScriptFri13thTest { final File dir = new File(DIR); dir.mkdirs(); for (int i = 1; i <= 30; i++) { - String day = i < 10 ? "0" + i : "" + i; + final String day = i < 10 ? "0" + i : "" + i; new File(dir, "test-201511" + day + "-0.log").createNewFile(); } assertEquals("Dir " + DIR + " filecount", 30, dir.listFiles().length); @@ -64,13 +64,13 @@ public class RollingAppenderDeleteScriptFri13thTest { } final File[] files = dir.listFiles(); - for (File file : files) { + for (final File file : files) { System.out.println(file); } - for (File file : files) { + for (final File file : files) { assertTrue(file.getName() + " starts with 'test-'", file.getName().startsWith("test-")); assertTrue(file.getName() + " ends with '.log'", file.getName().endsWith(".log")); - String strDate = file.getName().substring(5, 13); + final String strDate = file.getName().substring(5, 13); assertFalse(file + " is not Fri 13th", strDate.endsWith("20151113")); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptTest.java index 6f64ebe..0a4ac23 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderDeleteScriptTest.java @@ -60,14 +60,14 @@ public class RollingAppenderDeleteScriptTest { assertTrue("Dir " + DIR + " should contain files", dir.listFiles().length > 0); final File[] files = dir.listFiles(); - for (File file : files) { + for (final File file : files) { System.out.println(file); } - for (File file : files) { + for (final File file : files) { assertTrue(file.getName() + " starts with 'test-'", file.getName().startsWith("test-")); assertTrue(file.getName() + " ends with '.log'", file.getName().endsWith(".log")); - String strIndex = file.getName().substring(5, file.getName().indexOf('.')); - int index = Integer.parseInt(strIndex); + final String strIndex = file.getName().substring(5, file.getName().indexOf('.')); + final int index = Integer.parseInt(strIndex); assertTrue(file + " should have odd index", index % 2 == 1); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java index adcfd68..f354290 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderNoUnconditionalDeleteTest.java @@ -81,8 +81,8 @@ public class RollingAppenderNoUnconditionalDeleteTest { assertTrue("Dir " + directory + " should contain files", directory.listFiles().length > 0); int total = 0; - for (File file : directory.listFiles()) { - List<String> lines = Files.readAllLines(file.toPath(), Charset.defaultCharset()); + for (final File file : directory.listFiles()) { + final List<String> lines = Files.readAllLines(file.toPath(), Charset.defaultCharset()); total += lines.size(); } assertEquals("rolled over lines", LINECOUNT - 1, total); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java index 4258cb0..1834105 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderSizeTest.java @@ -92,26 +92,26 @@ public class RollingAppenderSizeTest { assertNotNull(files); assertThat(files, hasItemInArray(that(hasName(that(endsWith(fileExtension)))))); - DefaultRolloverStrategy.FileExtensions ext = DefaultRolloverStrategy.FileExtensions.lookup(fileExtension); + final DefaultRolloverStrategy.FileExtensions ext = DefaultRolloverStrategy.FileExtensions.lookup(fileExtension); if (ext == null || DefaultRolloverStrategy.FileExtensions.ZIP == ext || DefaultRolloverStrategy.FileExtensions.PACK200 == ext) { return; // commons compress cannot deflate zip? TODO test decompressing these formats } - for (File file : files) { + for (final File file : files) { if (file.getName().endsWith(fileExtension)) { CompressorInputStream in = null; try (FileInputStream fis = new FileInputStream(file)) { try { in = new CompressorStreamFactory().createCompressorInputStream(ext.name().toLowerCase(), fis); - } catch (CompressorException ce) { + } catch (final CompressorException ce) { ce.printStackTrace(); fail("Error creating intput stream from " + file.toString() + ": " + ce.getMessage()); } - ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(in, baos); - String text = new String(baos.toByteArray(), Charset.defaultCharset()); - String[] lines = text.split("[\\r\\n]+"); - for (String line : lines) { + final String text = new String(baos.toByteArray(), Charset.defaultCharset()); + final String[] lines = text.split("[\\r\\n]+"); + for (final String line : lines) { assertTrue(line .contains("DEBUG o.a.l.l.c.a.r.RollingAppenderSizeTest [main] This is test message number")); } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java index c745dd3..8f13ae2 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeleteActionTest.java @@ -40,78 +40,78 @@ import static org.junit.Assert.*; public class DeleteActionTest { private static DeleteAction createAnyFilter(final String path, final boolean followLinks, final int maxDepth, final boolean testMode) { - PathCondition[] pathFilters = {new FixedCondition(true)}; + final PathCondition[] pathFilters = {new FixedCondition(true)}; return create(path, followLinks, maxDepth, testMode, pathFilters); } private static DeleteAction create(final String path, final boolean followLinks, final int maxDepth, final boolean testMode, final PathCondition[] conditions) { - Configuration config = new BasicConfigurationFactory().new BasicConfiguration(); - DeleteAction delete = DeleteAction.createDeleteAction(path, followLinks, maxDepth, testMode, null, conditions, + final Configuration config = new BasicConfigurationFactory().new BasicConfiguration(); + final DeleteAction delete = DeleteAction.createDeleteAction(path, followLinks, maxDepth, testMode, null, conditions, null, config); return delete; } @Test public void testGetBasePathResolvesLookups() { - DeleteAction delete = createAnyFilter("${sys:user.home}/a/b/c", false, 1, false); + final DeleteAction delete = createAnyFilter("${sys:user.home}/a/b/c", false, 1, false); - Path actual = delete.getBasePath(); - String expected = System.getProperty("user.home") + "/a/b/c"; + final Path actual = delete.getBasePath(); + final String expected = System.getProperty("user.home") + "/a/b/c"; assertEquals(FileSystems.getDefault().getPath(expected), actual); } @Test public void testGetBasePathStringReturnsOriginalParam() { - DeleteAction delete = createAnyFilter("${sys:user.home}/a/b/c", false, 1, false); + final DeleteAction delete = createAnyFilter("${sys:user.home}/a/b/c", false, 1, false); assertEquals("${sys:user.home}/a/b/c", delete.getBasePathString()); } @Test public void testGetMaxDepthReturnsConstructorValue() { - DeleteAction delete = createAnyFilter("any", false, 23, false); + final DeleteAction delete = createAnyFilter("any", false, 23, false); assertEquals(23, delete.getMaxDepth()); } @Test public void testGetOptionsReturnsEmptySetIfNotFollowingLinks() { - DeleteAction delete = createAnyFilter("any", false, 0, false); + final DeleteAction delete = createAnyFilter("any", false, 0, false); assertEquals(Collections.emptySet(), delete.getOptions()); } @Test public void testGetOptionsReturnsSetWithFollowLinksIfFollowingLinks() { - DeleteAction delete = createAnyFilter("any", true, 0, false); + final DeleteAction delete = createAnyFilter("any", true, 0, false); assertEquals(EnumSet.of(FileVisitOption.FOLLOW_LINKS), delete.getOptions()); } @Test public void testGetFiltersReturnsConstructorValue() { - PathCondition[] filters = {new FixedCondition(true), new FixedCondition(false)}; + final PathCondition[] filters = {new FixedCondition(true), new FixedCondition(false)}; - DeleteAction delete = create("any", true, 0, false, filters); + final DeleteAction delete = create("any", true, 0, false, filters); assertEquals(Arrays.asList(filters), delete.getPathConditions()); } @Test public void testCreateFileVisitorReturnsDeletingVisitor() { - DeleteAction delete = createAnyFilter("any", true, 0, false); - FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); + final DeleteAction delete = createAnyFilter("any", true, 0, false); + final FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); assertTrue(visitor instanceof DeletingVisitor); } @Test public void testCreateFileVisitorTestModeIsActionTestMode() { - DeleteAction delete = createAnyFilter("any", true, 0, false); + final DeleteAction delete = createAnyFilter("any", true, 0, false); assertFalse(delete.isTestMode()); - FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); + final FileVisitor<Path> visitor = delete.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); assertTrue(visitor instanceof DeletingVisitor); assertFalse(((DeletingVisitor) visitor).isTestMode()); - DeleteAction deleteTestMode = createAnyFilter("any", true, 0, true); + final DeleteAction deleteTestMode = createAnyFilter("any", true, 0, true); assertTrue(deleteTestMode.isTestMode()); - FileVisitor<Path> testVisitor = deleteTestMode.createFileVisitor(delete.getBasePath(), + final FileVisitor<Path> testVisitor = deleteTestMode.createFileVisitor(delete.getBasePath(), delete.getPathConditions()); assertTrue(testVisitor instanceof DeletingVisitor); assertTrue(((DeletingVisitor) testVisitor).isTestMode()); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java index f35f44f..7258c23 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DeletingVisitorTest.java @@ -53,59 +53,59 @@ public class DeletingVisitorTest { @Test public void testAcceptedFilesAreDeleted() throws IOException { - Path base = Paths.get("/a/b/c"); + final Path base = Paths.get("/a/b/c"); final FixedCondition ACCEPT_ALL = new FixedCondition(true); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(ACCEPT_ALL), false); + final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(ACCEPT_ALL), false); - Path any = Paths.get("/a/b/c/any"); + final Path any = Paths.get("/a/b/c/any"); visitor.visitFile(any, null); assertTrue(visitor.deleted.contains(any)); } @Test public void testRejectedFilesAreNotDeleted() throws IOException { - Path base = Paths.get("/a/b/c"); + final Path base = Paths.get("/a/b/c"); final FixedCondition REJECT_ALL = new FixedCondition(false); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(REJECT_ALL), false); + final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(REJECT_ALL), false); - Path any = Paths.get("/a/b/c/any"); + final Path any = Paths.get("/a/b/c/any"); visitor.visitFile(any, null); assertFalse(visitor.deleted.contains(any)); } @Test public void testAllFiltersMustAcceptOrFileIsNotDeleted() throws IOException { - Path base = Paths.get("/a/b/c"); + final Path base = Paths.get("/a/b/c"); final FixedCondition ACCEPT_ALL = new FixedCondition(true); final FixedCondition REJECT_ALL = new FixedCondition(false); - List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, REJECT_ALL); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, false); + final List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, REJECT_ALL); + final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, false); - Path any = Paths.get("/a/b/c/any"); + final Path any = Paths.get("/a/b/c/any"); visitor.visitFile(any, null); assertFalse(visitor.deleted.contains(any)); } @Test public void testIfAllFiltersAcceptFileIsDeleted() throws IOException { - Path base = Paths.get("/a/b/c"); + final Path base = Paths.get("/a/b/c"); final FixedCondition ACCEPT_ALL = new FixedCondition(true); - List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, false); + final List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); + final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, false); - Path any = Paths.get("/a/b/c/any"); + final Path any = Paths.get("/a/b/c/any"); visitor.visitFile(any, null); assertTrue(visitor.deleted.contains(any)); } @Test public void testInTestModeFileIsNotDeletedEvenIfAllFiltersAccept() throws IOException { - Path base = Paths.get("/a/b/c"); + final Path base = Paths.get("/a/b/c"); final FixedCondition ACCEPT_ALL = new FixedCondition(true); - List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, true); + final List<? extends PathCondition> filters = Arrays.asList(ACCEPT_ALL, ACCEPT_ALL, ACCEPT_ALL); + final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, filters, true); - Path any = Paths.get("/a/b/c/any"); + final Path any = Paths.get("/a/b/c/any"); visitor.visitFile(any, null); assertFalse(visitor.deleted.contains(any)); } @@ -113,11 +113,11 @@ public class DeletingVisitorTest { @Test public void testVisitFileRelativizesAgainstBase() throws IOException { - PathCondition filter = new PathCondition() { + final PathCondition filter = new PathCondition() { @Override public boolean accept(final Path baseDir, final Path relativePath, final BasicFileAttributes attrs) { - Path expected = Paths.get("relative"); + final Path expected = Paths.get("relative"); assertEquals(expected, relativePath); return true; } @@ -126,10 +126,10 @@ public class DeletingVisitorTest { public void beforeFileTreeWalk() { } }; - Path base = Paths.get("/a/b/c"); - DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(filter), false); + final Path base = Paths.get("/a/b/c"); + final DeletingVisitorHelper visitor = new DeletingVisitorHelper(base, Arrays.asList(filter), false); - Path child = Paths.get("/a/b/c/relative"); + final Path child = Paths.get("/a/b/c/relative"); visitor.visitFile(child, null); } } http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DurationTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DurationTest.java index 880a4cf..456f95b 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DurationTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/DurationTest.java @@ -1,149 +1,149 @@ -/* - * 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.appender.rolling.action; - -import org.apache.logging.log4j.core.appender.rolling.action.Duration; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the Duration class. - */ -public class DurationTest { - - @Test(expected = NullPointerException.class) - public void testParseFailsIfNullText() { - Duration.parse(null); - } - - @Test(expected = IllegalArgumentException.class) - public void testParseFailsIfInvalidPattern() { - Duration.parse("abc"); - } - - @Test(expected = IllegalArgumentException.class) - public void testParseFailsIfSectionsOutOfOrder() { - Duration.parse("P4DT2M1S3H"); - } - - @Test(expected = IllegalArgumentException.class) - public void testParseFailsIfTButMissingTime() { - Duration.parse("P1dT"); - } - - @Test - public void testParseIsCaseInsensitive() { - assertEquals("P4DT3H2M1S", Duration.parse("p4dt3h2m1s").toString()); - } - - @Test - public void testParseAllowsOverflows() { - assertEquals(1000 * 70, Duration.parse("PT70S").toMillis()); - assertEquals(1000 * 70 * 60, Duration.parse("PT70M").toMillis()); - assertEquals(1000 * 25 * 60 * 60, Duration.parse("PT25H").toMillis()); - } - - @Test - public void testToMillis() { - assertEquals(0, Duration.ZERO.toMillis()); - assertEquals(1000, Duration.parse("PT1S").toMillis()); - assertEquals(1000 * 2 * 60, Duration.parse("PT2M").toMillis()); - assertEquals(1000 * 3 * 60 * 60, Duration.parse("PT3H").toMillis()); - assertEquals(1000 * 4 * 24 * 60 * 60, Duration.parse("P4D").toMillis()); - long expected = (1000 * 4 * 24 * 60 * 60) + (1000 * 3 * 60 * 60) + (1000 * 2 * 60) + 1000; - assertEquals(expected, Duration.parse("P4DT3H2M1S").toMillis()); - } - - @Test - public void testToString() { - assertEquals("PT0S", Duration.ZERO.toString()); - assertEquals("PT1S", Duration.parse("PT1S").toString()); - assertEquals("PT2M1S", Duration.parse("PT2M1S").toString()); - assertEquals("PT3H2M1S", Duration.parse("PT3H2M1S").toString()); - assertEquals("P4DT3H2M1S", Duration.parse("P4DT3H2M1S").toString()); - } - - @Test - public void testPrefixPNotRequired() { - assertEquals("PT1S", Duration.parse("T1S").toString()); - assertEquals("PT2M1S", Duration.parse("T2M1S").toString()); - assertEquals("PT3H2M1S", Duration.parse("T3H2M1S").toString()); - assertEquals("P4DT3H2M1S", Duration.parse("4DT3H2M1S").toString()); - } - - @Test - public void testInfixTNotRequired() { - assertEquals("PT1S", Duration.parse("P1S").toString()); - assertEquals("PT2M1S", Duration.parse("P2M1S").toString()); - assertEquals("PT3H2M1S", Duration.parse("P3H2M1S").toString()); - assertEquals("P4DT3H2M1S", Duration.parse("P4D3H2M1S").toString()); - } - - @Test - public void testPrefixPAndInfixTNotRequired() { - assertEquals("PT1S", Duration.parse("1S").toString()); - assertEquals("PT2M1S", Duration.parse("2M1S").toString()); - assertEquals("PT3H2M1S", Duration.parse("3H2M1S").toString()); - assertEquals("P4DT3H2M1S", Duration.parse("4D3H2M1S").toString()); - } - - @Test - public void testCompareTo() { - assertEquals(-1, Duration.parse("PT1S").compareTo(Duration.parse("PT2S"))); - assertEquals(-1, Duration.parse("PT1M").compareTo(Duration.parse("PT2M"))); - assertEquals(-1, Duration.parse("PT1H").compareTo(Duration.parse("PT2H"))); - assertEquals(-1, Duration.parse("P1D").compareTo(Duration.parse("P2D"))); - - assertEquals(0, Duration.parse("PT1S").compareTo(Duration.parse("PT1S"))); - assertEquals(0, Duration.parse("PT1M").compareTo(Duration.parse("PT1M"))); - assertEquals(0, Duration.parse("PT1H").compareTo(Duration.parse("PT1H"))); - assertEquals(0, Duration.parse("P1D").compareTo(Duration.parse("P1D"))); - - assertEquals(1, Duration.parse("PT2S").compareTo(Duration.parse("PT1S"))); - assertEquals(1, Duration.parse("PT2M").compareTo(Duration.parse("PT1M"))); - assertEquals(1, Duration.parse("PT2H").compareTo(Duration.parse("PT1H"))); - assertEquals(1, Duration.parse("P2D").compareTo(Duration.parse("P1D"))); - - assertEquals(0, Duration.parse("PT1M").compareTo(Duration.parse("PT60S"))); - assertEquals(0, Duration.parse("PT1H").compareTo(Duration.parse("PT60M"))); - assertEquals(0, Duration.parse("PT1H").compareTo(Duration.parse("PT3600S"))); - assertEquals(0, Duration.parse("P1D").compareTo(Duration.parse("PT24H"))); - assertEquals(0, Duration.parse("P1D").compareTo(Duration.parse("PT1440M"))); - } - - @Test - public void testEquals() { - assertNotEquals(Duration.parse("PT1S"),(Duration.parse("PT2S"))); - assertNotEquals(Duration.parse("PT1M"),(Duration.parse("PT2M"))); - assertNotEquals(Duration.parse("PT1H"),(Duration.parse("PT2H"))); - assertNotEquals(Duration.parse("P1D"),(Duration.parse("P2D"))); - - assertEquals( Duration.parse("PT1S"),(Duration.parse("PT1S"))); - assertEquals( Duration.parse("PT1M"),(Duration.parse("PT1M"))); - assertEquals( Duration.parse("PT1H"),(Duration.parse("PT1H"))); - assertEquals( Duration.parse("P1D"),(Duration.parse("P1D"))); - - assertEquals( Duration.parse("PT1M"),(Duration.parse("PT60S"))); - assertEquals( Duration.parse("PT1H"),(Duration.parse("PT60M"))); - assertEquals( Duration.parse("PT1H"),(Duration.parse("PT3600S"))); - assertEquals( Duration.parse("P1D"),(Duration.parse("PT24H"))); - assertEquals(Duration.parse("P1D"), (Duration.parse("PT1440M"))); - } - -} +/* + * 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.appender.rolling.action; + +import org.apache.logging.log4j.core.appender.rolling.action.Duration; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the Duration class. + */ +public class DurationTest { + + @Test(expected = NullPointerException.class) + public void testParseFailsIfNullText() { + Duration.parse(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testParseFailsIfInvalidPattern() { + Duration.parse("abc"); + } + + @Test(expected = IllegalArgumentException.class) + public void testParseFailsIfSectionsOutOfOrder() { + Duration.parse("P4DT2M1S3H"); + } + + @Test(expected = IllegalArgumentException.class) + public void testParseFailsIfTButMissingTime() { + Duration.parse("P1dT"); + } + + @Test + public void testParseIsCaseInsensitive() { + assertEquals("P4DT3H2M1S", Duration.parse("p4dt3h2m1s").toString()); + } + + @Test + public void testParseAllowsOverflows() { + assertEquals(1000 * 70, Duration.parse("PT70S").toMillis()); + assertEquals(1000 * 70 * 60, Duration.parse("PT70M").toMillis()); + assertEquals(1000 * 25 * 60 * 60, Duration.parse("PT25H").toMillis()); + } + + @Test + public void testToMillis() { + assertEquals(0, Duration.ZERO.toMillis()); + assertEquals(1000, Duration.parse("PT1S").toMillis()); + assertEquals(1000 * 2 * 60, Duration.parse("PT2M").toMillis()); + assertEquals(1000 * 3 * 60 * 60, Duration.parse("PT3H").toMillis()); + assertEquals(1000 * 4 * 24 * 60 * 60, Duration.parse("P4D").toMillis()); + final long expected = (1000 * 4 * 24 * 60 * 60) + (1000 * 3 * 60 * 60) + (1000 * 2 * 60) + 1000; + assertEquals(expected, Duration.parse("P4DT3H2M1S").toMillis()); + } + + @Test + public void testToString() { + assertEquals("PT0S", Duration.ZERO.toString()); + assertEquals("PT1S", Duration.parse("PT1S").toString()); + assertEquals("PT2M1S", Duration.parse("PT2M1S").toString()); + assertEquals("PT3H2M1S", Duration.parse("PT3H2M1S").toString()); + assertEquals("P4DT3H2M1S", Duration.parse("P4DT3H2M1S").toString()); + } + + @Test + public void testPrefixPNotRequired() { + assertEquals("PT1S", Duration.parse("T1S").toString()); + assertEquals("PT2M1S", Duration.parse("T2M1S").toString()); + assertEquals("PT3H2M1S", Duration.parse("T3H2M1S").toString()); + assertEquals("P4DT3H2M1S", Duration.parse("4DT3H2M1S").toString()); + } + + @Test + public void testInfixTNotRequired() { + assertEquals("PT1S", Duration.parse("P1S").toString()); + assertEquals("PT2M1S", Duration.parse("P2M1S").toString()); + assertEquals("PT3H2M1S", Duration.parse("P3H2M1S").toString()); + assertEquals("P4DT3H2M1S", Duration.parse("P4D3H2M1S").toString()); + } + + @Test + public void testPrefixPAndInfixTNotRequired() { + assertEquals("PT1S", Duration.parse("1S").toString()); + assertEquals("PT2M1S", Duration.parse("2M1S").toString()); + assertEquals("PT3H2M1S", Duration.parse("3H2M1S").toString()); + assertEquals("P4DT3H2M1S", Duration.parse("4D3H2M1S").toString()); + } + + @Test + public void testCompareTo() { + assertEquals(-1, Duration.parse("PT1S").compareTo(Duration.parse("PT2S"))); + assertEquals(-1, Duration.parse("PT1M").compareTo(Duration.parse("PT2M"))); + assertEquals(-1, Duration.parse("PT1H").compareTo(Duration.parse("PT2H"))); + assertEquals(-1, Duration.parse("P1D").compareTo(Duration.parse("P2D"))); + + assertEquals(0, Duration.parse("PT1S").compareTo(Duration.parse("PT1S"))); + assertEquals(0, Duration.parse("PT1M").compareTo(Duration.parse("PT1M"))); + assertEquals(0, Duration.parse("PT1H").compareTo(Duration.parse("PT1H"))); + assertEquals(0, Duration.parse("P1D").compareTo(Duration.parse("P1D"))); + + assertEquals(1, Duration.parse("PT2S").compareTo(Duration.parse("PT1S"))); + assertEquals(1, Duration.parse("PT2M").compareTo(Duration.parse("PT1M"))); + assertEquals(1, Duration.parse("PT2H").compareTo(Duration.parse("PT1H"))); + assertEquals(1, Duration.parse("P2D").compareTo(Duration.parse("P1D"))); + + assertEquals(0, Duration.parse("PT1M").compareTo(Duration.parse("PT60S"))); + assertEquals(0, Duration.parse("PT1H").compareTo(Duration.parse("PT60M"))); + assertEquals(0, Duration.parse("PT1H").compareTo(Duration.parse("PT3600S"))); + assertEquals(0, Duration.parse("P1D").compareTo(Duration.parse("PT24H"))); + assertEquals(0, Duration.parse("P1D").compareTo(Duration.parse("PT1440M"))); + } + + @Test + public void testEquals() { + assertNotEquals(Duration.parse("PT1S"),(Duration.parse("PT2S"))); + assertNotEquals(Duration.parse("PT1M"),(Duration.parse("PT2M"))); + assertNotEquals(Duration.parse("PT1H"),(Duration.parse("PT2H"))); + assertNotEquals(Duration.parse("P1D"),(Duration.parse("P2D"))); + + assertEquals( Duration.parse("PT1S"),(Duration.parse("PT1S"))); + assertEquals( Duration.parse("PT1M"),(Duration.parse("PT1M"))); + assertEquals( Duration.parse("PT1H"),(Duration.parse("PT1H"))); + assertEquals( Duration.parse("P1D"),(Duration.parse("P1D"))); + + assertEquals( Duration.parse("PT1M"),(Duration.parse("PT60S"))); + assertEquals( Duration.parse("PT1H"),(Duration.parse("PT60M"))); + assertEquals( Duration.parse("PT1H"),(Duration.parse("PT3600S"))); + assertEquals( Duration.parse("P1D"),(Duration.parse("PT24H"))); + assertEquals(Duration.parse("P1D"), (Duration.parse("PT1440M"))); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java index bb2a0d0..0022b40 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java @@ -1,75 +1,75 @@ -/* - * 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.appender.rolling.action; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the IfAccumulatedFileCount class. - */ -public class IfAccumulatedFileCountTest { - - @Test - public void testGetThresholdCount() { - assertEquals(123, IfAccumulatedFileCount.createFileCountCondition(123).getThresholdCount()); - assertEquals(456, IfAccumulatedFileCount.createFileCountCondition(456).getThresholdCount()); - } - - @Test - public void testAccept() { - int[] counts = {3, 5, 9}; - for (int count : counts) { - IfAccumulatedFileCount condition = IfAccumulatedFileCount.createFileCountCondition(count); - for (int i = 0; i < count; i++) { - assertFalse(condition.accept(null, null, null)); - // exact match: does not accept - } - // accept when threshold is exceeded - assertTrue(condition.accept(null, null, null)); - assertTrue(condition.accept(null, null, null)); - } - } - - @Test - public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() { - final CountingCondition counter = new CountingCondition(true); - IfAccumulatedFileCount condition = IfAccumulatedFileCount.createFileCountCondition(3, counter); - - for (int i = 1; i < 10; i++) { - if (i <= 3) { - assertFalse("i=" + i, condition.accept(null, null, null)); - assertEquals(0, counter.getAcceptCount()); - } else { - assertTrue(condition.accept(null, null, null)); - assertEquals(i - 3, counter.getAcceptCount()); - } - } - } - - @Test - public void testBeforeTreeWalk() { - final CountingCondition counter = new CountingCondition(true); - final IfAccumulatedFileCount filter = IfAccumulatedFileCount.createFileCountCondition(30, counter, counter, - counter); - filter.beforeFileTreeWalk(); - assertEquals(3, counter.getBeforeFileTreeWalkCount()); - } - -} +/* + * 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.appender.rolling.action; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the IfAccumulatedFileCount class. + */ +public class IfAccumulatedFileCountTest { + + @Test + public void testGetThresholdCount() { + assertEquals(123, IfAccumulatedFileCount.createFileCountCondition(123).getThresholdCount()); + assertEquals(456, IfAccumulatedFileCount.createFileCountCondition(456).getThresholdCount()); + } + + @Test + public void testAccept() { + final int[] counts = {3, 5, 9}; + for (final int count : counts) { + final IfAccumulatedFileCount condition = IfAccumulatedFileCount.createFileCountCondition(count); + for (int i = 0; i < count; i++) { + assertFalse(condition.accept(null, null, null)); + // exact match: does not accept + } + // accept when threshold is exceeded + assertTrue(condition.accept(null, null, null)); + assertTrue(condition.accept(null, null, null)); + } + } + + @Test + public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() { + final CountingCondition counter = new CountingCondition(true); + final IfAccumulatedFileCount condition = IfAccumulatedFileCount.createFileCountCondition(3, counter); + + for (int i = 1; i < 10; i++) { + if (i <= 3) { + assertFalse("i=" + i, condition.accept(null, null, null)); + assertEquals(0, counter.getAcceptCount()); + } else { + assertTrue(condition.accept(null, null, null)); + assertEquals(i - 3, counter.getAcceptCount()); + } + } + } + + @Test + public void testBeforeTreeWalk() { + final CountingCondition counter = new CountingCondition(true); + final IfAccumulatedFileCount filter = IfAccumulatedFileCount.createFileCountCondition(30, counter, counter, + counter); + filter.beforeFileTreeWalk(); + assertEquals(3, counter.getBeforeFileTreeWalkCount()); + } + +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ce4492f6/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileSizeTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileSizeTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileSizeTest.java index d22df55..740c998 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileSizeTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileSizeTest.java @@ -1,130 +1,130 @@ -/* - * 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.appender.rolling.action; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests the IfAccumulatedFileSize class. - */ -public class IfAccumulatedFileSizeTest { - - @Test - public void testGetThresholdBytes() { - assertEquals(2, create("2B").getThresholdBytes()); - assertEquals(3, create("3 B").getThresholdBytes()); - assertEquals(2 * 1024, create("2KB").getThresholdBytes()); - assertEquals(3 * 1024, create("3 KB").getThresholdBytes()); - assertEquals(2 * 1024 * 1024, create("2MB").getThresholdBytes()); - assertEquals(3 * 1024 * 1024, create("3 MB").getThresholdBytes()); - assertEquals(2L * 1024 * 1024 * 1024, create("2GB").getThresholdBytes()); - assertEquals(3L * 1024 * 1024 * 1024, create("3 GB").getThresholdBytes()); - } - - private static IfAccumulatedFileSize create(final String size) { - return IfAccumulatedFileSize.createFileSizeCondition(size); - } - - @Test - public void testNotAcceptOnExactMatch() { - String[] sizes = {"2KB", "3MB", "4GB"}; - for (String size : sizes) { - IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size); - DummyFileAttributes attribs = new DummyFileAttributes(); - attribs.size = condition.getThresholdBytes(); - assertFalse(condition.accept(null, null, attribs)); - } - } - - @Test - public void testAcceptIfExceedThreshold() { - String[] sizes = {"2KB", "3MB", "4GB"}; - for (String size : sizes) { - IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size); - DummyFileAttributes attribs = new DummyFileAttributes(); - attribs.size = condition.getThresholdBytes() + 1; - assertTrue(condition.accept(null, null, attribs)); - } - } - - @Test - public void testNotAcceptIfBelowThreshold() { - String[] sizes = {"2KB", "3MB", "4GB"}; - for (String size : sizes) { - IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size); - DummyFileAttributes attribs = new DummyFileAttributes(); - attribs.size = condition.getThresholdBytes() - 1; - assertFalse(condition.accept(null, null, attribs)); - } - } - - @Test - public void testAcceptOnceThresholdExceeded() { - DummyFileAttributes attribs = new DummyFileAttributes(); - String[] sizes = {"2KB", "3MB", "4GB"}; - for (String size : sizes) { - IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size); - long quarter = condition.getThresholdBytes() / 4; - attribs.size = quarter; - assertFalse(condition.accept(null, null, attribs)); - assertFalse(condition.accept(null, null, attribs)); - assertFalse(condition.accept(null, null, attribs)); - assertFalse(condition.accept(null, null, attribs)); - assertTrue(condition.accept(null, null, attribs)); - } - } - - @Test - public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() { - final CountingCondition counter = new CountingCondition(true); - IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition("2KB", counter); - DummyFileAttributes attribs = new DummyFileAttributes(); - - long quarter = condition.getThresholdBytes() / 4; - attribs.size = quarter; - assertFalse(condition.accept(null, null, attribs)); - assertEquals(0, counter.getAcceptCount()); - - assertFalse(condition.accept(null, null, attribs)); - assertEquals(0, counter.getAcceptCount()); - - assertFalse(condition.accept(null, null, attribs)); - assertEquals(0, counter.getAcceptCount()); - - assertFalse(condition.accept(null, null, attribs)); - assertEquals(0, counter.getAcceptCount()); - - assertTrue(condition.accept(null, null, attribs)); - assertEquals(1, counter.getAcceptCount()); - - assertTrue(condition.accept(null, null, attribs)); - assertEquals(2, counter.getAcceptCount()); - } - - @Test - public void testBeforeTreeWalk() { - final CountingCondition counter = new CountingCondition(true); - final IfAccumulatedFileSize filter = IfAccumulatedFileSize.createFileSizeCondition("2GB", counter, counter, - counter); - filter.beforeFileTreeWalk(); - assertEquals(3, counter.getBeforeFileTreeWalkCount()); - } - -} +/* + * 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.appender.rolling.action; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Tests the IfAccumulatedFileSize class. + */ +public class IfAccumulatedFileSizeTest { + + @Test + public void testGetThresholdBytes() { + assertEquals(2, create("2B").getThresholdBytes()); + assertEquals(3, create("3 B").getThresholdBytes()); + assertEquals(2 * 1024, create("2KB").getThresholdBytes()); + assertEquals(3 * 1024, create("3 KB").getThresholdBytes()); + assertEquals(2 * 1024 * 1024, create("2MB").getThresholdBytes()); + assertEquals(3 * 1024 * 1024, create("3 MB").getThresholdBytes()); + assertEquals(2L * 1024 * 1024 * 1024, create("2GB").getThresholdBytes()); + assertEquals(3L * 1024 * 1024 * 1024, create("3 GB").getThresholdBytes()); + } + + private static IfAccumulatedFileSize create(final String size) { + return IfAccumulatedFileSize.createFileSizeCondition(size); + } + + @Test + public void testNotAcceptOnExactMatch() { + final String[] sizes = {"2KB", "3MB", "4GB"}; + for (final String size : sizes) { + final IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size); + final DummyFileAttributes attribs = new DummyFileAttributes(); + attribs.size = condition.getThresholdBytes(); + assertFalse(condition.accept(null, null, attribs)); + } + } + + @Test + public void testAcceptIfExceedThreshold() { + final String[] sizes = {"2KB", "3MB", "4GB"}; + for (final String size : sizes) { + final IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size); + final DummyFileAttributes attribs = new DummyFileAttributes(); + attribs.size = condition.getThresholdBytes() + 1; + assertTrue(condition.accept(null, null, attribs)); + } + } + + @Test + public void testNotAcceptIfBelowThreshold() { + final String[] sizes = {"2KB", "3MB", "4GB"}; + for (final String size : sizes) { + final IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size); + final DummyFileAttributes attribs = new DummyFileAttributes(); + attribs.size = condition.getThresholdBytes() - 1; + assertFalse(condition.accept(null, null, attribs)); + } + } + + @Test + public void testAcceptOnceThresholdExceeded() { + final DummyFileAttributes attribs = new DummyFileAttributes(); + final String[] sizes = {"2KB", "3MB", "4GB"}; + for (final String size : sizes) { + final IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition(size); + final long quarter = condition.getThresholdBytes() / 4; + attribs.size = quarter; + assertFalse(condition.accept(null, null, attribs)); + assertFalse(condition.accept(null, null, attribs)); + assertFalse(condition.accept(null, null, attribs)); + assertFalse(condition.accept(null, null, attribs)); + assertTrue(condition.accept(null, null, attribs)); + } + } + + @Test + public void testAcceptCallsNestedConditionsOnlyIfPathAccepted() { + final CountingCondition counter = new CountingCondition(true); + final IfAccumulatedFileSize condition = IfAccumulatedFileSize.createFileSizeCondition("2KB", counter); + final DummyFileAttributes attribs = new DummyFileAttributes(); + + final long quarter = condition.getThresholdBytes() / 4; + attribs.size = quarter; + assertFalse(condition.accept(null, null, attribs)); + assertEquals(0, counter.getAcceptCount()); + + assertFalse(condition.accept(null, null, attribs)); + assertEquals(0, counter.getAcceptCount()); + + assertFalse(condition.accept(null, null, attribs)); + assertEquals(0, counter.getAcceptCount()); + + assertFalse(condition.accept(null, null, attribs)); + assertEquals(0, counter.getAcceptCount()); + + assertTrue(condition.accept(null, null, attribs)); + assertEquals(1, counter.getAcceptCount()); + + assertTrue(condition.accept(null, null, attribs)); + assertEquals(2, counter.getAcceptCount()); + } + + @Test + public void testBeforeTreeWalk() { + final CountingCondition counter = new CountingCondition(true); + final IfAccumulatedFileSize filter = IfAccumulatedFileSize.createFileSizeCondition("2GB", counter, counter, + counter); + filter.beforeFileTreeWalk(); + assertEquals(3, counter.getBeforeFileTreeWalkCount()); + } + +}
