Skip to content

Commit 824375d

Browse files
committed
Reconcile TableIOServiceTest and TableIOPluginTest
1 parent 840f95b commit 824375d

2 files changed

Lines changed: 26 additions & 118 deletions

File tree

src/test/java/org/scijava/table/TableIOServiceTest.java

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/test/java/org/scijava/table/io/TableIOPluginTest.java renamed to src/test/java/org/scijava/table/io/TableIOServiceTest.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@
3838
import org.scijava.plugin.PluginInfo;
3939
import org.scijava.plugin.PluginService;
4040
import org.scijava.table.DefaultGenericTable;
41+
import org.scijava.table.GenericTable;
4142
import org.scijava.table.Table;
4243

4344
import java.io.IOException;
4445

46+
import static org.junit.Assert.assertEquals;
4547
import static org.junit.Assert.assertTrue;
4648
import static org.junit.Assert.fail;
4749

48-
public class TableIOPluginTest {
50+
public class TableIOServiceTest {
4951

5052
private Context context;
5153

@@ -64,10 +66,15 @@ public void tearDown() {
6466
context = null;
6567
}
6668

69+
6770
@Test
6871
public void testTableIOService() {
6972
String tableFile = "fakeTableFile.csv";
73+
GenericTable table = new DefaultGenericTable();
7074
TableIOService tableIOService = context.getService(TableIOService.class);
75+
assertTrue(tableIOService.getClass().equals(DefaultTableIOService.class));
76+
assertTrue(tableIOService.canOpen(tableFile));
77+
assertTrue(tableIOService.canSave(table, tableFile));
7178
try {
7279
Table<?, ?> data = tableIOService.open(tableFile);
7380
assertTrue(Table.class.isAssignableFrom(data.getClass()));
@@ -84,11 +91,15 @@ public void testTableIOServiceWithOptions() {
8491
TableIOOptions options = new TableIOOptions()
8592
.readColumnHeaders(true)
8693
.readRowHeaders(true)
87-
.columnDelimiter('-')
88-
.columnType(0, Double.class);
94+
.rowDelimiter("|")
95+
.columnDelimiter('-');
8996
try {
9097
Table<?, ?> data = tableIOService.open(tableFile, options);
9198
assertTrue(Table.class.isAssignableFrom(data.getClass()));
99+
assertEquals(1, data.getRowCount());
100+
assertEquals(1, data.getColumnCount());
101+
assertEquals("-", data.getColumnHeader(0));
102+
assertEquals("|", data.getRowHeader(0));
92103
}
93104
catch (IOException exc) {
94105
fail(exc.toString());
@@ -108,14 +119,20 @@ public boolean supportsSave(String loc) {
108119
return loc.endsWith("csv");
109120
}
110121

111-
@Override
112-
public Table open(String loc) {
113-
return new DefaultGenericTable();
114-
}
115-
122+
/**
123+
* This method creates a fake table for the purpose of testing the propagation of options.
124+
* It creates a row and a column with header names based on the {@param options}.
125+
*/
116126
@Override
117127
public Table open(String loc, TableIOOptions options) {
118-
return new DefaultGenericTable();
128+
DefaultGenericTable table = new DefaultGenericTable();
129+
if(options.values.readColumnHeaders()) {
130+
table.appendColumn(String.valueOf(options.values.columnDelimiter()));
131+
}
132+
if(options.values.readRowHeaders()) {
133+
table.appendRow(options.values.rowDelimiter());
134+
}
135+
return table;
119136
}
120137
}
121138

0 commit comments

Comments
 (0)