ValidatingVisitor extends Visitor { boolean passesTypeCheck(Class<?> expectedType, boolean schemaRequiresType, Boolean nullable) { if (isNull(subject)) { if (schemaRequiresType && !Boolean.TRUE.equals(nullable)) { failureReporter.failure(expectedType, subject); } return false; } if (expectedType.isAssignableFrom(subject.getClass())) { return true; } if (schemaRequiresType) { failureReporter.failure(expectedType, subject); } return false; } ValidatingVisitor(Object subject, ValidationFailureReporter failureReporter, ReadWriteValidator readWriteValidator,
            ValidationListener validationListener);   }
@Test public void passesTypeCheck_otherType_noRequires() { ValidatingVisitor subject = new ValidatingVisitor("string", reporter, null, null); assertFalse(subject.passesTypeCheck(JSONObject.class, false, null)); verifyZeroInteractions(reporter); }
@Test public void passesTypeCheck_otherType_nullPermitted_nullObject() { ValidatingVisitor subject = new ValidatingVisitor(JSONObject.NULL, reporter, null, null); assertFalse(subject.passesTypeCheck(JSONObject.class, true, Boolean.TRUE)); verifyZeroInteractions(reporter); }
@Test public void passesTypeCheck_otherType_nullPermitted_nullReference() { ValidatingVisitor subject = new ValidatingVisitor(null, reporter, null, null); assertFalse(subject.passesTypeCheck(JSONObject.class, true, Boolean.TRUE)); verifyZeroInteractions(reporter); }
@Test public void passesTypeCheck_sameType() { ValidatingVisitor subject = new ValidatingVisitor("string", reporter, null, null); assertTrue(subject.passesTypeCheck(String.class, true, Boolean.TRUE)); verifyZeroInteractions(reporter); }