Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rovaniemi committed Jun 7, 2017
1 parent 9f9a916 commit 1e7aa46
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
Empty file added map/.gitkeep
Empty file.
22 changes: 22 additions & 0 deletions src/test/java/omsparser/OsmparserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<String> lines = Arrays.asList("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<osm version=\"0.6\" generator=\"CGImap 0.6.0 (1590 thorn-02.openstreetmap.org)\" copyright=\"OpenStreetMap and contributors\" attribution=\"http://www.openstreetmap.org/copyright\" license=\"http://opendatacommons.org/licenses/odbl/1-0/\">\n" +
" <bounds minlat=\"53.9427100\" minlon=\"4.4592000\" maxlat=\"53.9436000\" maxlon=\"4.4617000\"/>\n" +
"</osm>\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());
}

}
22 changes: 21 additions & 1 deletion src/test/java/omsparser/XmlReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<String> lines = Arrays.asList("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<osm version=\"0.6\" generator=\"CGImap 0.6.0 (1590 thorn-02.openstreetmap.org)\" copyright=\"OpenStreetMap and contributors\" attribution=\"http://www.openstreetmap.org/copyright\" license=\"http://opendatacommons.org/licenses/odbl/1-0/\">\n" +
" <bounds minlat=\"53.9427100\" minlon=\"4.4592000\" maxlat=\"53.9436000\" maxlon=\"4.4617000\"/>\n" +
"</osm>\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());
}
Expand All @@ -43,6 +62,7 @@ public void underTenWorks(){

@Test
public void ifDocumentationNotFoundReturnNull(){

XmlReader reader = new XmlReader();
Assert.assertEquals(null, reader.getDocument("madfsmfds", 10));
}
Expand Down

0 comments on commit 1e7aa46

Please sign in to comment.