Address lint issues in IdeaSuppressionDetectorTest
Inline sample files into test file
Fixes: 236486964
Fixes: 236487053
Test: IdeaSuppressionDetectorTest
Test: ./gradlew :lint-checks:lintDebug
Test: presubmit
Change-Id: I5c1b1020da66ef1564c06d93c05489aee616cd3e
diff --git a/lint-checks/integration-tests/src/main/java/androidx/IdeaSuppressionJava.java b/lint-checks/integration-tests/src/main/java/androidx/IdeaSuppressionJava.java
deleted file mode 100644
index 390bf2b..0000000
--- a/lint-checks/integration-tests/src/main/java/androidx/IdeaSuppressionJava.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx;
-
-/**
- * Java usage of inline suppression.
- */
-@SuppressWarnings("unused")
-public class IdeaSuppressionJava {
-
- /**
- * Call to a deprecated method with an inline suppression.
- */
- public void callDeprecatedMethod() {
- //noinspection deprecation
- deprecatedMethod();
-
- notDeprecatedMethod();
- }
-
- /**
- * This method is deprecated.
- *
- * @deprecated Replaced with {@link #notDeprecatedMethod()}
- */
- @Deprecated
- public void deprecatedMethod() {}
-
- /**
- * This method is not deprecated.
- */
- public void notDeprecatedMethod() {}
-
-}
diff --git a/lint-checks/integration-tests/src/main/java/androidx/IdeaSuppressionKotlin.kt b/lint-checks/integration-tests/src/main/java/androidx/IdeaSuppressionKotlin.kt
deleted file mode 100644
index abd0612..0000000
--- a/lint-checks/integration-tests/src/main/java/androidx/IdeaSuppressionKotlin.kt
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx
-
-// Suppress deprecation warning as it generates false positives when running project lint checks.
-// This is OK as the tests check for usage of `//noinspection deprecation`.
-@Suppress("unused", "DEPRECATION")
-class IdeaSuppressionKotlin {
- /**
- * Call to a deprecated method with an inline suppression.
- */
- fun callDeprecatedMethod() {
- //noinspection deprecation
- deprecatedMethod()
-
- notDeprecatedMethod()
- }
-
- /**
- * This method is deprecated.
- */
- @Deprecated("Replaced with {@link #notDeprecatedMethod()}")
- fun deprecatedMethod() {
- }
-
- /**
- * This method is not deprecated.
- */
- fun notDeprecatedMethod() {}
-}
\ No newline at end of file
diff --git a/lint-checks/src/test/java/androidx/build/lint/IdeaSuppressionDetectorTest.kt b/lint-checks/src/test/java/androidx/build/lint/IdeaSuppressionDetectorTest.kt
index 0e7cb12..702c6088 100644
--- a/lint-checks/src/test/java/androidx/build/lint/IdeaSuppressionDetectorTest.kt
+++ b/lint-checks/src/test/java/androidx/build/lint/IdeaSuppressionDetectorTest.kt
@@ -30,37 +30,71 @@
@Test
fun `Detection of IDEA-specific suppression in Java sources`() {
- val input = arrayOf(
- javaSample("androidx.IdeaSuppressionJava")
+ val input = java(
+ "src/androidx/IdeaSuppressionJava.java",
+ """
+ public class IdeaSuppressionJava {
+
+ // Call to a deprecated method with an inline suppression.
+ public void callDeprecatedMethod() {
+ //noinspection deprecation
+ deprecatedMethod();
+
+ notDeprecatedMethod();
+ }
+
+ @Deprecated
+ public void deprecatedMethod() {}
+
+ public void notDeprecatedMethod() {}
+ }
+ """.trimIndent()
)
/* ktlint-disable max-line-length */
val expected = """
-src/androidx/IdeaSuppressionJava.java:29: Error: Uses IntelliJ-specific suppression, should use @SuppressWarnings("deprecation") [IdeaSuppression]
+src/androidx/IdeaSuppressionJava.java:5: Error: Uses IntelliJ-specific suppression, should use @SuppressWarnings("deprecation") [IdeaSuppression]
//noinspection deprecation
~~~~~~~~~~~~~~~~~~~~~~~~~~
1 errors, 0 warnings
""".trimIndent()
/* ktlint-enable max-line-length */
- check(*input).expect(expected)
+ check(input).expect(expected)
}
@Test
fun `Detection of IDEA-specific suppression in Kotlin sources`() {
- val input = arrayOf(
- ktSample("androidx.IdeaSuppressionKotlin")
+ val input = kotlin(
+ "src/androidx/IdeaSuppressionKotlin.kt",
+ """
+ class IdeaSuppressionKotlin {
+
+ // Call to a deprecated method with an inline suppression.
+ fun callDeprecatedMethod() {
+ //noinspection deprecation
+ deprecatedMethod()
+
+ notDeprecatedMethod()
+ }
+
+ @Deprecated("Replaced with {@link #notDeprecatedMethod()}")
+ fun deprecatedMethod() {}
+
+ fun notDeprecatedMethod() {}
+ }
+ """.trimIndent()
)
/* ktlint-disable max-line-length */
val expected = """
-src/androidx/IdeaSuppressionKotlin.kt:27: Error: Uses IntelliJ-specific suppression, should use @SuppressWarnings("deprecation") [IdeaSuppression]
+src/androidx/IdeaSuppressionKotlin.kt:5: Error: Uses IntelliJ-specific suppression, should use @SuppressWarnings("deprecation") [IdeaSuppression]
//noinspection deprecation
~~~~~~~~~~~~~~~~~~~~~~~~~~
1 errors, 0 warnings
""".trimIndent()
/* ktlint-enable max-line-length */
- check(*input).expect(expected)
+ check(input).expect(expected)
}
}