@@ -80,15 +80,22 @@ public void multipleSchemaDepViolation() {
80
80
subject .validate (OBJECTS .get ("schemaDepViolation" ));
81
81
Assert .fail ("did not throw ValidationException" );
82
82
} catch (ValidationException e ) {
83
- ValidationException billingAddressFailure = e .getCausingExceptions ().get (0 )
84
- .getCausingExceptions ().get (0 );
83
+ ValidationException creditCardFailure = e .getCausingExceptions ().get (0 );
84
+ ValidationException ageFailure = e .getCausingExceptions ().get (1 );
85
+ // due to schemaDeps being stored in (unsorted) HashMap, the exceptions may need to be swapped
86
+ if (creditCardFailure .getCausingExceptions ().size () == 0 ) {
87
+ ValidationException tmp = creditCardFailure ;
88
+ creditCardFailure = ageFailure ;
89
+ ageFailure = tmp ;
90
+ }
91
+ ValidationException billingAddressFailure = creditCardFailure .getCausingExceptions ().get (0 );
85
92
Assert .assertEquals ("#/billing_address" , billingAddressFailure .getPointerToViolation ());
86
93
Assert .assertEquals (billingAddressSchema , billingAddressFailure .getViolatedSchema ());
87
- ValidationException billingNameFailure = e . getCausingExceptions (). get ( 0 )
94
+ ValidationException billingNameFailure = creditCardFailure
88
95
.getCausingExceptions ().get (1 );
89
96
Assert .assertEquals ("#/billing_name" , billingNameFailure .getPointerToViolation ());
90
97
Assert .assertEquals (billingNameSchema , billingNameFailure .getViolatedSchema ());
91
- ValidationException ageFailure = e . getCausingExceptions (). get ( 1 );
98
+
92
99
Assert .assertEquals ("#" , ageFailure .getPointerToViolation ());
93
100
Assert .assertEquals ("required key [age] not found" , ageFailure .getMessage ());
94
101
}
@@ -216,6 +223,21 @@ public void schemaForNoAdditionalProperties() {
216
223
.schemaOfAdditionalProperties (BooleanSchema .INSTANCE ).build ();
217
224
}
218
225
226
+ @ Test
227
+ public void testImmutability () {
228
+ ObjectSchema .Builder builder = ObjectSchema .builder ();
229
+ builder .propertyDependency ("a" , "b" );
230
+ builder .schemaDependency ("a" , BooleanSchema .INSTANCE );
231
+ builder .patternProperty ("aaa" , BooleanSchema .INSTANCE );
232
+ ObjectSchema schema = builder .build ();
233
+ builder .propertyDependency ("c" , "a" );
234
+ builder .schemaDependency ("b" , BooleanSchema .INSTANCE );
235
+ builder .patternProperty ("bbb" , BooleanSchema .INSTANCE );
236
+ Assert .assertEquals (1 , schema .getPropertyDependencies ().size ());
237
+ Assert .assertEquals (1 , schema .getSchemaDependencies ().size ());
238
+ Assert .assertEquals (1 , schema .getPatternProperties ().size ());
239
+ }
240
+
219
241
@ Test
220
242
public void typeFailure () {
221
243
TestSupport .expectFailure (ObjectSchema .builder ().build (), "#" , "a" );
0 commit comments