@@ -42,49 +42,67 @@ internal class ValidatorProcessorKotlinSpec : ValidatorCompilationTest() {
42
42
@Nested inner class
43
43
Discover {
44
44
45
- private val topLevelValidator = kotlinFile(" TimestampValidator" , """
46
- package io.spine.validation.java.ksp.test
47
-
48
- import io.spine.validation.api.DetectedViolation
49
- import io.spine.validation.api.MessageValidator
50
- import io.spine.validation.api.Validator
51
- import com.google.protobuf.Timestamp
52
-
45
+ @Test
46
+ fun `a top level validator` () = assertDiscovered(
47
+ """
53
48
@Validator(Timestamp::class)
54
49
public class TimestampValidator : MessageValidator<Timestamp> {
55
50
public override fun validate(message: Timestamp): List<DetectedViolation> {
56
51
return emptyList() // Always valid.
57
52
}
58
- }
59
- """ .trimIndent())
53
+ }
54
+ """ .trimIndent(),
55
+ " TimestampValidator"
56
+ )
60
57
61
58
@Test
62
- fun `a top level validator` () {
63
- compilation.apply {
64
- sources = listOf (topLevelValidator)
65
- }
66
-
59
+ fun `a nested validator` () = assertDiscovered(
60
+ """
61
+ public class Outer {
62
+ @Validator(Timestamp::class)
63
+ public class TimestampValidator : MessageValidator<Timestamp> {
64
+ public override fun validate(message: Timestamp): List<DetectedViolation> {
65
+ return emptyList() // Always valid.
66
+ }
67
+ }
68
+ }
69
+ """ .trimIndent(),
70
+ " Outer.TimestampValidator"
71
+ )
72
+
73
+ private fun assertDiscovered (declaration : String , expected : String ) {
74
+ val sourceFile = kotlinFile(" TimestampValidator" , """
75
+ package $VALIDATOR_PACKAGE
76
+
77
+ $IMPORTS
78
+
79
+ $declaration
80
+ """ .trimIndent()
81
+ )
82
+
83
+ compilation.sources = listOf (sourceFile)
67
84
val result = compilation.compileSilently()
68
85
result.exitCode shouldBe OK
69
86
70
87
val discovered = compilation.kspSourcesDir
71
88
.resolve(" resources" )
72
89
.resolve(DiscoveredValidators .RESOURCES_LOCATION )
90
+
73
91
with (discovered) {
74
92
exists() shouldBe true
75
- readText().trim() shouldBe " com.google.protobuf.Timestamp:io.spine.validation.java.ksp.test.TimestampValidator "
93
+ readText() shouldBe " $MESSAGE_CLASS : $VALIDATOR_PACKAGE . $expected \n "
76
94
}
77
95
}
78
-
79
- @Test
80
- fun `a nested validator` () {
81
-
82
- }
83
96
}
84
97
85
98
@Nested inner class
86
99
RejectValidator {
87
100
101
+ @Test
102
+ fun `declared as inner class` () {
103
+
104
+ }
105
+
88
106
@Test
89
107
fun `not implementing 'MessageValidator' interface` () {
90
108
@@ -105,4 +123,15 @@ internal class ValidatorProcessorKotlinSpec : ValidatorCompilationTest() {
105
123
106
124
}
107
125
}
126
+
127
+ companion object {
128
+ private const val MESSAGE_CLASS = " com.google.protobuf.Timestamp"
129
+ private const val VALIDATOR_PACKAGE = " io.spine.validation.java.ksp.test"
130
+ private val IMPORTS = """
131
+ import io.spine.validation.api.DetectedViolation
132
+ import io.spine.validation.api.MessageValidator
133
+ import io.spine.validation.api.Validator
134
+ import com.google.protobuf.Timestamp
135
+ """ .trimIndent()
136
+ }
108
137
}
0 commit comments