forked from greghaskins/spectrum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JUnit rules support. Includes supporting rules in the Test Class if …
…present, and supporting mix-in objects applied in the hierarchy as a special type of supplier. Updated the Hooks mechanism from greghaskins#77 to allow the passing of RunNotifier and Description around, and hooked in a private version of the rules handling code from JUnit which adapts from Hooks to Statement objects. Demonstrated the whole thing with Spring, Mockito and JUnit native rules, and managed to reverse some of the changes to exception handling brought by greghaskins#77
- Loading branch information
Ashley Frieze
committed
Jan 16, 2017
1 parent
659a38c
commit 00ed8a6
Showing
32 changed files
with
1,138 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
package com.greghaskins.spectrum; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runner.notification.RunNotifier; | ||
|
||
/** | ||
* A hook allows you to inject functionality before and/or after a {@link Block}. | ||
* Just implement the {@link ThrowingConsumer#acceptOrThrow(Object)} method and | ||
* Just implement the {@link #accept(Description, RunNotifier, Block)} method and | ||
* call {@link Block#run()} within your implementation. | ||
* If your hook is going to provide an object to the running test, then implement | ||
* {@link SupplyingHook} or subclass {@link AbstractSupplyingHook}. | ||
*/ | ||
public interface Hook extends ThrowingConsumer<Block> { | ||
public interface Hook { | ||
/** | ||
* Accept the block and execute it, hooking in any behaviour around it. | ||
* @param description description of where we are in the test | ||
* @param notifier the notifier for failures | ||
* @param block the block to execute | ||
* @throws Throwable on error | ||
*/ | ||
void accept(final Description description, final RunNotifier notifier, | ||
final Block block) throws Throwable; | ||
|
||
/** | ||
* Create a hook from a {@link ThrowingConsumer}. | ||
* @param consumer to turn into a hook | ||
* @return the hook | ||
*/ | ||
static Hook from(ThrowingConsumer<Block> consumer) { | ||
return (description, notifier, block) -> consumer.accept(block); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.