mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-01 18:03:59 +00:00
added basic tests for CourseImpl
This commit is contained in:
1 parent
f360f8db3f
commit
86f62f7b78
3 files changed
+92
-9
No files matched your search
+83
@@ -0,0 +1,83 @@
|
||||
package com.sap.sailing.domain.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.base.Course;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.domain.base.impl.BuoyImpl;
|
||||
import com.sap.sailing.domain.base.impl.CourseImpl;
|
||||
import com.sap.sailing.domain.base.impl.WaypointImpl;
|
||||
import com.sap.sailing.util.Util;
|
||||
|
||||
public class CourseTest {
|
||||
@Test
|
||||
public void testEmptyCourse() {
|
||||
Iterable<Waypoint> waypoints = Collections.emptyList();
|
||||
Course course = new CourseImpl("Test Course", waypoints);
|
||||
assertEquals(0, Util.size(course.getWaypoints()));
|
||||
assertEquals(0, Util.size(course.getLegs()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCourseWithOneWaypoint() {
|
||||
List<Waypoint> waypoints = new ArrayList<Waypoint>();
|
||||
waypoints.add(new WaypointImpl(new BuoyImpl("Test Buoy")));
|
||||
Course course = new CourseImpl("Test Course", waypoints);
|
||||
assertEquals(1, Util.size(course.getWaypoints()));
|
||||
assertEquals(0, Util.size(course.getLegs()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddWaypointToCourseWithOneWaypoint() {
|
||||
List<Waypoint> waypoints = new ArrayList<Waypoint>();
|
||||
waypoints.add(new WaypointImpl(new BuoyImpl("Test Buoy")));
|
||||
Course course = new CourseImpl("Test Course", waypoints);
|
||||
assertEquals(1, Util.size(course.getWaypoints()));
|
||||
assertEquals(0, Util.size(course.getLegs()));
|
||||
course.addWaypoint(1, new WaypointImpl(new BuoyImpl("Second Buoy")));
|
||||
assertEquals(2, Util.size(course.getWaypoints()));
|
||||
assertEquals(1, Util.size(course.getLegs()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddWaypointToEmptyCourse() {
|
||||
Iterable<Waypoint> waypoints = Collections.emptyList();
|
||||
Course course = new CourseImpl("Test Course", waypoints);
|
||||
assertEquals(0, Util.size(course.getWaypoints()));
|
||||
assertEquals(0, Util.size(course.getLegs()));
|
||||
course.addWaypoint(0, new WaypointImpl(new BuoyImpl("First Buoy")));
|
||||
assertEquals(1, Util.size(course.getWaypoints()));
|
||||
assertEquals(0, Util.size(course.getLegs()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveWaypointToCourseWithOneWaypoint() {
|
||||
List<Waypoint> waypoints = new ArrayList<Waypoint>();
|
||||
waypoints.add(new WaypointImpl(new BuoyImpl("Test Buoy")));
|
||||
waypoints.add(new WaypointImpl(new BuoyImpl("Second Buoy")));
|
||||
Course course = new CourseImpl("Test Course", waypoints);
|
||||
assertEquals(2, Util.size(course.getWaypoints()));
|
||||
assertEquals(1, Util.size(course.getLegs()));
|
||||
course.removeWaypoint(1);
|
||||
assertEquals(1, Util.size(course.getWaypoints()));
|
||||
assertEquals(0, Util.size(course.getLegs()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveWaypointToEmptyCourse() {
|
||||
Iterable<Waypoint> waypoints = Collections.emptyList();
|
||||
Course course = new CourseImpl("Test Course", waypoints);
|
||||
course.addWaypoint(0, new WaypointImpl(new BuoyImpl("First Buoy")));
|
||||
assertEquals(1, Util.size(course.getWaypoints()));
|
||||
assertEquals(0, Util.size(course.getLegs()));
|
||||
course.removeWaypoint(0);
|
||||
assertEquals(0, Util.size(course.getWaypoints()));
|
||||
assertEquals(0, Util.size(course.getLegs()));
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ import com.sap.sailing.domain.base.Course;
|
||||
import com.sap.sailing.domain.base.CourseListener;
|
||||
import com.sap.sailing.domain.base.Leg;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.util.Util;
|
||||
|
||||
public class CourseImpl extends NamedImpl implements Course {
|
||||
private static final Logger logger = Logger.getLogger(CourseImpl.class.getName());
|
||||
@@ -28,9 +27,6 @@ public class CourseImpl extends NamedImpl implements Course {
|
||||
|
||||
public CourseImpl(String name, Iterable<Waypoint> waypoints) {
|
||||
super(name);
|
||||
if (Util.size(waypoints) == 1) {
|
||||
throw new IllegalArgumentException("Can't create a course with a single waypoint "+waypoints+"; this makes no leg");
|
||||
}
|
||||
listeners = new HashSet<CourseListener>();
|
||||
this.waypoints = new ArrayList<Waypoint>();
|
||||
waypointIndexes = new HashMap<Waypoint, Integer>();
|
||||
@@ -71,7 +67,9 @@ public class CourseImpl extends NamedImpl implements Course {
|
||||
} else {
|
||||
legStartWaypointIndex = zeroBasedPosition;
|
||||
}
|
||||
legs.add(new LegImpl(this, legStartWaypointIndex));
|
||||
if (waypoints.size() > 1) {
|
||||
legs.add(new LegImpl(this, legStartWaypointIndex));
|
||||
}
|
||||
notifyListenersWaypointAdded(zeroBasedPosition, waypointToAdd);
|
||||
}
|
||||
|
||||
@@ -81,7 +79,7 @@ public class CourseImpl extends NamedImpl implements Course {
|
||||
boolean isLast = zeroBasedPosition == waypoints.size()-1;
|
||||
Waypoint removedWaypoint = waypoints.remove(zeroBasedPosition);
|
||||
if (isLast) {
|
||||
if (waypoints.size() > 1) {
|
||||
if (waypoints.size() > 0) { // if we had only one waypoint, we didn't have any legs
|
||||
// last waypoint was removed; remove last leg
|
||||
legs.remove(legs.size() - 1);
|
||||
}
|
||||
|
||||
+5
-3
@@ -534,12 +534,14 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (toRemove == null) {
|
||||
if (toRemove == null && !trackedLegs.isEmpty()) {
|
||||
// last waypoint removed
|
||||
toRemove = last;
|
||||
}
|
||||
trackedLegs.remove(toRemove);
|
||||
updated(/* time point*/ null);
|
||||
if (toRemove != null) {
|
||||
trackedLegs.remove(toRemove);
|
||||
updated(/* time point*/ null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user