fixed bug in CourseImpl where deleting the last waypoint caused an exception while trying to delete non-existing leg

This commit is contained in:
Axel Uhl committed 2011-11-21 13:47:50 +01:00
1 parent 37d3f2d8ea
commit f360f8db3f
2 files changed
+24 -6

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());
}
}
}
@@ -81,8 +81,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() > 1) {
// last waypoint was removed; remove last leg
legs.remove(legs.size() - 1);
}
} else {
legs.remove(zeroBasedPosition);
}