diff --git a/src/test/java/org/burningwave/json/ValidatorTest.java b/src/test/java/org/burningwave/json/ValidatorTest.java index 0441cc1..735ca6e 100644 --- a/src/test/java/org/burningwave/json/ValidatorTest.java +++ b/src/test/java/org/burningwave/json/ValidatorTest.java @@ -13,10 +13,13 @@ class ValidatorTest extends BaseTest { void validateTestOne() { testThrow(() -> { facade.validator().registerCheck( - //Check + //Checking whether a value in any field marked as required (e.g.: @JsonProperty(value = "answer", required = true)) is null Check.forAll().checkMandatory(), - Check.forAllStringValues().execute(validationContext -> { - + //Checking whether a string value in any field is empty + Check.forAllStringValues().execute(pathValidationContext -> { + if (pathValidationContext.getValue() != null && pathValidationContext.getValue().trim().equals("")) { + pathValidationContext.rejectValue("IS_EMPTY", "is empty"); + } }) ); @@ -25,7 +28,6 @@ void validateTestOne() { ObjectHandlerTest.class.getClassLoader().getResourceAsStream("quiz-to-be-validated.json"), Root.class ); - ObjectHandler objectHandler = facade.newObjectHandler(jsonObject); Collection exceptions = facade.validator().validate(Validation.Config.forJsonObject(jsonObject).withCompleteValidation()); for (Throwable exc : exceptions) { System.err.println(exc.getMessage()); diff --git a/src/test/resources/quiz-to-be-validated.json b/src/test/resources/quiz-to-be-validated.json index 10972d0..1499c0a 100644 --- a/src/test/resources/quiz-to-be-validated.json +++ b/src/test/resources/quiz-to-be-validated.json @@ -27,7 +27,7 @@ "1", "2", "3", - "4" + "" ], "answer": "4" }