1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.build.lint.replacewith
18 
19 import org.junit.Test
20 import org.junit.runner.RunWith
21 import org.junit.runners.JUnit4
22 
23 @RunWith(JUnit4::class)
24 class ReplaceWithDetectorKotlinMethodTest {
25 
26     @Test
staticMethodExplicitClassnull27     fun staticMethodExplicitClass() {
28         val input =
29             arrayOf(
30                 ktSample("replacewith.ReplaceWithUsageKotlin"),
31                 javaSample("replacewith.StaticKotlinMethodExplicitClassJava")
32             )
33 
34         val expected =
35             """
36 src/replacewith/StaticKotlinMethodExplicitClassJava.java:25: Hint: Replacement available [ReplaceWith]
37         ReplaceWithUsageKotlin.toString(this);
38         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39 0 errors, 0 warnings, 1 hint
40         """
41                 .trimIndent()
42 
43         val expectedFixDiffs =
44             """
45 Fix for src/replacewith/StaticKotlinMethodExplicitClassJava.java line 25: Replace with `this.toString()`:
46 @@ -25 +25
47 -         ReplaceWithUsageKotlin.toString(this);
48 +         this.toString();
49         """
50                 .trimIndent()
51 
52         check(*input).expect(expected).expectFixDiffs(expectedFixDiffs)
53     }
54 
55     @Test
staticMethodExplicitClass_withKotlinSource_hasNoWarningsnull56     fun staticMethodExplicitClass_withKotlinSource_hasNoWarnings() {
57         val input =
58             arrayOf(
59                 ktSample("replacewith.ReplaceWithUsageKotlin"),
60                 ktSample("replacewith.StaticKotlinMethodExplicitClassKotlin")
61             )
62 
63         val expected =
64             """
65 No warnings.
66         """
67                 .trimIndent()
68 
69         check(*input).expect(expected)
70     }
71 }
72