@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 testBeforeTreeWalk() { final CountingCondition counter = new CountingCondition(true); final IfAccumulatedFileCount filter = IfAccumulatedFileCount.createFileCountCondition(30, counter, counter, counter); filter.beforeFileTreeWalk(); assertEquals(3, counter.getBeforeFileTreeWalkCount()); }
@Test public void testGetThresholdCount() { assertEquals(123, IfAccumulatedFileCount.createFileCountCondition(123).getThresholdCount()); assertEquals(456, IfAccumulatedFileCount.createFileCountCondition(456).getThresholdCount()); }
/** * Create an IfAccumulatedFileCount condition. * * @param threshold The threshold count from which files will be deleted. * @return An IfAccumulatedFileCount condition. */ @PluginFactory public static IfAccumulatedFileCount createFileCountCondition( // @formatter:off @PluginAttribute(value = "exceeds", defaultInt = Integer.MAX_VALUE) final int threshold, @PluginElement("PathConditions") final PathCondition... nestedConditions) { // @formatter:on if (threshold == Integer.MAX_VALUE) { LOGGER.error("IfAccumulatedFileCount invalid or missing threshold value."); } return new IfAccumulatedFileCount(threshold, nestedConditions); }
@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()); } } }