You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/06/30 13:47:48 UTC

[commons-io] branch master updated: Add test to make sure the setter of AndFileFilter works correctly (#244)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 726bc4e  Add test to make sure the setter of AndFileFilter works correctly (#244)
726bc4e is described below

commit 726bc4e23547df79ecf0b52e538ec6dc8116281b
Author: Bart <in...@bartfokker.com>
AuthorDate: Wed Jun 30 15:47:42 2021 +0200

    Add test to make sure the setter of AndFileFilter works correctly (#244)
    
    * add test to make sure the setter of AndFileFilter works correctly
    
    * remove unused import statement
---
 .../commons/io/filefilter/AndFileFilterTestCase.java   | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/test/java/org/apache/commons/io/filefilter/AndFileFilterTestCase.java b/src/test/java/org/apache/commons/io/filefilter/AndFileFilterTestCase.java
index e573b85..99e7902 100644
--- a/src/test/java/org/apache/commons/io/filefilter/AndFileFilterTestCase.java
+++ b/src/test/java/org/apache/commons/io/filefilter/AndFileFilterTestCase.java
@@ -17,9 +17,13 @@
 package org.apache.commons.io.filefilter;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
 
 /**
  * Tests {@link AndFileFilter}.
@@ -294,4 +298,18 @@ public class AndFileFilterTestCase extends ConditionalFileFilterAbstractTestCase
       testFilenameResults.add(9, Boolean.FALSE);
     }
   }
+
+  @Test
+  public void setTestFiltersClearsOld() {
+    // test that new filters correctly clear old filters
+    final List<IOFileFilter> simpleEmptyFileFilter = Collections.singletonList(EmptyFileFilter.EMPTY);
+    final AndFileFilter andFileFilter = new AndFileFilter(simpleEmptyFileFilter);
+    // make sure the filters at this point are the same
+    assertEquals(simpleEmptyFileFilter, andFileFilter.getFileFilters());
+
+    final List<IOFileFilter> simpleNonEmptyFilter = Collections.singletonList(EmptyFileFilter.NOT_EMPTY);
+    // when calling the setter the filters should reference the new filters
+    andFileFilter.setFileFilters(simpleNonEmptyFilter);
+    assertEquals(simpleNonEmptyFilter, andFileFilter.getFileFilters());
+  }
 }