SQLWriter { public void write(WritableToTable supplier, String fileName, String tableName) { ImmutableSet<String> header = supplier.getHeaders(); if (header.isEmpty()) { logger.info("Nothing to write to " + fileName); return; } writeFile(header, supplier, fileName, tableName); }  void write(WritableToTable supplier, String fileName, String tableName);  }
@Test void writeSimpleFile() { String tableName = "test"; int numberOfDataPoints = 10; TestLineSupplier lineSupplier = new TestLineSupplier(numberOfDataPoints, i -> i * i, false); new SQLWriter().write(lineSupplier, FILE.getAbsolutePath(), tableName); try (SQLiteConnection conn = SQLiteConnection.create(FILE.getAbsolutePath())) { SQLiteChecker checker = new SQLiteChecker(conn); checker.getNumberOfRowsInTable(numberOfDataPoints, tableName); checkQuantity(conn, tableName, 5, 5 * 5); } catch (SQLException e) { Assertions.fail("Failed to read file\n" + e); } }
@Test void testWritingMultipleTables() { String tableName_1 = "test_1"; String tableName_2 = "test_2"; TestLineSupplier lineSupplier_1 = new TestLineSupplier(10, i -> i, false); TestLineSupplier lineSupplier_2 = new TestLineSupplier(15, i -> i * i, false); new SQLWriter().write(lineSupplier_1, FILE.getAbsolutePath(), tableName_1); new SQLWriter().write(lineSupplier_2, FILE.getAbsolutePath(), tableName_2); try (SQLiteConnection conn = SQLiteConnection.create(FILE.getAbsolutePath())) { checkQuantity(conn, tableName_1, 5, 5); checkQuantity(conn, tableName_2, 12, 12 * 12); } catch (SQLException e) { Assertions.fail("Failed to read file\n" + e); } }
@Test void testWritingStringEntries() { String tableName = "string_test"; int numberOfDataPoints = 10; TestLineSupplier lineSupplier = new TestLineSupplier(numberOfDataPoints, i -> i, true); new SQLWriter().write(lineSupplier, FILE.getAbsolutePath(), tableName); try (SQLiteConnection conn = SQLiteConnection.create(FILE.getAbsolutePath())) { checkQuantity(conn, tableName, 1, 1); } catch (SQLException e) { Assertions.fail("Failed to read file\n" + e); } }