Skip to content

Commit 3591b6c

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 17f006e commit 3591b6c

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55

66
import com.retailsvc.http.ValidationException;
77
import com.retailsvc.http.spec.schema.AllOfSchema;
8+
import com.retailsvc.http.spec.schema.AlwaysSchema;
89
import com.retailsvc.http.spec.schema.AnyOfSchema;
910
import com.retailsvc.http.spec.schema.BooleanSchema;
11+
import com.retailsvc.http.spec.schema.NeverSchema;
1012
import com.retailsvc.http.spec.schema.NotSchema;
1113
import com.retailsvc.http.spec.schema.NullSchema;
1214
import com.retailsvc.http.spec.schema.OneOfSchema;
1315
import com.retailsvc.http.spec.schema.StringSchema;
1416
import com.retailsvc.http.spec.schema.TypeName;
1517
import java.util.List;
18+
import java.util.Map;
1619
import java.util.Set;
1720
import org.junit.jupiter.api.Test;
1821

@@ -172,4 +175,52 @@ void anyOfMatchesNullViaNullSchema() {
172175
var schema = new AnyOfSchema(List.of(stringSchema(1, null), new NullSchema()));
173176
v.validate(null, schema, "/v");
174177
}
178+
179+
@Test
180+
void alwaysSchemaAcceptsString() {
181+
v.validate("anything", new AlwaysSchema(), "/v");
182+
}
183+
184+
@Test
185+
void alwaysSchemaAcceptsInteger() {
186+
v.validate(42, new AlwaysSchema(), "/v");
187+
}
188+
189+
@Test
190+
void alwaysSchemaAcceptsObject() {
191+
v.validate(Map.of("a", 1), new AlwaysSchema(), "/v");
192+
}
193+
194+
@Test
195+
void alwaysSchemaAcceptsNull() {
196+
v.validate(null, new AlwaysSchema(), "/v");
197+
}
198+
199+
@Test
200+
void neverSchemaRejectsString() {
201+
assertThatThrownBy(() -> v.validate("anything", new NeverSchema(), "/v"))
202+
.isInstanceOf(ValidationException.class)
203+
.satisfies(
204+
t -> {
205+
var err = ((ValidationException) t).error();
206+
assertThat(err.keyword()).isEqualTo("false");
207+
assertThat(err.message()).contains("rejects all values");
208+
});
209+
}
210+
211+
@Test
212+
void neverSchemaRejectsInteger() {
213+
assertThatThrownBy(() -> v.validate(42, new NeverSchema(), "/v"))
214+
.isInstanceOf(ValidationException.class)
215+
.extracting(t -> ((ValidationException) t).error().keyword())
216+
.isEqualTo("false");
217+
}
218+
219+
@Test
220+
void neverSchemaRejectsNull() {
221+
assertThatThrownBy(() -> v.validate(null, new NeverSchema(), "/v"))
222+
.isInstanceOf(ValidationException.class)
223+
.extracting(t -> ((ValidationException) t).error().keyword())
224+
.isEqualTo("false");
225+
}
175226
}

0 commit comments

Comments
 (0)