1 package com.android.internal.systemui.lint 2 3 import com.android.tools.lint.checks.infrastructure.LintDetectorTest 4 import com.android.tools.lint.checks.infrastructure.TestLintTask 5 import java.io.File 6 import org.junit.ClassRule 7 import org.junit.rules.TestRule 8 import org.junit.runner.Description 9 import org.junit.runner.RunWith 10 import org.junit.runners.JUnit4 11 import org.junit.runners.model.Statement 12 13 @Suppress("UnstableApiUsage") 14 @RunWith(JUnit4::class) 15 abstract class SystemUILintDetectorTest : LintDetectorTest() { 16 17 companion object { 18 @ClassRule 19 @JvmField 20 val libraryChecker: LibraryExists = 21 LibraryExists("framework.jar", "androidx.annotation_annotation.jar") 22 } 23 24 class LibraryExists(vararg val libraryNames: String) : TestRule { 25 override fun apply(base: Statement, description: Description): Statement { 26 return object : Statement() { 27 override fun evaluate() { 28 for (libName in libraryNames) { 29 val libFile = File(libName) 30 if (!libFile.canonicalFile.exists()) { 31 throw Exception( 32 "Could not find $libName in the test's working directory. " + 33 "File ${libFile.absolutePath} does not exist." 34 ) 35 } 36 } 37 base.evaluate() 38 } 39 } 40 } 41 } 42 /** 43 * Customize the lint task to disable SDK usage completely. This ensures that running the tests 44 * in Android Studio has the same result as running the tests in atest 45 */ 46 override fun lint(): TestLintTask = 47 super.lint().allowMissingSdk(true).sdkHome(File("/dev/null")) 48 } 49