LOG4J2-435 added test for IfAccumulatedFileCount Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f496c0ae Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f496c0ae Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f496c0ae
Branch: refs/heads/master Commit: f496c0ae2c529ef92c4ecd9199e5cf4437def01a Parents: 97e22a7 Author: rpopma <[email protected]> Authored: Fri Nov 27 00:10:19 2015 +0900 Committer: rpopma <[email protected]> Committed: Fri Nov 27 00:10:19 2015 +0900 ---------------------------------------------------------------------- .../rolling/action/IfAccumulatedFileCount.java | 10 ++-- .../action/IfAccumulatedFileCountTest.java | 48 ++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f496c0ae/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCount.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCount.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCount.java index 8bc8a85..b411d50 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCount.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCount.java @@ -34,11 +34,11 @@ public final class IfAccumulatedFileCount implements PathCondition { private final int threshold; private int count; - private IfAccumulatedFileCount(final int threshold) { - if (threshold <= 0) { - throw new IllegalArgumentException("Count must be a positive integer but was " + threshold); + private IfAccumulatedFileCount(final int thresholdParam) { + if (thresholdParam <= 0) { + throw new IllegalArgumentException("Count must be a positive integer but was " + thresholdParam); } - this.threshold = threshold; + this.threshold = thresholdParam; } public int getThresholdCount() { @@ -76,7 +76,7 @@ public final class IfAccumulatedFileCount implements PathCondition { * @return An IfAccumulatedFileCount condition. */ @PluginFactory - public static IfAccumulatedFileCount createAgeCondition( // + public static IfAccumulatedFileCount createFileCountCondition( // @PluginAttribute(value = "exceeds", defaultInt = Integer.MAX_VALUE) final int threshold) { if (threshold == Integer.MAX_VALUE) { LOGGER.error("IfAccumulatedFileCount invalid or missing threshold value."); http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f496c0ae/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 new file mode 100644 index 0000000..719f6f6 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/action/IfAccumulatedFileCountTest.java @@ -0,0 +1,48 @@ +/* + * 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)); + } + assertTrue(condition.accept(null, null, null)); + assertTrue(condition.accept(null, null, null)); + } + } + +}
