Skip to content

Commit

Permalink
Call Reporter#hookFail explicitly from runners
Browse files Browse the repository at this point in the history
  • Loading branch information
joebandenburg committed Apr 11, 2016
1 parent 38db056 commit 6c1ca97
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,17 @@ private void runTest(Test test, List<TestBlockRunner> testParents) {
}

private boolean runTestHooks(HookType hookType, Test test, List<TestBlock> testParents) {
return runHooks(testBlock.hooksOfType(hookType), (hook, e) ->
reporter.testHookFail(hook, blocksFromRunners(parentsIncludeThis()), test, testParents, e));
return runHooks(testBlock.hooksOfType(hookType), (hook, e) -> {
reporter.testHookFail(hook, blocksFromRunners(parentsIncludeThis()), test, testParents, e);
reporter.hookFail(hook, blocksFromRunners(parentsIncludeThis()), e);
});
}

private boolean runBlockHooks(HookType hookType) {
return runHooks(testBlock.hooksOfType(hookType),
(hook, e) -> reporter.blockHookFail(hook, blocksFromRunners(parentsIncludeThis()), e));
return runHooks(testBlock.hooksOfType(hookType), (hook, e) -> {
reporter.blockHookFail(hook, blocksFromRunners(parentsIncludeThis()), e);
reporter.hookFail(hook, blocksFromRunners(parentsIncludeThis()), e);
});
}

