Skip to content

Instantly share code, notes, and snippets.

@fbcbl
Created February 13, 2020 13:43
Show Gist options
  • Select an option

  • Save fbcbl/a596b1fa15c8c09e10ce78402ca96668 to your computer and use it in GitHub Desktop.

Select an option

Save fbcbl/a596b1fa15c8c09e10ce78402ca96668 to your computer and use it in GitHub Desktop.

Revisions

  1. fbcbl created this gist Feb 13, 2020.
    47 changes: 47 additions & 0 deletions AndroidLogDetectorTest.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    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)
    }