DataSetLoaderProvider implements LoaderProvider<IDataSet> { @Override public DataSetLoader<IDataSet> jsonLoader() { return (final File path) -> { try (InputStream in = new FileInputStream(path)) { return defineReplaceableExpressions(new CachedDataSet(new JsonDataSetProducer(in), false)); } catch (final DataSetException e) { throw new IOException(e); } }; }  @Override DataSetLoader<IDataSet> xmlLoader(); @Override DataSetLoader<IDataSet> yamlLoader(); @Override DataSetLoader<IDataSet> jsonLoader(); @Override DataSetLoader<IDataSet> csvLoader(); @Override DataSetLoader<IDataSet> xlsLoader();  }
@Test public void testJsonLoaderLoadUsingProperResource() throws Exception { final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.jsonLoader(); assertThat(loader, notNullValue()); final IDataSet dataSet = loader.load(getFile("test-data.json")); assertThat(dataSet, notNullValue()); final List<String> tableNames = Arrays.asList(dataSet.getTableNames()); assertThat(tableNames.size(), equalTo(2)); assertThat(tableNames, hasItems("JSON_TABLE_1", "JSON_TABLE_2")); final ITable table1 = dataSet.getTable("JSON_TABLE_1"); assertThat(table1.getRowCount(), equalTo(3)); final ITable table2 = dataSet.getTable("JSON_TABLE_2"); assertThat(table2.getRowCount(), equalTo(1)); }
@Test(expected = NullPointerException.class) public void testJsonLoaderLoadUsingNullFileName() throws IOException, DataSetException { final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.jsonLoader(); assertThat(loader, notNullValue()); loader.load(null); }
@Test(expected = IOException.class) public void testJsonLoaderLoadUsingWrongResource() throws Exception { final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.jsonLoader(); assertThat(loader, notNullValue()); loader.load(getFile("test-data.yaml")); }