DataSetLoaderProvider implements LoaderProvider<IDataSet> { @Override public DataSetLoader<IDataSet> xlsLoader() { return (final File path) -> { try (InputStream in = new FileInputStream(path)) { return defineReplaceableExpressions(new XlsDataSet(in)); } 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 @Ignore("Somehow the given zip file (xlsx) is invalid, even Excel opens it without issues") public void testXlsxLoaderLoadUsingProperResource() throws Exception { final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader(); assertThat(loader, notNullValue()); final IDataSet dataSet = loader.load(getFile("test-data.xlsx")); assertThat(dataSet, notNullValue()); final List<String> tableNames = Arrays.asList(dataSet.getTableNames()); assertThat(tableNames.size(), equalTo(2)); assertThat(tableNames, hasItems("XLS_TABLE_1", "XLS_TABLE_2")); final ITable table1 = dataSet.getTable("XLS_TABLE_1"); assertThat(table1.getRowCount(), equalTo(3)); final ITable table2 = dataSet.getTable("XLS_TABLE_2"); assertThat(table2.getRowCount(), equalTo(1)); }
@Test(expected = NullPointerException.class) public void testXlsxLoaderLoadUsingNullFileName() throws IOException, DataSetException { final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader(); assertThat(loader, notNullValue()); loader.load(null); }
@Test(expected = IOException.class) public void testXlsxLoaderLoadUsingWrongResource() throws Exception { final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader(); assertThat(loader, notNullValue()); loader.load(getFile("test-data.json")); }
@Test @Ignore("Somehow the given zip file (xlsx) is invalid, even Excel opens it without issues") public void testXlsLoaderLoadUsingProperResource() throws Exception { final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader(); assertThat(loader, notNullValue()); final IDataSet dataSet = loader.load(getFile("test-data.xls")); assertThat(dataSet, notNullValue()); final List<String> tableNames = Arrays.asList(dataSet.getTableNames()); assertThat(tableNames.size(), equalTo(2)); assertThat(tableNames, hasItems("XLS_TABLE_1", "XLS_TABLE_2")); final ITable table1 = dataSet.getTable("XLS_TABLE_1"); assertThat(table1.getRowCount(), equalTo(3)); final ITable table2 = dataSet.getTable("XLS_TABLE_2"); assertThat(table2.getRowCount(), equalTo(1)); }
@Test(expected = NullPointerException.class) public void testXlsLoaderLoadUsingNullFileName() throws IOException, DataSetException { final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader(); assertThat(loader, notNullValue()); loader.load(null); }
@Test(expected = IOException.class) public void testXlsLoaderLoadUsingWrongResource() throws Exception { final DataSetLoader<IDataSet> loader = LOADER_PROVIDER.xlsLoader(); assertThat(loader, notNullValue()); loader.load(getFile("test-data.json")); }