Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added 'and_that' and 'and_to' methods

  • Loading branch information...
commit 333f2d749952935c2ee80a10c31671e0bdc1ee89 1 parent 5042c47
Eric Lefevre-Ardant authored
View
4 src/main/java/com/youdevise/test/narrative/Given.java
@@ -27,4 +27,8 @@ private Given(ACTOR actor) {
actor.perform(action);
return this;
}
+
+ public Given<TOOL, ACTOR> and_to(Action<TOOL, ACTOR> action) {
+ return was_able_to(action);
+ }
}
View
4 src/main/java/com/youdevise/test/narrative/Then.java
@@ -31,4 +31,8 @@ private Then(ACTOR actor) {
assertThat(actor.grabUsing(expected), matcher);
return this;
}
+
+ public <DATA> Then<TOOL, ACTOR> and_that(Extractor<DATA, ACTOR> expected, Matcher<? super DATA> matcher) {
+ return expects_that(expected, matcher);
+ }
}
View
4 src/main/java/com/youdevise/test/narrative/When.java
@@ -28,4 +28,8 @@ private When(ACTOR actor) {
actor.perform(action);
return this;
}
+
+ public When<TOOL, ACTOR> and_to(Action<TOOL, ACTOR> action) {
+ return attempts_to(action);
+ }
}
View
25 src/test/java/com/youdevise/test/narrative/GivenTest.java
@@ -39,6 +39,29 @@
}});
Given.the(actor).was_able_to(action)
- .was_able_to(otherAction);
+ .and_to(otherAction);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test public void
+ canMixCallsTo_WasAbleTo_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);
+ }});
+
+ Given.the(actor).and_to(firstAction)
+ .was_able_to(secondAction)
+ .and_to(thirdAction)
+ .was_able_to(fourthAction);
}
}
View
24 src/test/java/com/youdevise/test/narrative/ThenTest.java
@@ -68,7 +68,29 @@
}});
Then.the(actor).expects_that(characterExtractor, is('a'))
- .expects_that(stringExtractor, is("string"));
+ .and_that(stringExtractor, is("string"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test public void
+ canMixCallsTo_ExpectsThat_AndTo_AndThat() {
+ final StringActor actor = context.mock(StringActor.class);
+ final Extractor<Character, StringActor> characterExtractor = context.mock(Extractor.class, "character extractor");
+ final Extractor<String, StringActor> stringExtractor = context.mock(Extractor.class, "string extractor");
+ final Extractor<Integer, StringActor> intExtractor = context.mock(Extractor.class, "int extractor");
+ final Extractor<Double, StringActor> doubleExtractor = context.mock(Extractor.class, "double extractor");
+
+ context.checking(new Expectations() {{
+ oneOf(actor).grabUsing(characterExtractor); will(returnValue('a'));
+ oneOf(actor).grabUsing(stringExtractor); will(returnValue("string"));
+ oneOf(actor).grabUsing(intExtractor); will(returnValue(1));
+ oneOf(actor).grabUsing(doubleExtractor); will(returnValue(2.5));
+ }});
+
+ Then.the(actor).and_that(characterExtractor, is('a'))
+ .and_that(stringExtractor, is("string"))
+ .expects_that(intExtractor, is(1))
+ .expects_that(doubleExtractor, is(2.5));
}
@SuppressWarnings("unchecked")
View
25 src/test/java/com/youdevise/test/narrative/WhenTest.java
@@ -39,6 +39,29 @@
}});
When.the(actor).attempts_to(action)
- .attempts_to(otherAction);
+ .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);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.