From 378707683967018fc731f69065052b26406cf9fb Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Sun, 23 Oct 2022 10:11:12 +0200 Subject: [PATCH 1/2] Move testcases from brouter-server to their modules --- .../src/test/java/btools/router/RoutingEngineTest.java | 7 ++----- .../src/test/resources/testtrack0.gpx | 0 .../test/java/btools/mapaccess}/IntegrityCheckTest.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) rename brouter-server/src/test/java/btools/server/RouterTest.java => brouter-core/src/test/java/btools/router/RoutingEngineTest.java (95%) rename {brouter-server => brouter-core}/src/test/resources/testtrack0.gpx (100%) rename {brouter-server/src/test/java/btools/server => brouter-mapaccess/src/test/java/btools/mapaccess}/IntegrityCheckTest.java (96%) diff --git a/brouter-server/src/test/java/btools/server/RouterTest.java b/brouter-core/src/test/java/btools/router/RoutingEngineTest.java similarity index 95% rename from brouter-server/src/test/java/btools/server/RouterTest.java rename to brouter-core/src/test/java/btools/router/RoutingEngineTest.java index 210e033..1ef99f2 100644 --- a/brouter-server/src/test/java/btools/server/RouterTest.java +++ b/brouter-core/src/test/java/btools/router/RoutingEngineTest.java @@ -1,4 +1,4 @@ -package btools.server; +package btools.router; import java.util.*; @@ -8,10 +8,7 @@ import org.junit.Test; import java.net.URL; import java.io.File; -import btools.router.*; -import btools.mapaccess.*; - -public class RouterTest { +public class RoutingEngineTest { private File workingDir; @Test diff --git a/brouter-server/src/test/resources/testtrack0.gpx b/brouter-core/src/test/resources/testtrack0.gpx similarity index 100% rename from brouter-server/src/test/resources/testtrack0.gpx rename to brouter-core/src/test/resources/testtrack0.gpx diff --git a/brouter-server/src/test/java/btools/server/IntegrityCheckTest.java b/brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java similarity index 96% rename from brouter-server/src/test/java/btools/server/IntegrityCheckTest.java rename to brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java index cdae8d3..fa3a0f9 100644 --- a/brouter-server/src/test/java/btools/server/IntegrityCheckTest.java +++ b/brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java @@ -1,4 +1,4 @@ -package btools.server; +package btools.mapaccess; import java.io.File; import java.net.URL; From fd158dc0ce9fb2d2f3ac092ccf1e7b0a93942e6b Mon Sep 17 00:00:00 2001 From: Manuel Fuhr Date: Sun, 23 Oct 2022 10:51:02 +0200 Subject: [PATCH 2/2] Cleanup testcases (split, dependencies, assertions) --- brouter-core/build.gradle | 7 ++-- .../java/btools/router/RoutingEngineTest.java | 42 +++++++++---------- brouter-mapaccess/build.gradle | 4 ++ .../btools/mapaccess/IntegrityCheckTest.java | 24 +++++------ 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/brouter-core/build.gradle b/brouter-core/build.gradle index c96982f..cb7dde5 100644 --- a/brouter-core/build.gradle +++ b/brouter-core/build.gradle @@ -3,11 +3,12 @@ plugins { } dependencies { - implementation project(':brouter-mapaccess') implementation project(':brouter-util') implementation project(':brouter-expressions') implementation project(':brouter-codec') - testImplementation 'junit:junit:4.13.1' - + testImplementation 'junit:junit:4.13.2' } + +// MapcreatorTest generates segments which are used in tests +test.dependsOn ':brouter-map-creator:test' diff --git a/brouter-core/src/test/java/btools/router/RoutingEngineTest.java b/brouter-core/src/test/java/btools/router/RoutingEngineTest.java index 1ef99f2..ba2dc90 100644 --- a/brouter-core/src/test/java/btools/router/RoutingEngineTest.java +++ b/brouter-core/src/test/java/btools/router/RoutingEngineTest.java @@ -1,47 +1,46 @@ package btools.router; -import java.util.*; - import org.junit.Assert; +import org.junit.Before; import org.junit.Test; -import java.net.URL; import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; public class RoutingEngineTest { private File workingDir; - @Test - public void routerTest() throws Exception { + @Before + public void before() { URL resulturl = this.getClass().getResource("/testtrack0.gpx"); - Assert.assertTrue("reference result not found: ", resulturl != null); + Assert.assertNotNull("reference result not found: ", resulturl); File resultfile = new File(resulturl.getFile()); workingDir = resultfile.getParentFile(); + } - String msg; - - // first test: route within dreiech test-map crossing tile border - - msg = calcRoute(8.720897, 50.002515, 8.723658, 49.997510, "testtrack"); - + @Test + public void routeCrossingSegmentBorder() { + String msg = calcRoute(8.720897, 50.002515, 8.723658, 49.997510, "testtrack"); // error message from router? - Assert.assertTrue("routing failed: " + msg, msg == null); + Assert.assertNull("routing failed: " + msg, msg); // if the track didn't change, we expect the first alternative also File a1 = new File(workingDir, "testtrack1.gpx"); Assert.assertTrue("result content missmatch", a1.exists()); - - // second test: to-point far off - - msg = calcRoute(8.720897, 50.002515, 16.723658, 49.997510, "notrack"); - - Assert.assertTrue(msg, msg != null && msg.indexOf("not found") >= 0); } - private String calcRoute(double flon, double flat, double tlon, double tlat, String trackname) throws Exception { + @Test + public void routeDestinationPointFarOff() { + String msg = calcRoute(8.720897, 50.002515, 16.723658, 49.997510, "notrack"); + Assert.assertTrue(msg, msg != null && msg.contains("not found")); + } + + private String calcRoute(double flon, double flat, double tlon, double tlat, String trackname) { String wd = workingDir.getAbsolutePath(); - List wplist = new ArrayList(); + List wplist = new ArrayList<>(); OsmNodeNamed n; n = new OsmNodeNamed(); n.name = "from"; @@ -57,7 +56,6 @@ public class RoutingEngineTest { RoutingContext rctx = new RoutingContext(); rctx.localFunction = wd + "/../../../../misc/profiles2/trekking.brf"; - // c.setAlternativeIdx( 1 ); RoutingEngine re = new RoutingEngine( wd + "/" + trackname, diff --git a/brouter-mapaccess/build.gradle b/brouter-mapaccess/build.gradle index c920239..40189cb 100644 --- a/brouter-mapaccess/build.gradle +++ b/brouter-mapaccess/build.gradle @@ -6,4 +6,8 @@ dependencies { implementation project(':brouter-util') implementation project(':brouter-codec') implementation project(':brouter-expressions') + testImplementation 'junit:junit:4.13.2' } + +// MapcreatorTest generates segments which are used in tests +test.dependsOn ':brouter-map-creator:test' diff --git a/brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java b/brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java index fa3a0f9..6685895 100644 --- a/brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java +++ b/brouter-mapaccess/src/test/java/btools/mapaccess/IntegrityCheckTest.java @@ -1,28 +1,24 @@ package btools.mapaccess; -import java.io.File; -import java.net.URL; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; -import org.junit.Assert; import org.junit.Test; -import btools.mapaccess.PhysicalFile; +import java.io.File; +import java.io.IOException; public class IntegrityCheckTest { - private File workingDir; - @Test - public void integrityTest() throws Exception { - URL resulturl = this.getClass().getResource("/testtrack0.gpx"); - Assert.assertTrue("reference result not found: ", resulturl != null); - File resultfile = new File(resulturl.getFile()); - workingDir = resultfile.getParentFile(); - - File segmentDir = new File(workingDir, "/../../../../brouter-map-creator/build/resources/test/tmp/segments"); + public void integrityTest() throws IOException { + File workingDir = new File(".").getCanonicalFile(); + File segmentDir = new File(workingDir, "../brouter-map-creator/build/resources/test/tmp/segments"); File[] files = segmentDir.listFiles(); + assertNotNull("Missing segments", files); + for (File f : files) { - PhysicalFile.checkFileIntegrity(f); + assertNull(PhysicalFile.checkFileIntegrity(f)); } }