LoadingState { JsonValue childFor(String key) { Object rawChild = schemaJson .canBeMappedTo(JsonObject.class, obj -> getRawChildOfObject(obj, key)) .orMappedTo(JsonArray.class, array -> getRawElemOfArray(array, key)) .requireAny(); LoadingState childLs = new LoadingState( config, pointerSchemas, rootSchemaJson, rawChild, id, pointerToCurrentObj.addPointerSegment(key), subschemaRegistries ); return childLs.schemaJson; } LoadingState(LoaderConfig config,
        Map<String, ReferenceKnot> pointerSchemas,
        Object rootSchemaJson,
        Object schemaJson,
        URI parentScopeId,
        SchemaLocation pointerToCurrentObj);   LoadingState(LoaderConfig config,
            Map<String, ReferenceKnot> pointerSchemas,
            Object rootSchemaJson,
            Object schemaJson,
            URI parentScopeId,
            SchemaLocation pointerToCurrentObj,
            Map<JsonValue, SubschemaRegistry> subschemaRegistries);   }
@Test public void childForString() { LoadingState ls = helloWorldObjState(); LoadingState actual = ls.childFor("hello").ls; assertEquals(new SchemaLocation(asList("hello")), actual.pointerToCurrentObj); }
@Test public void childForSecond() { LoadingState ls = helloWorldObjState(); LoadingState actual = ls.childFor("hello").requireObject().childFor("world").ls; assertEquals(new SchemaLocation(asList("hello", "world")), actual.pointerToCurrentObj); }
@Test public void childForArrayIndex() { LoadingState subject = singleElemArrayState(); LoadingState actual = subject.childFor(0).ls; assertEquals(new SchemaLocation(asList("0")), actual.pointerToCurrentObj); }
@Test public void testChildForFailure_NotFound() { LoadingState ls = helloWorldObjState(); try { ls.childFor("nonexistent"); fail("did not throw exception for nonexistent key"); } catch (SchemaException e) { SchemaException expected = new SchemaException("#", "key [nonexistent] not found"); assertEquals(expected, e); } }
@Test public void testChildForArrayFailure_NotFound() { LoadingState subject = singleElemArrayState(); try { subject.childFor(1); fail("did not throw exception"); } catch (SchemaException e) { SchemaException expected = new SchemaException("#", "array index [1] is out of bounds"); assertEquals(expected, e); } }
@Test public void invalidArrayIndex() { try { singleElemArrayState().childFor("key"); fail("did not throw exception"); } catch (SchemaException e) { SchemaException expected = new SchemaException("#", "[key] is not an array index"); assertEquals(expected, e); } }