Skip to content

Instantly share code, notes, and snippets.

@fbcbl
Created February 13, 2020 13:43
Show Gist options
  • Save fbcbl/a596b1fa15c8c09e10ce78402ca96668 to your computer and use it in GitHub Desktop.
Save fbcbl/a596b1fa15c8c09e10ce78402ca96668 to your computer and use it in GitHub Desktop.
AndroidLogDetectorTest - Full Test
package com.fabiocarballo.rules
import com.android.tools.lint.checks.infrastructure.LintDetectorTest
import com.android.tools.lint.detector.api.Detector
import com.android.tools.lint.detector.api.Issue
import com.fabiocarballo.rules.Stubs.ANDROID_LOG_IMPL_JAVA
import org.junit.jupiter.api.Test
class AndroidLogDetectorTest : LintDetectorTest() {
@Test
fun shouldDetectUsageOfAndroidLog() {
val stubFile = kotlin(
"""
package com.fabiocarballo.lint
import android.util.Log
class Dog {
fun bark() {
Log.d(TAG, "woof! woof!")
}
}
"""
).indented()
val lintResult = lint()
.files(ANDROID_LOG_IMPL_JAVA, stubFile)
.run()
lintResult
.expectErrorCount(1)
.expect(
"""
src/com/fabiocarballo/lint/Dog.kt:8: Error: android.util.Log usage is forbidden. [AndroidLogDetector]
Log.d(TAG, "woof! woof!")
~~~~~~~~~~~~~~~~~~~~~~~~~
1 errors, 0 warnings
""".trimIndent()
)
}
override fun getDetector(): Detector = AndroidLogDetector()
override fun getIssues(): MutableList<Issue> = mutableListOf(AndroidLogDetector.ISSUE)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment