-
-
Notifications
You must be signed in to change notification settings - Fork 755
/
LargeClassSpec.kt
35 lines (29 loc) · 1.12 KB
/
LargeClassSpec.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package io.gitlab.arturbosch.detekt.rules.complexity
import io.github.detekt.test.utils.resourceAsPath
import io.gitlab.arturbosch.detekt.api.SourceLocation
import io.gitlab.arturbosch.detekt.test.TestConfig
import io.gitlab.arturbosch.detekt.test.assertThat
import io.gitlab.arturbosch.detekt.test.compileAndLint
import io.gitlab.arturbosch.detekt.test.lint
import org.junit.jupiter.api.Test
private fun subject(threshold: Int) = LargeClass(TestConfig(mapOf("threshold" to threshold)))
class LargeClassSpec {
@Test
fun `should detect only the nested large class which exceeds threshold 70`() {
val findings = subject(threshold = 70).lint(resourceAsPath("NestedClasses.kt"))
assertThat(findings).hasSize(1)
assertThat(findings).hasStartSourceLocations(SourceLocation(12, 15))
}
@Test
fun `should not report anything in files without classes`() {
val code = """
val i = 0
fun f() {
println()
println()
}
"""
val rule = subject(threshold = 2)
assertThat(rule.compileAndLint(code)).isEmpty()
}
}