From 6c468a1b3424395a5797c305bb2a361ba6f10bbd Mon Sep 17 00:00:00 2001 From: Thomas Francart Date: Mon, 2 Jul 2018 15:27:31 +0200 Subject: [PATCH] Fixed way to properly load test data file when path contains special characters --- src/test/java/TestIO.java | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/test/java/TestIO.java b/src/test/java/TestIO.java index 3785ce3..2092ee3 100644 --- a/src/test/java/TestIO.java +++ b/src/test/java/TestIO.java @@ -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; @@ -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 @@ -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 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"); @@ -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) { @@ -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 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");