diff options
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/ExportTest.java | 24 | ||||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/ImportTest.java | 39 |
2 files changed, 63 insertions, 0 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/ExportTest.java b/test/src/java/com/healthmarketscience/jackcess/ExportTest.java index 86b8fa6..4e22683 100644 --- a/test/src/java/com/healthmarketscience/jackcess/ExportTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/ExportTest.java @@ -103,6 +103,30 @@ public class ExportTest extends TestCase "'crazy''data\"here'||-345||-3.45E-4||61 62 63 64 65 66 67||true||" + NL + "C:\\temp\\some_file.txt||25||0.0||||false||" + NL; assertEquals(expected, out.toString()); + + ExportFilter oddFilter = new SimpleExportFilter() { + private int _num; + @Override + public Object[] filterRow(Object[] row) { + if((_num++ % 2) == 1) { + return null; + } + return row; + } + }; + + out = new StringWriter(); + + ExportUtil.exportWriter(db, "test", new BufferedWriter(out), false, + ExportUtil.DEFAULT_DELIMITER, + ExportUtil.DEFAULT_QUOTE_CHAR, oddFilter); + + expected = + "some text||some more,13,13.25,\"61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78" + NL + + "79 7A 61 62 63 64\",true," + testDate + NL + + "C:\\temp\\some_file.txt,25,0.0,,false," + NL; + + assertEquals(expected, out.toString()); } } diff --git a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java index a0de8c4..5f75de0 100644 --- a/test/src/java/com/healthmarketscience/jackcess/ImportTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/ImportTest.java @@ -94,6 +94,45 @@ public class ImportTest extends TestCase ); assertTable(expectedRows, t); + + ImportFilter oddFilter = new SimpleImportFilter() { + private int _num; + @Override + public Object[] filterRow(Object[] row) { + if((_num++ % 2) == 1) { + return null; + } + return row; + } + }; + + tableName = db.importFile( + "test2", new File("test/data/sample-input.tab"), "\\t", oddFilter); + t = db.getTable(tableName); + + colNames = new ArrayList<String>(); + for(Column c : t.getColumns()) { + colNames.add(c.getName()); + } + assertEquals(Arrays.asList("Test1", "Test2", "Test3"), colNames); + + expectedRows = + createExpectedTable( + createExpectedRow( + "Test1", "Foo", + "Test2", "Bar", + "Test3", "Ralph"), + createExpectedRow( + "Test1", "", + "Test2", "Partial line", + "Test3", null), + createExpectedRow( + "Test1", "buzz", + "Test2", "embedded\tseparator", + "Test3", "long") + ); + assertTable(expectedRows, t); + db.close(); } } |