/
RuleSetConfigPropertySpec.kt
67 lines (56 loc) · 2.05 KB
/
RuleSetConfigPropertySpec.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
65
66
67
package io.gitlab.arturbosch.detekt.api.internal
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.RuleSet
import io.gitlab.arturbosch.detekt.api.RuleSetProvider
import io.gitlab.arturbosch.detekt.test.TestConfig
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
class RuleSetConfigPropertySpec {
@Nested
inner class `boolean property` {
@Test
fun `reads the value in config if present`() {
assertThat(TestRuleSetProvider.android.value(TestConfig("android" to "false")))
.isEqualTo(false)
}
@Test
fun `uses the default value in config if not present`() {
assertThat(TestRuleSetProvider.android.value(TestConfig()))
.isEqualTo(true)
}
}
@Nested
inner class `int property` {
@Test
fun `reads the value in config if present`() {
assertThat(TestRuleSetProvider.number.value(TestConfig("number" to "37"))).isEqualTo(37)
}
@Test
fun `uses the default value in config if not present`() {
assertThat(TestRuleSetProvider.number.value(TestConfig())).isEqualTo(42)
}
}
@Nested
inner class `string property` {
@Test
fun `reads the value in config if present`() {
assertThat(TestRuleSetProvider.fileName.value(TestConfig("fileName" to "main.kt")))
.isEqualTo("main.kt")
}
@Test
fun `uses the default value in config if not present`() {
assertThat(TestRuleSetProvider.fileName.value(TestConfig()))
.isEqualTo("test.kt")
}
}
}
private class TestRuleSetProvider : RuleSetProvider {
override val ruleSetId: String = "testRuleSetId"
override fun instance(config: Config): RuleSet = RuleSet(ruleSetId, emptyList())
companion object {
val android by ruleSetConfig(true)
val fileName by ruleSetConfig("test.kt")
val number by ruleSetConfig(42)
}
}