1
1
package kickstart.validation
2
2
3
3
import com.natpryce.hamkrest.assertion.assertThat
4
+ import dev.minutest.Tests
5
+ import dev.minutest.junit.JUnit5Minutests
6
+ import dev.minutest.rootContext
7
+ import dev.minutest.test
4
8
import kickstart.isFailure
5
- import kotlin.test.Test
6
9
7
- class FailureTest {
8
- @Test
9
- fun `always fails, reporting offending value` () {
10
- val validate = failure(Key (" invalid" ))
11
- val result = validate(" value" )
12
- assertThat(result, isFailure<String >(Violation (Key (" invalid" ), listOf (" value" ))))
13
- }
14
- }
15
10
16
- class NotBlankTest {
17
- @Test
18
- fun `fails if value is null, reporting no value` () {
19
- val validate = notBlank(Key (" null" ))
20
- val result = validate(null )
21
- assertThat(result, isFailure<String >(Violation (Key (" null" ))))
11
+ class ValidationRulesTest : JUnit5Minutests {
12
+ @Tests
13
+ fun `failure tests` () = rootContext {
14
+ test(" always fails, reporting offending value" ) {
15
+ val validate = failure(Key (" invalid" ))
16
+ val result = validate(" value" )
17
+ assertThat(result, isFailure<String >(Violation (Key (" invalid" ), listOf (" value" ))))
18
+ }
22
19
}
23
20
24
- @Test
25
- fun `fails if value is blank, still reporting no value` () {
26
- val validate = notBlank(Key (" blank" ))
27
- val result = validate(" " )
28
- assertThat(result, isFailure<String >(Violation (Key (" blank" ))))
21
+ @Tests
22
+ fun `not blank tests` () = rootContext {
23
+ context(" value is null" ) {
24
+ test(" fails and reports no value" ) {
25
+ val validate = notBlank(Key (" null" ))
26
+ val result = validate(null )
27
+ assertThat(result, isFailure<String >(Violation (Key (" null" ))))
28
+ }
29
+ }
30
+
31
+ context(" value is blank" ) {
32
+ test(" fails if value is blank, still reporting no value" ) {
33
+ val validate = notBlank(Key (" blank" ))
34
+ val result = validate(" " )
35
+ assertThat(result, isFailure<String >(Violation (Key (" blank" ))))
36
+ }
37
+ }
29
38
}
30
39
}
0 commit comments