gui: fix jump manager

This commit is contained in:
Skylot
2014-09-20 13:00:20 +04:00
parent 46c8572887
commit 0bc37e5d32
2 changed files with 17 additions and 3 deletions
@@ -26,7 +26,7 @@ public class JumpManager {
}
private Position getCurrent() {
if (currentPos < list.size()) {
if (currentPos >= 0 && currentPos < list.size()) {
return list.get(currentPos);
}
return null;
@@ -41,9 +41,14 @@ public class JumpManager {
}
public Position getNext() {
int size = list.size();
if (size == 0) {
currentPos = 0;
return null;
}
int newPos = currentPos + 1;
if (newPos >= list.size()) {
currentPos = list.size() - 1;
if (newPos >= size) {
currentPos = size - 1;
return null;
}
Position position = list.get(newPos);
@@ -18,6 +18,15 @@ class TestJumpManager extends Specification {
jm.getNext() == null
}
def "empty history 2"() {
expect:
jm.getPrev() == null
jm.getNext() == null
jm.getPrev() == null
jm.getNext() == null
jm.getPrev() == null
}
def "1 element"() {
when:
jm.addPosition(Mock(Position))