Skip to content

Commit

Permalink
Fixed way to properly load test data file when path contains special …
Browse files Browse the repository at this point in the history
…characters
  • Loading branch information
tfrancart committed Jul 2, 2018
1 parent 5e19a4e commit 6c468a1
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/test/java/TestIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.util.SortedMap;
import java.util.SortedSet;

Expand Down Expand Up @@ -79,8 +79,9 @@ public void testCSV() {
}

@Test
public void testCSVNoTitles() {
makeLoadAssertions(new CSVImpl(), TestIO.class.getResource("csvnotitles.csv").getPath());
public void testCSVNoTitles() throws URISyntaxException {
// note : this does not work if path contains special characters
makeLoadAssertions(new CSVImpl(), new File(TestIO.class.getResource("csvnotitles.csv").toURI()));
}

@Test
Expand All @@ -94,12 +95,11 @@ public void testRDF() {
}

@Test
public void testRDFLoadISOLatin1() {
public void testRDFLoadISOLatin1() throws URISyntaxException {
IOAlignment ioplugin = new EuzenatRDFImpl();
String filename = TestIO.class.getResource("isolatin.rdf").getPath();
Alignment<String, String> newAlignment = null;
try {
newAlignment = ioplugin.loadAlignment(mockContainer, mockContainer, new File(filename));
newAlignment = ioplugin.loadAlignment(mockContainer, mockContainer, new File(TestIO.class.getResource("isolatin.rdf").toURI()));
} catch (IOException e) {
e.printStackTrace();
fail("Something wrong while reading test");
Expand All @@ -126,10 +126,9 @@ public void testSKOS() {

private void makeFullAssertions(IOAlignment ioplugin) throws IOException {
Path tmpPath = Files.createTempFile(null, null);
String filename = tmpPath.toString();

makeSaveAssertions(ioplugin, filename);
makeLoadAssertions(ioplugin, filename);
makeSaveAssertions(ioplugin, tmpPath.toString());
makeLoadAssertions(ioplugin, tmpPath.toFile());
}

private void makeSaveAssertions(IOAlignment ioplugin, String filename) {
Expand All @@ -141,10 +140,10 @@ private void makeSaveAssertions(IOAlignment ioplugin, String filename) {
}
}

private void makeLoadAssertions(IOAlignment ioplugin, String filename) {
private void makeLoadAssertions(IOAlignment ioplugin, File file) {
Alignment<String, String> newAlignment = null;
try {
newAlignment = ioplugin.loadAlignment(mockContainer, mockContainer, new File(filename));
newAlignment = ioplugin.loadAlignment(mockContainer, mockContainer, file);
} catch (IOException e) {
e.printStackTrace();
fail("Something wrong while reading test");
Expand Down

0 comments on commit 6c468a1

Please sign in to comment.