private boolean runHooks(List<Hook> hooks, BiConsumer<Hook, Throwable> failHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public void testHookFail(Hook hook, List<TestBlock> hookParents, Test test, List
reporters.forEach(r -> r.testHookFail(hook, hookParents, test, testParents, cause));
}

@Override
public void hookFail(Hook hook, List<TestBlock> parents, Throwable cause) {
reporters.forEach(r -> r.hookFail(hook, parents, cause));
}

@Override
public void testStart(Test test, List<TestBlock> parents) {
reporters.forEach(r -> r.testStart(test, parents));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ public void testBlockEnd(TestBlock testBlock, List<TestBlock> parents) {
}

@Override
public void hookFail(Hook hook, List<TestBlock> parents, Throwable cause) {
public void testHookFail(Hook hook, List<TestBlock> hookParents, Test test, List<TestBlock> testParents,
Throwable cause) {
blockHookFail(hook, hookParents, cause);
}

@Override
public void blockHookFail(Hook hook, List<TestBlock> parents, Throwable cause) {
failed++;
failures.add(new TestFailure(ReporterSupport.getFullDescription(hook, parents), cause));
stream.println(getIndent() + failures.size() + ") " + ReporterSupport.getDescription(hook));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ default void testBlockEnd(TestBlock testBlock, List<TestBlock> parents) {
*/
default void testHookFail(Hook hook, List<TestBlock> hookParents, Test test, List<TestBlock> testParents,
Throwable cause) {
hookFail(hook, hookParents, cause);
}

/**
Expand All @@ -84,15 +83,17 @@ default void testHookFail(Hook hook, List<TestBlock> hookParents, Test test, Lis
* @param cause The throwable that the hook threw.
*/
default void blockHookFail(Hook hook, List<TestBlock> parents, Throwable cause) {
hookFail(hook, parents, cause);
}
/**
* Called when a hook failed due to it throwing an exception.
*
* @param hook The hook that threw an exception.
* @param parents The ancestor test blocks, starting with the root block and ending with the immediate parent.
* @param cause The throwable that the hook threw.
* @deprecated Use {@link Reporter#testHookFail(Hook, List, Test, List, Throwable)} and
* {@link Reporter#blockHookFail(Hook, List, Throwable)} instead.
*/
@Deprecated
default void hookFail(Hook hook, List<TestBlock> parents, Throwable cause) {
}

Expand Down
10 changes: 10 additions & 0 deletions cuppa/src/test/java/org/forgerock/cuppa/ExecutionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public void verifyExecutionWithOuterBeforeHookFailure() throws Exception {
verifyStart();
order.verify(outerBeforeFn1).apply();
order.verify(reporter).blockHookFail(outerBefore1, parentsOfOuterChildren, exception);
order.verify(reporter).hookFail(outerBefore1, parentsOfOuterChildren, exception);
order.verify(reporter).testSkip(outerTest1, parentsOfOuterChildren);
order.verify(reporter).testSkip(outerTest2, parentsOfOuterChildren);
verifySkipNested1Execution();
Expand All @@ -262,6 +263,7 @@ public void verifyExecutionWithOuterAfterHookFailure() throws Exception {
verifyNormalNested2Execution();
order.verify(outerAfterFn1).apply();
order.verify(reporter).blockHookFail(outerAfter1, parentsOfOuterChildren, exception);
order.verify(reporter).hookFail(outerAfter1, parentsOfOuterChildren, exception);
verifyEnd();
}

Expand All @@ -277,6 +279,7 @@ public void verifyExecutionWithOuterBeforeEachHookFailure() throws Exception {
order.verify(outerBeforeEachFn1).apply();
order.verify(reporter).testHookFail(outerBeforeEach1, parentsOfOuterChildren, outerTest1,
parentsOfOuterChildren, exception);
order.verify(reporter).hookFail(outerBeforeEach1, parentsOfOuterChildren, exception);
order.verify(reporter).testSkip(outerTest1, parentsOfOuterChildren);
order.verify(outerAfterEachFn1).apply();
order.verify(outerAfterEachFn2).apply();
Expand Down Expand Up @@ -305,6 +308,7 @@ public void verifyExecutionWithOuterBeforeEachHookFailureOnSecondCall() throws E
order.verify(outerBeforeEachFn1).apply();
order.verify(reporter).testHookFail(outerBeforeEach1, parentsOfOuterChildren, outerTest2,
parentsOfOuterChildren, exception);
order.verify(reporter).hookFail(outerBeforeEach1, parentsOfOuterChildren, exception);
order.verify(reporter).testSkip(outerTest2, parentsOfOuterChildren);
order.verify(outerAfterEachFn1).apply();
order.verify(outerAfterEachFn2).apply();
Expand All @@ -328,6 +332,7 @@ public void verifyExecutionWithOuterBeforeEachHookFailureOnThirdCall() throws Ex
order.verify(outerBeforeEachFn1).apply();
order.verify(reporter).testHookFail(outerBeforeEach1, parentsOfOuterChildren, nested1Test1,
parentsOfNested1Children, exception);
order.verify(reporter).hookFail(outerBeforeEach1, parentsOfOuterChildren, exception);
order.verify(reporter).testSkip(nested1Test1, parentsOfNested1Children);
order.verify(outerAfterEachFn1).apply();
order.verify(outerAfterEachFn2).apply();
Expand Down Expand Up @@ -355,6 +360,7 @@ public void verifyExecutionWithOuterAfterEachHookFailure() throws Exception {
order.verify(outerAfterEachFn1).apply();
order.verify(reporter).testHookFail(outerAfterEach1, parentsOfOuterChildren, outerTest1, parentsOfOuterChildren,
exception);
order.verify(reporter).hookFail(outerAfterEach1, parentsOfOuterChildren, exception);
order.verify(reporter).testSkip(outerTest2, parentsOfOuterChildren);
verifySkipNested1Execution();
verifySkipNested2Execution();
Expand All @@ -374,6 +380,7 @@ public void verifyExecutionWithNested1BeforeHookFailure() throws Exception {
order.verify(reporter).testBlockStart(nested1, parentsOfOuterChildren);
order.verify(nested1BeforeFn).apply();
order.verify(reporter).blockHookFail(nested1Before, parentsOfNested1Children, exception);
order.verify(reporter).hookFail(nested1Before, parentsOfNested1Children, exception);
order.verify(reporter).testSkip(nested1Test1, parentsOfNested1Children);
order.verify(reporter).testSkip(nested1Test2, parentsOfNested1Children);
order.verify(nested1AfterFn).apply();
Expand Down Expand Up @@ -410,6 +417,7 @@ public void verifyExecutionWithNested1AfterHookFailure() throws Exception {
order.verify(outerAfterEachFn2).apply();
order.verify(nested1AfterFn).apply();
order.verify(reporter).blockHookFail(nested1After, parentsOfNested1Children, exception);
order.verify(reporter).hookFail(nested1After, parentsOfNested1Children, exception);
order.verify(reporter).testBlockEnd(nested1, parentsOfOuterChildren);
verifyNormalNested2Execution();
order.verify(outerAfterFn1).apply();
Expand All @@ -432,6 +440,7 @@ public void verifyExecutionWithNested1BeforeEachHookFailure() throws Exception {
order.verify(nested1BeforeEachFn).apply();
order.verify(reporter).testHookFail(nested1BeforeEach, parentsOfNested1Children, nested1Test1,
parentsOfNested1Children, exception);
order.verify(reporter).hookFail(nested1BeforeEach, parentsOfNested1Children, exception);
order.verify(reporter).testSkip(nested1Test1, parentsOfNested1Children);
order.verify(nested1AfterEachFn).apply();
order.verify(outerAfterEachFn1).apply();
Expand Down Expand Up @@ -462,6 +471,7 @@ public void verifyExecutionWithNested1AfterEachHookFailure() throws Exception {
order.verify(nested1AfterEachFn).apply();
order.verify(reporter).testHookFail(nested1AfterEach, parentsOfNested1Children, nested1Test1,
parentsOfNested1Children, exception);
order.verify(reporter).hookFail(nested1AfterEach, parentsOfNested1Children, exception);
order.verify(outerAfterEachFn1).apply();
order.verify(outerAfterEachFn2).apply();
order.verify(reporter).testSkip(nested1Test2, parentsOfNested1Children);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public void shouldCallTestHookFail() {
order.verify(mockReporter2).testHookFail(hook, parents, test, parents, cause);
}

@Test
public void shouldCallBHookFail() {
reporter.hookFail(hook, parents, cause);
order.verify(mockReporter1).hookFail(hook, parents, cause);
order.verify(mockReporter2).hookFail(hook, parents, cause);
}

@Test
public void shouldCallTestStart() {
reporter.testStart(test, parents);
Expand Down

0 comments on commit 6c1ca97

Please sign in to comment.