1 /* 2 * Copyright 2024 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 ReplaceWithDetectorPropertyTest { 25 26 @Test propertyUsage_isIgnorednull27 fun propertyUsage_isIgnored() { 28 val input = 29 arrayOf( 30 ktSample("replacewith.ReplaceWithUsageKotlin"), 31 javaSample("replacewith.PropertyJava") 32 ) 33 34 // TODO(b/323214452): This is incomplete, but we have explicitly suppressed replacement of 35 // Kotlin property accessors until we can properly convert the expressions to Java. 36 val expected = 37 """ 38 src/replacewith/PropertyJava.java:42: Hint: Replacement available [ReplaceWith] 39 clazz.setMethodDeprecated("value"); 40 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 41 src/replacewith/PropertyJava.java:43: Hint: Replacement available [ReplaceWith] 42 clazz.getMethodDeprecated(); 43 ~~~~~~~~~~~~~~~~~~~ 44 0 errors, 0 warnings, 2 hints 45 """ 46 .trimIndent() 47 48 // TODO(b/323214452): These are incorrect, but we can't fix them unless we parse the 49 // expression as a property reference and (a) convert to Java or (b) ignore them. 50 val expectedFixDiffs = 51 """ 52 Fix for src/replacewith/PropertyJava.java line 42: Replace with `otherProperty = "value"`: 53 @@ -42 +42 54 - clazz.setMethodDeprecated("value"); 55 + clazz.otherProperty = "value"; 56 Fix for src/replacewith/PropertyJava.java line 43: Replace with `otherProperty`: 57 @@ -43 +43 58 - clazz.getMethodDeprecated(); 59 + clazz.otherProperty(); 60 """ 61 .trimIndent() 62 63 check(*input).expect(expected).expectFixDiffs(expectedFixDiffs) 64 } 65 } 66