### Question:
DataShapeUtils { static Optional<DataShape> buildDataShape(final JsonNode root) { if (root == null) { return Optional.empty(); } final DataShape.Builder builder = new DataShape.Builder(); addKindAndTypeTo(builder, root); addValueTo(root, "name", builder::name); addValueTo(root, "description", builder::description); addValueTo(root, "specification", builder::specification); addMetadataTo(builder, root); addVariantsTo(builder, root); return Optional.of(builder.build()); } private  DataShapeUtils();   }### Answer:
@Test public void testCompositeJavaDataShape() throws Exception { final ObjectNode ds = new ObjectMapper().createObjectNode(); ds.put("type", "java:" + String.class.getName()); final Optional<DataShape> shape = DataShapeUtils.buildDataShape(ds); assertThat(shape.isPresent()).isTrue(); assertThat(shape.get().getKind()).isEqualTo(DataShapeKinds.JAVA); assertThat(shape.get().getType()).isEqualTo(String.class.getName()); assertThat(shape.get().getName()).isNull(); assertThat(shape.get().getDescription()).isNull(); assertThat(shape.get().getSpecification()).isNull(); }
@Test public void testDefaultDataShape() throws Exception { final ObjectNode ds = new ObjectMapper().createObjectNode(); final Optional<DataShape> shape = DataShapeUtils.buildDataShape(ds); assertThat(shape.isPresent()).isTrue(); assertThat(shape.get().getKind()).isEqualTo(DataShapeKinds.NONE); assertThat(shape.get().getType()).isNull(); assertThat(shape.get().getName()).isNull(); assertThat(shape.get().getDescription()).isNull(); assertThat(shape.get().getSpecification()).isNull(); }
@Test public void testJsonInstanceDataShape() throws Exception { final String spec = "{\"kind\":\"java-instance\",\"name\":\"person\"}"; final ObjectNode ds = new ObjectMapper().createObjectNode(); ds.put("kind", DataShapeKinds.JSON_INSTANCE.toString()); ds.put("specification", spec); final Optional<DataShape> shape = DataShapeUtils.buildDataShape(ds); assertThat(shape.isPresent()).isTrue(); assertThat(shape.get().getKind()).isEqualTo(DataShapeKinds.JSON_INSTANCE); assertThat(shape.get().getType()).isNull(); assertThat(shape.get().getName()).isNull(); assertThat(shape.get().getDescription()).isNull(); assertThat(shape.get().getSpecification()).isEqualTo(spec); }
@Test public void testSimpleJavaDataShape() throws Exception { final ObjectNode ds = new ObjectMapper().createObjectNode(); ds.put("kind", DataShapeKinds.JAVA.toString()); ds.put("type", String.class.getName()); final Optional<DataShape> shape = DataShapeUtils.buildDataShape(ds); assertThat(shape.isPresent()).isTrue(); assertThat(shape.get().getKind()).isEqualTo(DataShapeKinds.JAVA); assertThat(shape.get().getType()).isEqualTo(String.class.getName()); assertThat(shape.get().getName()).isNull(); assertThat(shape.get().getDescription()).isNull(); assertThat(shape.get().getSpecification()).isNull(); }