Project Report: fawkez

Packagesummary org.jcoderz.commons.tracing

org.jcoderz.commons.tracing.AspectPatternTest

LineHitsNoteSource
1  /*
2   * $Id: ArraysUtil.java 1011 2008-06-16 17:57:36Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.tracing;
34  
35  
36  import org.objectweb.asm.Opcodes;
37  
38  import junit.framework.TestCase;
39  
40100(1)public class AspectPatternTest extends TestCase
41  {
42  
43 (2)(3)  public void testAspectPattern()
44    {
45100(4)    AspectPattern pat
46        = new AspectPattern("int foo.*.Bar.method()");
47100     assertEquals("No modifier!", pat.getModifiers(), 0);
48100(5)    assertEquals("method\\(\\)I", pat.getMethodRegex());
49100(6)    assertTrue(pat.matches(0,
50 (7)        "foo/test/Bar""method()I"));
51100(8)    assertFalse(pat.matches(0,
52          "foo/test/Bar", "method(I)I"));
53100   }
54  
55 (9)(10)  public void testAspectPattern2()
56    {
57100(11)    AspectPattern pat
58        = new AspectPattern("int *.method(*)");
59100     assertEquals("No modifier!", pat.getModifiers(), 0);
60100(12)(13)    assertEquals("method\\(\\[*([VZCBSIFJD]|L[^;]+;)\\)I", pat.getMethodRegex());
61100(14)    assertEquals("[^/]*", pat.getClassRegex());
62100(15)    assertTrue(pat.matches(0,
63 (16)        "Foo""method(I)I"));
64100(17)    assertTrue(pat.matches(0,
65          "Foo", "method([I)I"));
66100(18)    assertTrue(pat.matches(0,
67          "Foo", "method(Ljava/lang/String;)I"));
68100(19)    assertFalse(pat.matches(0,
69          "Foo", "method()I"));
70100(20)    assertFalse(pat.matches(0,
71          "pkg/Foo", "method(I)I"));
72100(21)    assertFalse(pat.matches(0,
73 (22)        "pkg/Foo", "method(II)I"));
74100(23)    assertFalse(pat.matches(0,
75          "Foo", "method()I"));
76100(24)    assertFalse(pat.matches(0,
77          "Foo", "method(I)V"));
78100   }
79  
80 (25)(26)  public void testAspectPattern3()
81    {
82100(27)    AspectPattern pat
83        = new AspectPattern("int foo.*.*.method(*,int)");
84100     assertEquals("No modifier!", pat.getModifiers(), 0);
85 (28)//    assertEquals("method\\(\\[*([VZCBSIFJD]|L[^;]+;)\\)I", pat.mMethodPattern);
86  //    assertEquals("[^/]*", pat.mClassName);
87100(29)    assertTrue(pat.matches(0,
88 (30)        "foo/foo/Foo", "method(JI)I"));
89100(31)    assertTrue(pat.matches(0,
90          "foo/test/Bar", "method(Ljava/lang/String;I)I"));
91100(32)    assertTrue(pat.matches(0,
92          "foo/test/Bar", "method(II)I"));
93100(33)    assertFalse(pat.matches(0,
94          "foo/Bar", "method(II)I"));
95100(34)    assertFalse(pat.matches(0,
96          "foo/test/Bar", "method(IJ)I"));
97100(35)    assertFalse(pat.matches(0,
98          "foo/test/Bar", "method(II)V"));
99100(36)    assertFalse(pat.matches(0,
100          "test/test/Bar", "method(II)I"));
101100   }
102  
103 (37)(38)  public void testAspectPattern4()
104    {
105100(39)    AspectPattern pat
106        = new AspectPattern("public * org.jcoderz..*.*(..)");
107100     assertTrue("Pattern should match class!" + pat,
108          pat.matchClass("org/jcoderz/tracing/Test"));
109100     assertTrue("Pattern should match method!" + pat,
110          pat.matchMethod("method(JI)I"));
111100     assertTrue("Pattern should match!" + pat, pat.matches(1,
112          "org/jcoderz/tracing/Test", "method(JI)I"));
113100   }
114  
115 (40)(41)  public void testAspectPattern5()
116    {
117100(42)    AspectPattern pat
118        = new AspectPattern("public * org.jcoderz.tracing.logging.test.*.*(..)");
119100     assertTrue("Pattern should match class!" + pat,
120          pat.matchClass("org/jcoderz/tracing/logging/test/Test"));
121100     assertTrue("Pattern should match method!" + pat,
122          pat.matchMethod("method(JI)I"));
123100     assertTrue("Pattern should match!" + pat, pat.matches(1,
124          "org/jcoderz/tracing/logging/test/Test", "method(JI)I"));
125100   }
126  
127 (43)(44)  public void testAspectPattern6()
128    {
129100(45)    AspectPattern pat
130        = new AspectPattern("* *.set*(..)");
131100     assertTrue("Pattern should match class!" + pat,
132          pat.matchClass("Test"));
133100     assertTrue("Pattern should match method!" + pat,
134          pat.matchMethod("setMethod(JI)I"));
135100     assertFalse("Pattern should not match class!" + pat,
136          pat.matchClass("com/Test"));
137100   }
138  
139 (46)(47)  public void testAspectPattern7()
140    {
141100(48)    AspectPattern pat
142        = new AspectPattern("public void Account.set*(*)");
143100(49)    assertTrue("Pattern should match class! " + pat,
144          pat.matchClass("Account"));
145100(50)    assertTrue("Pattern should match method! " + pat,
146          pat.matchMethod("setMethod(I)V"));
147100     assertTrue("Pattern should match method! " + pat,
148          pat.matchAccess(Opcodes.ACC_PUBLIC));
149100     assertFalse("Pattern should not access level! " + pat,
150          pat.matchAccess(Opcodes.ACC_PRIVATE));
151100     assertFalse("Pattern should not match method! " + pat,
152          pat.matchMethod("getMethod(I)V"));
153100     assertFalse("Pattern should not match class! " + pat,
154          pat.matchClass("com.Account"));
155100   }
156  
157 (51)(52)  public void testAspectPattern8()
158    {
159100(53)    AspectPattern pat
160        = new AspectPattern("public static void ...main(String[])");
161100     assertTrue("Pattern should match class! " + pat,
162          pat.matchClass("Account"));
163100     assertTrue("Pattern should match class! " + pat,
164          pat.matchClass("com/Account"));
165100     assertTrue("Pattern should match method! " + pat,
166          pat.matchMethod("main([Ljava/lang/String;)V"));
167100     assertTrue("Pattern should match access level! " + pat,
168          pat.matchAccess(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC));
169100     assertFalse("Pattern should not match access level! " + pat,
170          pat.matchAccess(Opcodes.ACC_STATIC));
171100     assertFalse("Pattern should not access level! " + pat,
172          pat.matchAccess(Opcodes.ACC_PRIVATE));
173100     assertFalse("Pattern should not match method! " + pat,
174          pat.matchMethod("getMethod(I)V"));
175100   }
176  
177 (54)(55)  public void testAspectPattern9()
178    {
179100(56)    AspectPattern pat
180 (57)      = new AspectPattern("public static * org.jcoderz.tracing.db.DaoUtil.*(..)");
181100     assertTrue("Pattern should match class! " + pat,
182          pat.matchClass("org/jcoderz/tracing/db/DaoUtil"));
183100     assertTrue("Pattern should match method! " + pat + " '"
184          + pat.getMethodPattern() + "'",
185          pat.matchMethod("create(Ljava/lang/Object;)Ljava/lang/Object;"));
186100     assertTrue("Pattern should match access level! " + pat,
187          pat.matchAccess(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC));
188100     assertFalse("Pattern should not match access level! " + pat,
189          pat.matchAccess(Opcodes.ACC_STATIC));
190100     assertFalse("Pattern should not access level! " + pat,
191          pat.matchAccess(Opcodes.ACC_PRIVATE));
192100   }
193  }

Findings in this File

c (1) 40 : 0 Missing a Javadoc comment.
c (2) 43 : 3 Missing a Javadoc comment.
c (3) 43 : 32 '(' is not preceded with whitespace.
c (4) 45 : 19 Variable 'pat' should be declared final.
c (5) 48 : 5 JUnit assertions should include a message
c (6) 49 : 5 JUnit assertions should include a message
i (7) 50 : 9 The String literal "foo/test/Bar" appears 6 times in this file; the first occurrence is on line 50 (test code)
c (8) 51 : 5 JUnit assertions should include a message
c (9) 55 : 3 Missing a Javadoc comment.
c (10) 55 : 33 '(' is not preceded with whitespace.
c (11) 57 : 19 Variable 'pat' should be declared final.
c (12) 60 : 0 Line is longer than 80 characters.
c (13) 60 : 5 JUnit assertions should include a message
c (14) 61 : 5 JUnit assertions should include a message
c (15) 62 : 5 JUnit assertions should include a message
i (16) 63 : 9 The String literal "Foo" appears 6 times in this file; the first occurrence is on line 63 (test code)
c (17) 64 : 5 JUnit assertions should include a message
c (18) 66 : 5 JUnit assertions should include a message
c (19) 68 : 5 JUnit assertions should include a message
c (20) 70 : 5 JUnit assertions should include a message
c (21) 72 : 5 JUnit assertions should include a message
i (22) 73 : 20 The String literal "method(II)I" appears 4 times in this file; the first occurrence is on line 73 (test code)
c (23) 74 : 5 JUnit assertions should include a message
c (24) 76 : 5 JUnit assertions should include a message
c (25) 80 : 3 Missing a Javadoc comment.
c (26) 80 : 33 '(' is not preceded with whitespace.
c (27) 82 : 19 Variable 'pat' should be declared final.
c (28) 85 : 0 Line is longer than 80 characters.
c (29) 87 : 5 JUnit assertions should include a message
i (30) 88 : 24 The String literal "method(JI)I" appears 5 times in this file; the first occurrence is on line 88 (test code)
c (31) 89 : 5 JUnit assertions should include a message
c (32) 91 : 5 JUnit assertions should include a message
c (33) 93 : 5 JUnit assertions should include a message
c (34) 95 : 5 JUnit assertions should include a message
c (35) 97 : 5 JUnit assertions should include a message
c (36) 99 : 5 JUnit assertions should include a message
c (37) 103 : 3 Missing a Javadoc comment.
c (38) 103 : 33 '(' is not preceded with whitespace.
c (39) 105 : 19 Variable 'pat' should be declared final.
c (40) 115 : 3 Missing a Javadoc comment.
c (41) 115 : 33 '(' is not preceded with whitespace.
c (42) 117 : 19 Variable 'pat' should be declared final.
c (43) 127 : 3 Missing a Javadoc comment.
c (44) 127 : 33 '(' is not preceded with whitespace.
c (45) 129 : 19 Variable 'pat' should be declared final.
c (46) 139 : 3 Missing a Javadoc comment.
c (47) 139 : 33 '(' is not preceded with whitespace.
c (48) 141 : 19 Variable 'pat' should be declared final.
i (49) 143 : 16 The String literal "Pattern should match class! " appears 4 times in this file; the first occurrence is on line 143 (test code)
i (50) 145 : 16 The String literal "Pattern should match method! " appears 4 times in this file; the first occurrence is on line 145 (test code)
c (51) 157 : 3 Missing a Javadoc comment.
c (52) 157 : 33 '(' is not preceded with whitespace.
c (53) 159 : 19 Variable 'pat' should be declared final.
c (54) 177 : 3 Missing a Javadoc comment.
c (55) 177 : 33 '(' is not preceded with whitespace.
c (56) 179 : 19 Variable 'pat' should be declared final.
c (57) 180 : 0 Line is longer than 80 characters.