|
16 | 16 | import java |
17 | 17 |
|
18 | 18 | /** |
19 | | - * Represents a likely a test method, which is either a method that is already |
20 | | - * recognized as a `TestMethod` or something that is likely a JUnit test or |
21 | | - * something in the expected test path for Java tests. |
22 | | - */ |
23 | | -class LikelyTestMethod extends Method { |
24 | | - LikelyTestMethod() { |
25 | | - this.getDeclaringType() instanceof TestClass |
26 | | - or |
27 | | - this instanceof TestMethod |
28 | | - or |
29 | | - this instanceof LikelyJunitTest |
30 | | - or |
31 | | - //standard Maven/Gradle test file discovery filepath |
32 | | - this.getFile().getAbsolutePath().matches("%src/test/java%") |
33 | | - or |
34 | | - this.getDeclaringType() instanceof SurefireTest |
35 | | - } |
36 | | -} |
37 | | - |
38 | | -/** |
39 | | - * Classes that are likely part of junit tests (more general than `TestMethod` from `UnitTest.qll`) |
40 | | - * A `Method` that is public, has no parameters, |
41 | | - * has a "void" return type, AND either has a name that starts with "test" OR |
42 | | - * has an annotation that ends with "Test" |
43 | | - */ |
44 | | -class LikelyJunitTest extends Method { |
45 | | - LikelyJunitTest() { |
46 | | - this.isPublic() and |
47 | | - this.getReturnType().hasName("void") and |
48 | | - this.hasNoParameters() and |
49 | | - ( |
50 | | - this.getName().matches("JUnit%") or |
51 | | - this.getName().matches("test%") or |
52 | | - this.getAnAnnotation().getType().getName().matches("%Test") |
53 | | - ) |
54 | | - } |
55 | | -} |
56 | | - |
57 | | -/** |
58 | | - * Maven surefire patterns to consider which files are testcases: |
59 | | - * https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html |
60 | | - */ |
61 | | -class SurefireTest extends Class { |
62 | | - SurefireTest() { |
63 | | - this.getFile().getAbsolutePath().matches("%src/test/java%") and |
64 | | - this.getFile() |
65 | | - .getBaseName() |
66 | | - .matches(["Test%.java", "%Test.java", "%Tests.java", "%TestCase.java"]) |
67 | | - } |
68 | | -} |
69 | | - |
70 | | -/** |
71 | | - * A `Method` from source that is not abstract |
| 19 | + * A `Method` from source that is not abstract, and likely not a test method |
72 | 20 | */ |
73 | 21 | class NonAbstractSource extends Method { |
74 | 22 | NonAbstractSource() { |
|
0 commit comments