1 /* 2 * Copyright 2021 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 @file:Suppress("UnstableApiUsage") 18 19 package androidx.build.lint 20 21 import org.junit.Test 22 import org.junit.runner.RunWith 23 import org.junit.runners.JUnit4 24 25 @RunWith(JUnit4::class) 26 class BanKeepAnnotationTest : 27 AbstractLintDetectorTest( 28 useDetector = BanKeepAnnotation(), 29 useIssues = listOf(BanKeepAnnotation.ISSUE), 30 stubs = arrayOf(Stubs.Keep), 31 ) { 32 33 @Test Detection of Keep annotation in Java sourcesnull34 fun `Detection of Keep annotation in Java sources`() { 35 val input = 36 arrayOf( 37 javaSample("androidx.KeepAnnotationUsageJava"), 38 ) 39 40 val expected = 41 """ 42 src/androidx/KeepAnnotationUsageJava.java:21: Error: Uses @Keep annotation [BanKeepAnnotation] 43 @Keep 44 ~~~~~ 45 1 errors, 0 warnings 46 """ 47 .trimIndent() 48 49 check(*input).expect(expected) 50 } 51 52 @Test Detection of Keep annotation in Kotlin sourcesnull53 fun `Detection of Keep annotation in Kotlin sources`() { 54 val input = 55 arrayOf( 56 ktSample("androidx.KeepAnnotationUsageKotlin"), 57 ) 58 59 val expected = 60 """ 61 src/androidx/KeepAnnotationUsageKotlin.kt:21: Error: Uses @Keep annotation [BanKeepAnnotation] 62 @Keep class KeepAnnotationUsageKotlin 63 ~~~~~ 64 1 errors, 0 warnings 65 """ 66 .trimIndent() 67 68 check(*input).expect(expected) 69 } 70 } 71