1 /* 2 * Copyright 2023 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 BanThreadSleepTest : 27 AbstractLintDetectorTest( 28 useDetector = BanThreadSleep(), 29 useIssues = listOf(BanThreadSleep.ISSUE), 30 stubs = arrayOf(Stubs.Keep), 31 ) { 32 33 @Test Detection of Thread#sleep in Java sourcesnull34 fun `Detection of Thread#sleep in Java sources`() { 35 val input = 36 arrayOf( 37 javaSample("androidx.ThreadSleepUsageJava"), 38 ) 39 40 val expected = 41 """ 42 src/androidx/ThreadSleepUsageJava.java:21: Error: Uses Thread.sleep() [BanThreadSleep] 43 Thread.sleep(1000); 44 ~~~~~ 45 1 errors, 0 warnings 46 """ 47 .trimIndent() 48 49 check(*input).expect(expected) 50 } 51 52 @Test Detection of Thread#sleep in Kotlin sourcesnull53 fun `Detection of Thread#sleep in Kotlin sources`() { 54 val input = 55 arrayOf( 56 ktSample("androidx.ThreadSleepUsageKotlin"), 57 ) 58 59 val expected = 60 """ 61 src/androidx/ThreadSleepUsageKotlin.kt:21: Error: Uses Thread.sleep() [BanThreadSleep] 62 Thread.sleep(1000) 63 ~~~~~ 64 1 errors, 0 warnings 65 """ 66 .trimIndent() 67 68 check(*input).expect(expected) 69 } 70 } 71