Skip to content

Commit 6a16353

Browse files
committed
Remove LocationService dependency from test
1 parent 521c631 commit 6a16353

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

src/test/java/net/imagej/table/DefaultTableIOPluginTest.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,23 @@
2424
import static org.junit.Assert.assertEquals;
2525
import static org.junit.Assert.fail;
2626

27-
import io.scif.io.ByteArrayHandle;
28-
import io.scif.services.LocationService;
29-
27+
import java.io.File;
3028
import java.io.IOException;
3129
import java.lang.reflect.Field;
3230
import java.util.HashMap;
3331
import java.util.List;
3432
import java.util.function.Function;
3533

34+
import org.junit.After;
35+
import org.junit.Before;
3636
import org.junit.Test;
3737
import org.scijava.Context;
38+
import org.scijava.io.DataHandle;
39+
import org.scijava.io.DataHandleService;
40+
import org.scijava.io.FileLocation;
3841
import org.scijava.io.IOPlugin;
3942
import org.scijava.io.IOService;
43+
import org.scijava.io.Location;
4044
import org.scijava.plugin.Parameter;
4145
import org.scijava.util.ClassUtils;
4246

@@ -49,6 +53,15 @@ public class DefaultTableIOPluginTest {
4953

5054
private static final Context ctx = new Context();
5155

56+
@Before
57+
@After
58+
public void removeTempFiles() {
59+
Location source = new FileLocation("table.txt");
60+
new File(source.getURI()).delete();
61+
source = new FileLocation("fake.csv");
62+
new File(source.getURI()).delete();
63+
}
64+
5265
/**
5366
* Tests if the parser works on a common tab-delimited table.
5467
*/
@@ -241,18 +254,21 @@ private void assertTableEquals(final String[] colHeaders,
241254
private GenericTable openTable(final String tableSource,
242255
final IOPlugin<GenericTable> tableIO) throws IOException
243256
{
244-
final ByteArrayHandle bah = new ByteArrayHandle(tableSource.getBytes());
245-
ctx.service(LocationService.class).mapFile("table.txt", bah);
257+
final Location dest = new FileLocation("table.txt");
258+
final DataHandle<? extends Location> destHandle = ctx.service(DataHandleService.class).create(dest);
259+
destHandle.write(tableSource.getBytes());
246260
return tableIO.open("table.txt");
247261
}
248262

249263
private String saveTable(final GenericTable table,
250264
final IOPlugin<GenericTable> tableIO) throws IOException
251265
{
252-
final ByteArrayHandle bah = new ByteArrayHandle();
253-
ctx.service(LocationService.class).mapFile("table.txt", bah);
266+
final Location source = new FileLocation("table.txt");
267+
// Remove file during tests
268+
new File(source.getURI()).delete();
269+
final DataHandle<? extends Location> sourceHandle = ctx.service(DataHandleService.class).create(source);
254270
tableIO.save(table, "table.txt");
255-
return new String(bah.getBytes(), 0, (int) bah.length());
271+
return sourceHandle.readString(Integer.MAX_VALUE);
256272
}
257273

258274
private void setValues(final Object instance, final String[] fieldNames,

0 commit comments

Comments
 (0)