blob: 372bbda9b71653c2701b20f654d84851ad5eec0d (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package au.id.zancanaro.javacheck.state.queue.commands;
import au.id.zancanaro.javacheck.state.Command;
import au.id.zancanaro.javacheck.state.CommandValue;
import au.id.zancanaro.javacheck.state.queue.QueueState;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
public class Poll<T> extends Command<QueueState<T>, Void, T> {
@Override
public boolean preCondition(QueueState<T> state, Void args) {
return state != null && !state.getAbstractQueue().isEmpty();
}
@Override
public T runCommand(QueueState<T> state, Void args) {
return state.getConcreteQueue().poll();
}
@Override
public QueueState<T> nextState(QueueState<T> state, Void args, CommandValue<T> result) {
List<T> newState = new ArrayList<>(state.getAbstractQueue());
newState.remove(0);
return state.withAbstractQueue(newState);
}
@Override
public void postCondition(QueueState<T> oldState, QueueState<T> newState, Void args, T result) {
assertEquals(oldState.getAbstractQueue().get(0), result);
}
}
|