From a2051c190330e82b73a78f01c205344aa1c3adeb Mon Sep 17 00:00:00 2001 From: Nick Klose Date: Fri, 17 Jan 2014 13:01:26 +0100 Subject: [PATCH] Fixed NullPointerException in MarkPassing tests. --- .../sailing/domain/test/AbstractTracTracLiveTest.java | 9 ++++++--- .../test/markpassing/FlorianopolisMarkPassingTest.java | 8 ++++---- .../test/markpassing/FlorianopolisStartOfRaceTest.java | 4 ++-- .../domain/test/markpassing/OBMRMarkPassingTest.java | 8 ++++---- .../domain/test/markpassing/OBMRStartOfRaceTest.java | 4 ++-- .../domain/markpassingcalculation/CandidateChooser.java | 2 +- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/AbstractTracTracLiveTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/AbstractTracTracLiveTest.java index b446a43d880..6a88bb4bdfe 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/AbstractTracTracLiveTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/AbstractTracTracLiveTest.java @@ -127,10 +127,13 @@ public abstract class AbstractTracTracLiveTest extends StoredTrackBasedTest impl logger.info("entering "+getClass().getName()+".tearDown()"); Thread.sleep(500); // wait a bit before stopping the controller; in earlier versions we did a web request to stop the // simulator here; then, the ioThread joined flawlessly; aggressively stopping the controller doesn't let the ioThread join - controller.stop(/* abortStored */ true); - logger.info("successfully stopped controller"); + if (getController() != null) + controller.stop(/* abortStored */ true); + logger.info("successfully stopped controller"); try { - ioThread.join(3000); // just wait a little bit, then give up + if (ioThread != null) { + ioThread.join(3000); // just wait a little bit, then give up + } } catch (InterruptedException ex) { Assert.fail(ex.getMessage()); } diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/FlorianopolisMarkPassingTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/FlorianopolisMarkPassingTest.java index db59f80db17..a9df49fa3c3 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/FlorianopolisMarkPassingTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/FlorianopolisMarkPassingTest.java @@ -78,11 +78,11 @@ public class FlorianopolisMarkPassingTest extends OnlineTracTracBasedTest { int incorrectPasses = 0; boolean printRight = false; - boolean printWrong = true; + boolean printWrong = false; for (Competitor c : getRace().getCompetitors()) { numberOfCompetitors++; - System.out.println(c.getName() + "\n"); + // System.out.println(c.getName() + "\n"); for (Waypoint w : waypoints) { if (givenPasses.get(c).get(w) == null && !(computedPasses.get(c).get(w) == null)) { wronglyComputed++; @@ -131,15 +131,15 @@ public class FlorianopolisMarkPassingTest extends OnlineTracTracBasedTest { int totalMarkPasses = numberOfCompetitors * waypoints.size(); assertEquals(totalMarkPasses, incorrectPasses + correctPasses + wronglyNotComputed + correctlyNotComputed + wronglyComputed); - System.out.println("Total theoretical Passes: " + totalMarkPasses); double accuracy = (double) (correctPasses + correctlyNotComputed) / totalMarkPasses; + /* System.out.println("Total theoretical Passes: " + totalMarkPasses); System.out.println("Correct comparison: " + correctPasses); System.out.println("Incorrect comparison: " + incorrectPasses); System.out.println("Correctly Null: " + correctlyNotComputed); System.out.println("Should be null but arent:" + wronglyComputed); System.out.println("Should not be null but are: " + wronglyNotComputed); System.out.println("accuracy: " + accuracy); - System.out.println("Computation time: " + time + " ms"); + System.out.println("Computation time: " + time + " ms");*/ assertTrue(accuracy >= 0.9); } diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/FlorianopolisStartOfRaceTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/FlorianopolisStartOfRaceTest.java index 6015b1a099c..a3eb60a00f7 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/FlorianopolisStartOfRaceTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/FlorianopolisStartOfRaceTest.java @@ -41,12 +41,12 @@ public class FlorianopolisStartOfRaceTest extends FlorianopolisMarkPassingTest { } finder.calculateFixesAffectedByNewCompetitorFixes(c, fixes); chooser.calculateMarkPassDeltas(c, finder.getCandidateDeltas(c)); - System.out.println("\n"+c); + // System.out.println("\n"+c); Waypoint w1 = getRace().getCourse().getFirstWaypoint(); boolean gotFirst=false; boolean gotOther=false; for (Waypoint w : getRace().getCourse().getWaypoints()) { - System.out.println(getTrackedRace().getMarkPassing(c, w)); + // System.out.println(getTrackedRace().getMarkPassing(c, w)); if(w==w1){ gotFirst = (getTrackedRace().getMarkPassing(c, w) != null) ? true : false; } else { diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/OBMRMarkPassingTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/OBMRMarkPassingTest.java index 1836b1fb5df..c30538b5778 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/OBMRMarkPassingTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/OBMRMarkPassingTest.java @@ -78,11 +78,11 @@ public class OBMRMarkPassingTest extends OnlineTracTracBasedTest { int incorrectPasses = 0; boolean printRight = false; - boolean printWrong = true; + boolean printWrong = false; for (Competitor c : getRace().getCompetitors()) { numberOfCompetitors++; - System.out.println(c.getName() + "\n"); + //System.out.println(c.getName() + "\n"); for (Waypoint w : waypoints) { if (givenPasses.get(c).get(w) == null && !(computedPasses.get(c).get(w) == null)) { wronglyComputed++; @@ -131,15 +131,15 @@ public class OBMRMarkPassingTest extends OnlineTracTracBasedTest { int totalMarkPasses = numberOfCompetitors * waypoints.size(); assertEquals(totalMarkPasses, incorrectPasses + correctPasses + wronglyNotComputed + correctlyNotComputed + wronglyComputed); - System.out.println("Total theoretical Passes: " + totalMarkPasses); double accuracy = (double) (correctPasses + correctlyNotComputed) / totalMarkPasses; + /* System.out.println("Total theoretical Passes: " + totalMarkPasses); System.out.println("Correct comparison: " + correctPasses); System.out.println("Incorrect comparison: " + incorrectPasses); System.out.println("Correctly Null: " + correctlyNotComputed); System.out.println("Should be null but arent:" + wronglyComputed); System.out.println("Should not be null but are: " + wronglyNotComputed); System.out.println("accuracy: " + accuracy); - System.out.println("Computation time: " + time + " ms"); + System.out.println("Computation time: " + time + " ms");*/ assertTrue(accuracy >= 0.9); } diff --git a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/OBMRStartOfRaceTest.java b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/OBMRStartOfRaceTest.java index 8a5e423547d..e8843e2c66e 100755 --- a/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/OBMRStartOfRaceTest.java +++ b/java/com.sap.sailing.domain.test/src/com/sap/sailing/domain/test/markpassing/OBMRStartOfRaceTest.java @@ -41,12 +41,12 @@ public class OBMRStartOfRaceTest extends OBMRMarkPassingTest { } finder.calculateFixesAffectedByNewCompetitorFixes(c, fixes); chooser.calculateMarkPassDeltas(c, finder.getCandidateDeltas(c)); - System.out.println("\n"+c); + // System.out.println("\n"+c); Waypoint w1 = getRace().getCourse().getFirstWaypoint(); boolean gotFirst=false; boolean gotOther=false; for (Waypoint w : getRace().getCourse().getWaypoints()) { - System.out.println(getTrackedRace().getMarkPassing(c, w)); + // System.out.println(getTrackedRace().getMarkPassing(c, w)); if(w==w1){ gotFirst = (getTrackedRace().getMarkPassing(c, w) != null) ? true : false; } else { diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/CandidateChooser.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/CandidateChooser.java index facd0f80e67..cb03a4bebf6 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/CandidateChooser.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/markpassingcalculation/CandidateChooser.java @@ -150,7 +150,7 @@ public class CandidateChooser implements AbstractCandidateChooser { marker = candidateWithParent.get(marker); } if (changed) { - logger.info("New MarkPasses for" + co); + logger.info("New MarkPasses for " + co); List markPassDeltas = new ArrayList<>(); for (MarkPassing m : currentMarkPasses.get(co).values()) { markPassDeltas.add(m);