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 BanParcelableUsageTest : 27 AbstractLintDetectorTest( 28 useDetector = BanParcelableUsage(), 29 useIssues = listOf(BanParcelableUsage.ISSUE), 30 ) { 31 32 @Test Detection of Parcelable usage in Java sourcesnull33 fun `Detection of Parcelable usage in Java sources`() { 34 val input = 35 arrayOf( 36 javaSample("androidx.ParcelableUsageJava"), 37 ) 38 39 val expected = 40 """ 41 src/androidx/ParcelableUsageJava.java:25: Error: Class implements android.os.Parcelable [BanParcelableUsage] 42 public class ParcelableUsageJava implements Parcelable { 43 ~~~~~~~~~~~~~~~~~~~ 44 1 errors, 0 warnings 45 """ 46 .trimIndent() 47 48 check(*input).expect(expected) 49 } 50 51 @Test Detection of Parcelable usage in Kotlin sourcesnull52 fun `Detection of Parcelable usage in Kotlin sources`() { 53 val input = 54 arrayOf( 55 ktSample("androidx.ParcelableUsageKotlin"), 56 ) 57 58 val expected = 59 """ 60 src/androidx/ParcelableUsageKotlin.kt:23: Error: Class implements android.os.Parcelable [BanParcelableUsage] 61 open class ParcelableUsageKotlin protected constructor(parcel: Parcel) : Parcelable { 62 ~~~~~~~~~~~~~~~~~~~~~ 63 1 errors, 0 warnings 64 """ 65 .trimIndent() 66 67 check(*input).expect(expected) 68 } 69 } 70