Skip to content

Commit 3486e86

Browse files
thcedclaude
andcommitted
feat: Validate AlwaysSchema and NeverSchema in DefaultValidator
Pins the existing case branches (added in Task 1 to keep the sealed switch compiling) with seven new unit tests covering pass/reject across string / integer / object / null inputs for both AlwaysSchema and NeverSchema. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d353b23 commit 3486e86

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

src/test/java/com/retailsvc/http/validate/DefaultValidatorDispatchTest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.retailsvc.http.validate;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
34
import static org.assertj.core.api.Assertions.assertThatThrownBy;
45

56
import com.retailsvc.http.ValidationException;
7+
import com.retailsvc.http.spec.schema.AlwaysSchema;
68
import com.retailsvc.http.spec.schema.BooleanSchema;
9+
import com.retailsvc.http.spec.schema.NeverSchema;
710
import com.retailsvc.http.spec.schema.NullSchema;
811
import com.retailsvc.http.spec.schema.OneOfSchema;
912
import com.retailsvc.http.spec.schema.TypeName;
1013
import java.util.List;
14+
import java.util.Map;
1115
import java.util.Set;
1216
import org.junit.jupiter.api.Test;
1317

@@ -49,4 +53,52 @@ void combinatorThrowsUnsupported() {
4953
assertThatThrownBy(() -> v.validate("x", schema, "/v"))
5054
.isInstanceOf(UnsupportedOperationException.class);
5155
}
56+
57+
@Test
58+
void alwaysSchemaAcceptsString() {
59+
v.validate("anything", new AlwaysSchema(), "/v");
60+
}
61+
62+
@Test
63+
void alwaysSchemaAcceptsInteger() {
64+
v.validate(42, new AlwaysSchema(), "/v");
65+
}
66+
67+
@Test
68+
void alwaysSchemaAcceptsObject() {
69+
v.validate(Map.of("a", 1), new AlwaysSchema(), "/v");
70+
}
71+
72+
@Test
73+
void alwaysSchemaAcceptsNull() {
74+
v.validate(null, new AlwaysSchema(), "/v");
75+
}
76+
77+
@Test
78+
void neverSchemaRejectsString() {
79+
assertThatThrownBy(() -> v.validate("anything", new NeverSchema(), "/v"))
80+
.isInstanceOf(ValidationException.class)
81+
.satisfies(
82+
t -> {
83+
var err = ((ValidationException) t).error();
84+
assertThat(err.keyword()).isEqualTo("false");
85+
assertThat(err.message()).contains("rejects all values");
86+
});
87+
}
88+
89+
@Test
90+
void neverSchemaRejectsInteger() {
91+
assertThatThrownBy(() -> v.validate(42, new NeverSchema(), "/v"))
92+
.isInstanceOf(ValidationException.class)
93+
.extracting(t -> ((ValidationException) t).error().keyword())
94+
.isEqualTo("false");
95+
}
96+
97+
@Test
98+
void neverSchemaRejectsNull() {
99+
assertThatThrownBy(() -> v.validate(null, new NeverSchema(), "/v"))
100+
.isInstanceOf(ValidationException.class)
101+
.extracting(t -> ((ValidationException) t).error().keyword())
102+
.isEqualTo("false");
103+
}
52104
}

0 commit comments

Comments
 (0)