Merge remote-tracking branch 'origin/gwt' into gwt-5

This commit is contained in:
fmittag committed 2011-11-21 14:07:33 +01:00
commit 088fca8de1
4 files changed
+115 -14

No files matched your search

@@ -1,12 +1,13 @@
package diffutils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import difflib.DiffUtils;
import difflib.Patch;
import difflib.PatchFailedException;
import junit.framework.TestCase;
import java.util.Arrays;
import java.util.List;
public class PatchTest extends TestCase {
@@ -45,4 +46,19 @@ public class PatchTest extends TestCase {
fail(e.getMessage());
}
}
public void testPatch_EntirelyDifferent() {
final List<String> changeTest_from = new ArrayList<String>();
changeTest_from.add("aaa");
changeTest_from.add("bbb");
final List<String> changeTest_to = Arrays.asList("ccc", "ddd");
final Patch<String> patch = DiffUtils.diff(changeTest_from, changeTest_to);
try {
patch.applyToInPlace(changeTest_from);
assertEquals(changeTest_to, changeTest_from);
} catch (PatchFailedException e) {
fail(e.getMessage());
}
}
}
@@ -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,8 +79,10 @@ public class CourseImpl extends NamedImpl implements Course {
boolean isLast = zeroBasedPosition == waypoints.size()-1;
Waypoint removedWaypoint = waypoints.remove(zeroBasedPosition);
if (isLast) {
// last waypoint was removed; remove last leg
legs.remove(legs.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);
}
} else {
legs.remove(zeroBasedPosition);
}
@@ -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