### Question:
LoadSchemaUtils { public static DatasetSchema datasetSchemaFromJson(final Path filePath) throws ModelLoadingException { if (!Files.isDirectory(filePath)) { throw new ModelLoadingException("The path should be a directory"); } final Path jsonFilePath = filePath.resolve(SCHEMA_IMPORT_MODEL); if (!Files.exists(jsonFilePath)) { throw new ModelLoadingException("There is no model.json file on the model path."); } try { final String jsonContent = new String(Files.readAllBytes(jsonFilePath)); final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new SerializersInModule()); return mapper.readValue(jsonContent, DatasetSchema.class); } catch (final IOException e) { final String msg = String.format("Could not load schema for model in path %s due to %s", filePath, e.toString()); logger.error(msg); logger.trace(msg, e); throw new ModelLoadingException(e.toString()); } } private  LoadSchemaUtils(); static DatasetSchema datasetSchemaFromJson(final Path filePath); static String getValueSchemaTypeToString(final AbstractValueSchema valueSchema); static final String CATEGORICAL; static final String NUMERIC; static final String STRING; }### Answer:
@Test public void schemaFromJsonTest() throws ModelLoadingException { final String directoryPath = getClass().getResource(File.separator + "random_forest").getPath(); final DatasetSchema datasetSchema = LoadSchemaUtils.datasetSchemaFromJson(Paths.get(directoryPath)); assertThat(datasetSchema.getFieldSchemas()) .as("number of fields of the schema") .hasSize(4); }
@Test public void dirNotExistTest() { assertThatThrownBy(() -> LoadSchemaUtils.datasetSchemaFromJson(Paths.get("dummy"))) .as("the dataset schema doesn't exist") .hasMessageContaining("The path") .hasMessageContaining("should be a directory"); }
@Test public void jsonNotExistTest() { final String directoryPath = getClass().getResource(File.separator + "wrong_model_000").getPath(); assertThatThrownBy(() -> LoadSchemaUtils.datasetSchemaFromJson(Paths.get(directoryPath))) .as("The exception thrown by loading the schema from a path without the model.json file") .isInstanceOf(ModelLoadingException.class) .hasMessageContaining("model.json "); }