From 3cfa1d954bd53aeed598e66ae6af11930377118f Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Mon, 9 May 2022 07:00:51 +0200 Subject: [PATCH] Test CoordinateReader --- .../routingapp/CoordinateReaderTest.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 brouter-routing-app/src/androidTest/java/btools/routingapp/CoordinateReaderTest.java diff --git a/brouter-routing-app/src/androidTest/java/btools/routingapp/CoordinateReaderTest.java b/brouter-routing-app/src/androidTest/java/btools/routingapp/CoordinateReaderTest.java new file mode 100644 index 0000000..b9edb7a --- /dev/null +++ b/brouter-routing-app/src/androidTest/java/btools/routingapp/CoordinateReaderTest.java @@ -0,0 +1,82 @@ +package btools.routingapp; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.closeTo; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.notNullValue; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.io.FileWriter; + + +public class CoordinateReaderTest { + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Test + public void readNogoRoute() throws Exception { + File importFolder = temporaryFolder.newFolder("brouter", "import", "tracks"); + File tempFile = new File(importFolder, "nogo_test.gpx"); + try (FileWriter writer = new FileWriter(tempFile)) { + writer.write("\n" + + "\n" + + " Nogo Route\n" + + " \n" + + " \n" + + "\n" + + " Nogo Oststadt\n" + + " Red\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n" + + ""); + } + + CoordinateReader coordinateReader = CoordinateReader.obtainValidReader(temporaryFolder.getRoot().getAbsolutePath(), false); + assertThat(coordinateReader.nogopoints, hasSize(1)); + // Name should return "Nogo Oststadt", "Nogo Route" or "nogo_test.gpx" + assertThat(coordinateReader.nogopoints.get(0).name, equalTo("nogo_test")); + assertThat(coordinateReader.nogopoints.get(0).radius, closeTo(810.0, 5.0)); + } + + @Test + public void readWaypoints() throws Exception { + File importFolder = temporaryFolder.newFolder("brouter", "import"); + File tempFile = new File(importFolder, "favourites.gpx"); + try (FileWriter writer = new FileWriter(tempFile)) { + // https://en.wikipedia.org/wiki/GPS_Exchange_Format#Sample_GPX_document + writer.write("\n" + + "\n" + + "3.4from\n" + + "3.4to\n" + + "3.4via1\n" + + "3.4nogo100 Test\n" + + ""); + } + + CoordinateReader coordinateReader = CoordinateReader.obtainValidReader(temporaryFolder.getRoot().getAbsolutePath(), false); + assertThat(coordinateReader, notNullValue()); + // from, to, viaX are parsed into waypoints + assertThat(coordinateReader.waypoints, hasSize(3)); + assertThat(coordinateReader.nogopoints, hasSize(1)); + coordinateReader.readAllPoints(); + assertThat(coordinateReader.allpoints, hasSize(4)); + } +}