1   /*
2    * Copyright (c) 2003-2008, by Henrik Arro and Contributors
3    *
4    * This file is part of JSeq, a tool to automatically create
5    * sequence diagrams by tracing program execution.
6    *
7    * See <http://jseq.sourceforge.net> for more information.
8    *
9    * JSeq is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of
12   * the License, or (at your option) any later version.
13   *
14   * JSeq is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public License
20   * along with JSeq. If not, see <http://www.gnu.org/licenses/>.
21   */
22  
23  package th.co.edge.jseq;
24  
25  import junit.framework.Test;
26  import junit.framework.TestCase;
27  import junit.framework.TestSuite;
28  
29  public class ClassExclusionFilterTest extends TestCase {
30      private Activation foobarBaz = new Activation(null, "foo.bar",
31              new TestMethodImpl("Baz"), -1);
32      private Activation foobarFrotz = new Activation(null, "foo.bar",
33              new TestMethodImpl("Frotz"), -1);
34      private Activation foobazBaz = new Activation(null, "foo.baz",
35              new TestMethodImpl("Baz"), -1);
36  
37      public ClassExclusionFilterTest(String name) {
38          super(name);
39      }
40  
41      public static Test suite() {
42          TestSuite suite = new TestSuite(ClassExclusionFilterTest.class);
43          return suite;
44      }
45  
46      //
47      // Test methods
48      //
49  
50      public void testExactMatch() {
51          ClassExclusionFilter filter = new ClassExclusionFilter("foo.bar.Baz");
52          assertTrue("foo.bar.Baz should not be accepted", !filter
53                  .accept(foobarBaz));
54          assertTrue("foo.bar.Frotz should be accepted", filter
55                  .accept(foobarFrotz));
56      }
57  
58      public void testPrefixMatch() {
59          ClassExclusionFilter filter = new ClassExclusionFilter("foo.bar.*");
60          assertTrue("foo.bar.Baz should not be accepted", !filter
61                  .accept(foobarBaz));
62          assertTrue("foo.baz.Baz should be accepted", filter.accept(foobazBaz));
63      }
64  
65      public void testSuffixMatch() {
66          ClassExclusionFilter filter = new ClassExclusionFilter("*.Baz");
67          assertTrue("foo.bar.Baz should not be accepted", !filter
68                  .accept(foobarBaz));
69          assertTrue("foo.bar.Frotz should be accepted", filter
70                  .accept(foobarFrotz));
71      }
72  
73      public void testEverythingMatch() {
74          ClassExclusionFilter filter = new ClassExclusionFilter("*");
75          assertTrue("foo.bar.Baz should not be accepted", !filter
76                  .accept(foobarBaz));
77          assertTrue("foo.baz.Baz should not be accepted", !filter
78                  .accept(foobazBaz));
79          assertTrue("foo.bar.Frotz should not be accepted", !filter
80                  .accept(foobarFrotz));
81      }
82  }