/
MultiRuleCollectorSpec.kt
58 lines (49 loc) · 1.7 KB
/
MultiRuleCollectorSpec.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
package io.gitlab.arturbosch.detekt.generator.collection
import io.gitlab.arturbosch.detekt.generator.collection.exception.InvalidDocumentationException
import io.gitlab.arturbosch.detekt.generator.util.run
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class MultiRuleCollectorSpec {
private lateinit var subject: MultiRuleCollector
@BeforeEach
fun createSubject() {
subject = MultiRuleCollector()
}
@Test
fun `collects no MultiRule when no class is extended`() {
val code = "class MyRule"
assertThat(subject.run(code)).isEmpty()
}
@Test
fun `collects no rules when no MultiRule class is extended`() {
val code = "class MyRule : Other"
assertThat(subject.run(code)).isEmpty()
}
@Test
fun `throws when no rules are added`() {
val code = "class MyRule : MultiRule"
assertThatExceptionOfType(InvalidDocumentationException::class.java).isThrownBy {
subject.run(code)
}
}
@Test
fun `collects all rules in fields and in the rule property`() {
val code = """
class MyRule : MultiRule {
val p1 = Rule3()
val p2 = Rule4()
override val rules: List<Rule> = listOf(
Rule1(),
Rule2(),
p1,
p2
)
}
""".trimIndent()
val items = subject.run(code)
assertThat(items[0].rules).hasSize(4)
assertThat(items[0].rules).contains("Rule1", "Rule2", "Rule3", "Rule4")
}
}