gui: fix jump manager
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user