Skip to content

Commit 9c5a794

Browse files
committed
Java: Test @VisibleForTesting method accessing @VisibleForTesting members
1 parent 2042883 commit 9c5a794

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

java/ql/test/query-tests/VisibleForTestingAbuse/VisibleForTestingAbuse.expected

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
| packageone/SourcePackage1.java:9:21:9:32 | Annotated.m1 | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:9:29:9:30 | m1 | element |
2+
| packageone/SourcePackage1.java:10:21:10:32 | Annotated.m2 | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:11:26:11:27 | m2 | element |
3+
| packageone/SourcePackage1.java:12:18:12:36 | fPublic(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:26:23:26:29 | fPublic | element |
4+
| packageone/SourcePackage1.java:13:18:13:39 | fProtected(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:31:26:31:35 | fProtected | element |
5+
| packageone/SourcePackage1.java:16:31:16:42 | Annotated.m1 | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:9:29:9:30 | m1 | element |
6+
| packageone/SourcePackage1.java:17:31:17:42 | Annotated.m2 | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:11:26:11:27 | m2 | element |
7+
| packageone/SourcePackage1.java:18:28:18:46 | fPublic(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:26:23:26:29 | fPublic | element |
8+
| packageone/SourcePackage1.java:19:28:19:49 | fProtected(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:31:26:31:35 | fProtected | element |
19
| packageone/SourcePackage.java:9:21:9:32 | Annotated.m1 | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:9:29:9:30 | m1 | element |
210
| packageone/SourcePackage.java:10:21:10:32 | Annotated.m2 | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:11:26:11:27 | m2 | element |
311
| packageone/SourcePackage.java:16:18:16:36 | fPublic(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:26:23:26:29 | fPublic | element |
@@ -6,6 +14,7 @@
614
| packageone/SourcePackage.java:26:31:26:42 | Annotated.m2 | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:11:26:11:27 | m2 | element |
715
| packageone/SourcePackage.java:29:28:29:46 | fPublic(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:26:23:26:29 | fPublic | element |
816
| packageone/SourcePackage.java:30:28:30:49 | fProtected(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:31:26:31:35 | fProtected | element |
17+
| packagetwo/Annotated.java:89:20:89:34 | getSize(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:79:13:79:19 | getSize | element |
918
| packagetwo/Source.java:8:20:8:30 | Annotated.m | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:7:19:7:19 | m | element |
1019
| packagetwo/Source.java:14:17:14:29 | f(...) | Access of $@ annotated with VisibleForTesting found in production code. | packagetwo/Annotated.java:16:16:16:16 | f | element |
1120
| packagetwo/Source.java:20:28:20:47 | new AnnotatedClass(...) | Access of $@ annotated with VisibleForTesting found in production code. | packageone/AnnotatedClass.java:4:14:4:27 | AnnotatedClass | element |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package packageone;
2+
3+
import packagetwo.Annotated;
4+
5+
public class SourcePackage1 extends Annotated {
6+
@VisibleForTesting
7+
public void f() {
8+
9+
String s1 = Annotated.m1; // $ SPURIOUS: Alert
10+
String s2 = Annotated.m2; // $ SPURIOUS: Alert
11+
12+
int i2 = Annotated.fPublic(); // $ SPURIOUS: Alert
13+
int i3 = Annotated.fProtected(); // $ SPURIOUS: Alert
14+
15+
Runnable lambda = () -> {
16+
String lambdaS1 = Annotated.m1; // $ SPURIOUS: Alert
17+
String lambdaS2 = Annotated.m2; // $ SPURIOUS: Alert
18+
int lambdaI2 = Annotated.fPublic(); // $ SPURIOUS: Alert
19+
int lambdaI3 = Annotated.fProtected(); // $ SPURIOUS: Alert
20+
};
21+
}
22+
}

java/ql/test/query-tests/VisibleForTestingAbuse/packagetwo/Annotated.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,21 @@ void useVisibleForMembers() {
7272
int methodProtected = fProtected();
7373
}
7474
}
75+
76+
@VisibleForTesting
77+
static class InnerTestClass {
78+
@VisibleForTesting
79+
int getSize() {
80+
return 42;
81+
}
82+
83+
@VisibleForTesting
84+
private String data;
85+
}
86+
87+
private void useInnerClass() {
88+
InnerTestClass inner = new InnerTestClass();
89+
int size = inner.getSize(); // $ SPURIOUS: Alert
90+
String value = inner.data;
91+
}
7592
}

0 commit comments

Comments
 (0)