/
WhenTest.java
67 lines (55 loc) · 2.62 KB
/
WhenTest.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.youdevise.test.narrative;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.Sequence;
import org.jmock.integration.junit4.JMock;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(JMock.class)
public class WhenTest {
private Mockery context = new Mockery();
@SuppressWarnings("unchecked")
@Test public void
usesTheActorToPerformTheAction() {
final StringActor actor = context.mock(StringActor.class);
final Action<String, StringActor> action = context.mock(Action.class);
context.checking(new Expectations() {{
oneOf(actor).perform(action);
}});
When.the(actor).attempts_to(action);
}
@SuppressWarnings("unchecked")
@Test public void
canPerformanManyActionsInARow() {
final StringActor actor = context.mock(StringActor.class);
final Action<String, StringActor> action = context.mock(Action.class, "action");
final Action<String, StringActor> otherAction = context.mock(Action.class, "other action");
final Sequence orderOfActions = context.sequence("Order of the actions");
context.checking(new Expectations() {{
oneOf(actor).perform(action); inSequence(orderOfActions);
oneOf(actor).perform(otherAction); inSequence(orderOfActions);
}});
When.the(actor).attempts_to(action)
.and_to(otherAction);
}
@SuppressWarnings("unchecked")
@Test public void
canMixCallsTo_AttempsTo_AndTo_AndTo() {
final StringActor actor = context.mock(StringActor.class);
final Action<String, StringActor> firstAction = context.mock(Action.class, "first action");
final Action<String, StringActor> secondAction = context.mock(Action.class, "second action");
final Action<String, StringActor> thirdAction = context.mock(Action.class, "third action");
final Action<String, StringActor> fourthAction = context.mock(Action.class, "fourth action");
final Sequence orderOfActions = context.sequence("Order of the actions");
context.checking(new Expectations() {{
oneOf(actor).perform(firstAction); inSequence(orderOfActions);
oneOf(actor).perform(secondAction); inSequence(orderOfActions);
oneOf(actor).perform(thirdAction); inSequence(orderOfActions);
oneOf(actor).perform(fourthAction); inSequence(orderOfActions);
}});
When.the(actor).and_to(firstAction)
.and_to(secondAction)
.and_to(thirdAction)
.attempts_to(fourthAction);
}
}