From 1e7aa46ecab8be5ae604c53b27825c7aebaf422b Mon Sep 17 00:00:00 2001 From: Rovaniemi Date: Wed, 7 Jun 2017 13:45:53 +0300 Subject: [PATCH] tests --- .gitignore | 1 - map/.gitkeep | 0 src/test/java/omsparser/OsmparserTest.java | 22 ++++++++++++++++++++++ src/test/java/omsparser/XmlReaderTest.java | 22 +++++++++++++++++++++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 map/.gitkeep diff --git a/.gitignore b/.gitignore index b6865c1..a201fae 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,6 @@ # Project files *.json *.osm -map/ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* diff --git a/map/.gitkeep b/map/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/omsparser/OsmparserTest.java b/src/test/java/omsparser/OsmparserTest.java index 47bf26a..f2f814e 100644 --- a/src/test/java/omsparser/OsmparserTest.java +++ b/src/test/java/omsparser/OsmparserTest.java @@ -4,8 +4,12 @@ import osmparser.Osmparser; import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; import static org.junit.Assert.assertNotEquals; @@ -37,4 +41,22 @@ public void masterTest() throws IOException { osmparser.main(new String[]{""}); Assert.assertEquals(1, Files.list(Paths.get("")).filter(n -> n.toString().contains("graph.json")).count()); } + + @Test + public void masterTestWithFile() throws IOException { + Charset utf8 = StandardCharsets.UTF_8; + List lines = Arrays.asList("\n" + + "\n" + + " \n" + + "\n"); + try { + Files.write(Paths.get("map/map-01.osm"), lines, utf8); + } catch (IOException e) { + e.printStackTrace(); + } + Osmparser osmparser = new Osmparser(); + osmparser.main(new String[]{""}); + Assert.assertEquals(1, Files.list(Paths.get("")).filter(n -> n.toString().contains("graph.json")).count()); + } + } diff --git a/src/test/java/omsparser/XmlReaderTest.java b/src/test/java/omsparser/XmlReaderTest.java index 19e5a39..9c6e947 100644 --- a/src/test/java/omsparser/XmlReaderTest.java +++ b/src/test/java/omsparser/XmlReaderTest.java @@ -2,6 +2,15 @@ import org.junit.*; import osmparser.XmlReader; + +import java.io.*; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; + import static org.mockito.Mockito.*; public class XmlReaderTest { @@ -28,7 +37,17 @@ public void tearDown() { //I tested these methods by hands, but there is some test for better coverage. @Test - public void rightAmountDocuments(){ + public void rightAmountDocuments() throws IOException { + Charset utf8 = StandardCharsets.UTF_8; + List lines = Arrays.asList("\n" + + "\n" + + " \n" + + "\n"); + try { + Files.write(Paths.get("map/map-01.osm"), lines, utf8); + } catch (IOException e) { + e.printStackTrace(); + } XmlReader reader = new XmlReader(); Assert.assertEquals(1, reader.howManyDocuments()); } @@ -43,6 +62,7 @@ public void underTenWorks(){ @Test public void ifDocumentationNotFoundReturnNull(){ + XmlReader reader = new XmlReader(); Assert.assertEquals(null, reader.getDocument("madfsmfds", 10)); }