Skip to content

Commit

Permalink
Test case for issue detekt#1573
Browse files Browse the repository at this point in the history
Shows that forbidding net.example.R.dimen also forbids
net.example.R.dimension.
  • Loading branch information
josephlbarnett committed Apr 3, 2019
1 parent b414beb commit 9abd1a9
Showing 1 changed file with 15 additions and 4 deletions.
Expand Up @@ -16,6 +16,7 @@ class ForbiddenImportSpec : Spek({
import com.example.R.string
import net.example.R.dimen
import net.example.R.dimension
"""

it("should report nothing by default") {
Expand All @@ -39,12 +40,16 @@ class ForbiddenImportSpec : Spek({
}

it("should report kotlin.SinceKotlin when specified via fully qualified name") {
val findings = ForbiddenImport(TestConfig(mapOf(ForbiddenImport.IMPORTS to "kotlin.SinceKotlin"))).lint(code)
val findings =
ForbiddenImport(TestConfig(mapOf(ForbiddenImport.IMPORTS to "kotlin.SinceKotlin"))).lint(code)
assertThat(findings).hasSize(1)
}

it("should report kotlin.SinceKotlin and kotlin.jvm.JvmField when specified via fully qualified names") {
val findings = ForbiddenImport(TestConfig(mapOf(ForbiddenImport.IMPORTS to "kotlin.SinceKotlin,kotlin.jvm.JvmField"))).lint(code)
val findings =
ForbiddenImport(TestConfig(mapOf(ForbiddenImport.IMPORTS to "kotlin.SinceKotlin,kotlin.jvm.JvmField"))).lint(
code
)
assertThat(findings).hasSize(2)
}

Expand All @@ -53,9 +58,15 @@ class ForbiddenImportSpec : Spek({
assertThat(findings).hasSize(1)
}

it("should report both com.example.R.string and net.example.R.dimen") {
it("should report all of com.example.R.string, net.example.R.dimen, and net.example.R.dimension") {
val findings = ForbiddenImport(TestConfig(mapOf(ForbiddenImport.IMPORTS to "*.R.*"))).lint(code)
assertThat(findings).hasSize(2)
assertThat(findings).hasSize(3)
}

it("should report net.example.R.dimen but not net.example.R.dimension") {
val findings =
ForbiddenImport(TestConfig(mapOf(ForbiddenImport.IMPORTS to "net.example.R.dimen"))).lint(code)
assertThat(findings).hasSize(1)
}
}
})

0 comments on commit 9abd1a9

Please sign in to comment.