View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2017 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      @Test
35      public void testAccept() {
36          final String fileName = "BAD";
37          final BeforeExecutionExclusionFileFilter filter = new BeforeExecutionExclusionFileFilter();
38          filter.setFileNamePattern(Pattern.compile(fileName));
39          final BeforeExecutionFileFilterSet set = new BeforeExecutionFileFilterSet();
40          set.addBeforeExecutionFileFilter(filter);
41  
42          assertTrue("Invalid accept state, should accept", set.accept("ATest.java"));
43      }
44  
45      @Test
46      public void testReject() {
47          final String fileName = "Test";
48          final BeforeExecutionExclusionFileFilter filter = new BeforeExecutionExclusionFileFilter();
49          filter.setFileNamePattern(Pattern.compile(fileName));
50          final BeforeExecutionFileFilterSet set = new BeforeExecutionFileFilterSet();
51          set.addBeforeExecutionFileFilter(filter);
52  
53          assertFalse("Invalid accept state, should not accept", set.accept("ATest.java"));
54      }
55  
56      @Test
57      public void testGetFilters2() {
58          final BeforeExecutionFileFilterSet filterSet = new BeforeExecutionFileFilterSet();
59          filterSet.addBeforeExecutionFileFilter(new BeforeExecutionExclusionFileFilter());
60          assertEquals("size is the same", 1, filterSet.getBeforeExecutionFileFilters().size());
61      }
62  
63      @Test
64      public void testToString2() {
65          final BeforeExecutionFileFilterSet filterSet = new BeforeExecutionFileFilterSet();
66          filterSet.addBeforeExecutionFileFilter(new BeforeExecutionExclusionFileFilter());
67          assertNotNull("size is the same", filterSet.toString());
68      }
69  
70      @Test
71      public void testClear() {
72          final BeforeExecutionFileFilterSet filterSet = new BeforeExecutionFileFilterSet();
73          filterSet.addBeforeExecutionFileFilter(new BeforeExecutionExclusionFileFilter());
74  
75          assertEquals("Invalid filter set size",
76                  1, filterSet.getBeforeExecutionFileFilters().size());
77  
78          filterSet.clear();
79  
80          assertEquals("Invalid filter set size",
81                  0, filterSet.getBeforeExecutionFileFilters().size());
82      }
83  }