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 @RunWith(JUnit4::class)
14 abstract class SystemUILintDetectorTest : LintDetectorTest() {
15 
16     companion object {
17         @ClassRule @JvmField val libraryChecker: LibraryExists = LibraryExists(*libraryNames)
18     }
19 
20     class LibraryExists(vararg val libraryNames: String) : TestRule {
applynull21         override fun apply(base: Statement, description: Description): Statement {
22             return object : Statement() {
23                 override fun evaluate() {
24                     for (libName in libraryNames) {
25                         val libFile = File(libName)
26                         if (!libFile.canonicalFile.exists()) {
27                             throw Exception(
28                                 "Could not find $libName in the test's working directory. " +
29                                     "File ${libFile.absolutePath} does not exist."
30                             )
31                         }
32                     }
33                     base.evaluate()
34                 }
35             }
36         }
37     }
38     /**
39      * Customize the lint task to disable SDK usage completely. This ensures that running the tests
40      * in Android Studio has the same result as running the tests in atest
41      */
lintnull42     override fun lint(): TestLintTask =
43         super.lint().allowMissingSdk(true).sdkHome(File("/dev/null"))
44 }
45