• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.apifinder
2 
3 import com.android.tools.lint.checks.infrastructure.LintDetectorTest
4 import com.android.tools.lint.detector.api.Detector
5 import com.android.tools.lint.detector.api.Issue
6 
7 @Suppress("UnstableApiUsage")
8 class ApiFinderDetectorTest : LintDetectorTest() {
testJavanull9     fun testJava() {
10         lint()
11             .files(
12                 java(
13 // TODO: Remove the explicit constructors once UCallExpression.resolve() can resolve generated
14 //  default constructors in Java.
15                     """
16 package com.android.apifinder;
17 
18 public class TestClass {
19     public class PublicSubclass {
20         public PublicSubclass() {}
21         public void publicMethod() {}
22         private void privateMethod() {}
23     }
24 
25     private class PrivateSubclass {
26         public PrivateSubclass() {}
27         public void publicMethod() {}
28     }
29 
30     public void testMethod() {
31         PublicSubclass publicSubclass = new PublicSubclass();
32         publicSubclass.publicMethod();
33         publicSubclass.privateMethod();
34         PrivateSubclass privateSubclass = new PrivateSubclass();
35         privateSubclass.publicMethod();
36     }
37 }
38                     """
39                 ).indented()
40             )
41             .run()
42             .expect(
43                 """
44 src/com/android/apifinder/TestClass.java:16: Information: ModuleMethod:com.android.apifinder.TestClass.PublicSubclass.TestClass.PublicSubclass() [JavaKotlinApiUsedByModule]
45         PublicSubclass publicSubclass = new PublicSubclass();
46                                         ~~~~~~~~~~~~~~~~~~~~
47 src/com/android/apifinder/TestClass.java:17: Information: ModuleMethod:com.android.apifinder.TestClass.PublicSubclass.publicMethod() [JavaKotlinApiUsedByModule]
48         publicSubclass.publicMethod();
49         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50 0 errors, 2 warnings
51                 """
52             )
53     }
54 
testKotlinnull55     fun testKotlin() {
56         lint()
57             .files(
58                 kotlin(
59                     """
60 package com.android.apifinder
61 
62 class TestClass {
63     class PublicSubclass {
64         fun publicMethod() {}
65         private fun privateMethod() {}
66     }
67 
68     private class PrivateSubclass {
69         fun publicMethod() {}
70     }
71 
72     fun testMethod() {
73         val publicSubclass = PublicSubclass()
74         publicSubclass.publicMethod()
75         publicSubclass.privateMethod()
76         val privateSubclass = PrivateSubclass()
77         privateSubclass.publicMethod()
78     }
79 }
80                     """
81                 ).indented()
82             )
83             .run()
84             .expect(
85                 """
86 src/com/android/apifinder/TestClass.kt:14: Information: ModuleMethod:com.android.apifinder.TestClass.PublicSubclass.TestClass.PublicSubclass() [JavaKotlinApiUsedByModule]
87         val publicSubclass = PublicSubclass()
88                              ~~~~~~~~~~~~~~~~
89 src/com/android/apifinder/TestClass.kt:15: Warning: ModuleMethod:com.android.apifinder.TestClass.PublicSubclass.publicMethod() [JavaKotlinApiUsedByModule]
90         publicSubclass.publicMethod()
91         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92 0 errors, 2 warnings
93                 """
94             )
95     }
96 
getDetectornull97     override fun getDetector(): Detector {
98         return ApiFinderDetector()
99     }
100 
getIssuesnull101     override fun getIssues(): List<Issue> {
102         return listOf(ApiFinderDetector.ISSUE)
103     }
104 }
105