/
EmptyBlocksMultiRuleSpec.kt
64 lines (53 loc) · 1.82 KB
/
EmptyBlocksMultiRuleSpec.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package io.gitlab.arturbosch.detekt.rules.empty
import io.github.detekt.test.utils.compileForTest
import io.github.detekt.test.utils.resourceAsPath
import io.gitlab.arturbosch.detekt.test.compileAndLint
import io.gitlab.arturbosch.detekt.test.lint
import io.gitlab.arturbosch.detekt.test.yamlConfig
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class EmptyBlocksMultiRuleSpec {
private val file = compileForTest(resourceAsPath("Empty.kt"))
private lateinit var subject: EmptyBlocks
@BeforeEach
fun createSubject() {
subject = EmptyBlocks()
}
@Test
fun `should report one finding per rule`() {
val findings = subject.lint(file)
// -1 because the empty kt file rule doesn't get triggered in the 'Empty' test file
val rulesSize = subject.rules.size - 1
assertThat(findings).hasSize(rulesSize)
}
@Test
fun `should not report any as all empty block rules are deactivated`() {
val config = yamlConfig("deactivated-empty-blocks.yml")
val ruleSet = EmptyCodeProvider().instance(config)
@Suppress("DEPRECATION")
val findings = ruleSet.accept(file)
assertThat(findings).isEmpty()
}
@Test
fun `reports an empty kt file`() {
assertThat(subject.compileAndLint("")).hasSize(1)
}
@Test
fun `reports no duplicated findings - issue #1605`() {
val findings = subject.compileAndLint(
"""
class EmptyBlocks {
class EmptyClass {}
fun exceptionHandling() {
try {
println()
} finally {
}
}
}
"""
)
assertThat(findings).hasSize(2)
}
}