View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2018 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.api;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertFalse;
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertTrue;
26  
27  import java.util.regex.Pattern;
28  
29  import org.junit.Test;
30  
31  import com.puppycrawl.tools.checkstyle.filefilters.BeforeExecutionExclusionFileFilter;
32  
33  public class BeforeExecutionFileFilterSetTest {
34  
35      @Test
36      public void testAccept() {
37          final String fileName = "BAD";
38          final BeforeExecutionExclusionFileFilter filter = new BeforeExecutionExclusionFileFilter();
39          filter.setFileNamePattern(Pattern.compile(fileName));
40          final BeforeExecutionFileFilterSet set = new BeforeExecutionFileFilterSet();
41          set.addBeforeExecutionFileFilter(filter);
42  
43          assertTrue("Invalid accept state, should accept", set.accept("ATest.java"));
44      }
45  
46      @Test
47      public void testReject() {
48          final String fileName = "Test";
49          final BeforeExecutionExclusionFileFilter filter = new BeforeExecutionExclusionFileFilter();
50          filter.setFileNamePattern(Pattern.compile(fileName));
51          final BeforeExecutionFileFilterSet set = new BeforeExecutionFileFilterSet();
52          set.addBeforeExecutionFileFilter(filter);
53  
54          assertFalse("Invalid accept state, should not accept", set.accept("ATest.java"));
55      }
56  
57      @Test
58      public void testGetFilters2() {
59          final BeforeExecutionFileFilterSet filterSet = new BeforeExecutionFileFilterSet();
60          filterSet.addBeforeExecutionFileFilter(new BeforeExecutionExclusionFileFilter());
61          assertEquals("size is the same", 1, filterSet.getBeforeExecutionFileFilters().size());
62      }
63  
64      @Test
65      public void testToString2() {
66          final BeforeExecutionFileFilterSet filterSet = new BeforeExecutionFileFilterSet();
67          filterSet.addBeforeExecutionFileFilter(new BeforeExecutionExclusionFileFilter());
68          assertNotNull("size is the same", filterSet.toString());
69      }
70  
71      @Test
72      public void testClear() {
73          final BeforeExecutionFileFilterSet filterSet = new BeforeExecutionFileFilterSet();
74          filterSet.addBeforeExecutionFileFilter(new BeforeExecutionExclusionFileFilter());
75  
76          assertEquals("Invalid filter set size",
77                  1, filterSet.getBeforeExecutionFileFilters().size());
78  
79          filterSet.clear();
80  
81          assertEquals("Invalid filter set size",
82                  0, filterSet.getBeforeExecutionFileFilters().size());
83      }
84  
85  }