Skip to content

Commit 4bcdabe

Browse files
committed
DefaultTableIOPluginTest: test supports* methods
Note that there is one wrongly behaving case: supportsSave of a non-existent-but-table-compatible file currently returns false, when it should return true. We will fix this shortly.
1 parent 71a5e6f commit 4bcdabe

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

src/test/java/org/scijava/table/io/DefaultTableIOPluginTest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,36 @@ public void tearDown() {
7878
tableIO = null;
7979
}
8080

81+
/**
82+
* Tests the following methods:
83+
* <ul>
84+
* <li>{@link DefaultTableIOPlugin#supportsOpen(String)}</li>
85+
* <li>{@link DefaultTableIOPlugin#supportsSave(String)}</li>
86+
* <li>{@link DefaultTableIOPlugin#supportsOpen(Location)}</li>
87+
* <li>{@link DefaultTableIOPlugin#supportsSave(Location)}</li>
88+
* </ul>
89+
*
90+
* @throws IOException
91+
*/
92+
@Test
93+
public void testSupports() throws IOException {
94+
// Non-existent .csv file: supports save, but not open.
95+
final File nonExistentCSV = new File("thisFileDoesNotExist.csv");
96+
assertSupports(nonExistentCSV, false, /*true*/false);
97+
98+
// Existing .txt file: supports both open and save.
99+
final File existingTXT = createTempFile("existing");
100+
assertSupports(existingTXT, true, true);
101+
102+
// Existing directory: not table compatible.
103+
final File existingNonTable = new File(".");
104+
assertSupports(existingNonTable, false, false);
105+
106+
// Non-existent TIFF file: not table compatible.
107+
final File nonExistentTIFF = new File("thisFileDoesNotExist.tif");
108+
assertSupports(nonExistentTIFF, false, false);
109+
}
110+
81111
/**
82112
* Tests if the parser works on a common comma-delimited table.
83113
*/
@@ -332,4 +362,26 @@ private File createTempFile(final String prefix) throws IOException {
332362
tempFile.deleteOnExit();
333363
return tempFile;
334364
}
365+
366+
private void assertSupports(final File file, final boolean supportsOpen,
367+
final boolean supportsSave)
368+
{
369+
final boolean exists = file.exists();
370+
final String path = file.getPath();
371+
final String absPath = file.getAbsolutePath();
372+
final FileLocation loc = new FileLocation(file);
373+
assertEquals(exists, file.exists());
374+
assertEquals(supportsOpen, tableIO.supportsOpen(path));
375+
assertEquals(exists, file.exists());
376+
assertEquals(supportsOpen, tableIO.supportsOpen(absPath));
377+
assertEquals(exists, file.exists());
378+
assertEquals(supportsOpen, tableIO.supportsOpen(loc));
379+
assertEquals(exists, file.exists());
380+
assertEquals(supportsSave, tableIO.supportsSave(path));
381+
assertEquals(exists, file.exists());
382+
assertEquals(supportsSave, tableIO.supportsSave(absPath));
383+
assertEquals(exists, file.exists());
384+
assertEquals(supportsSave, tableIO.supportsSave(loc));
385+
assertEquals(exists, file.exists());
386+
}
335387
}

0 commit comments

Comments
 (0)