Package com.peterphi.std.guice.testing
Class GuiceUnit
java.lang.Object
org.junit.runner.Runner
org.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
org.junit.runners.BlockJUnit4ClassRunner
com.peterphi.std.guice.testing.GuiceUnit
- All Implemented Interfaces:
org.junit.runner.Describable
,org.junit.runner.manipulation.Filterable
,org.junit.runner.manipulation.Orderable
,org.junit.runner.manipulation.Sortable
public class GuiceUnit
extends org.junit.runners.BlockJUnit4ClassRunner
A JUnit runner for the guice framework; test classes are generally annotated with
GuiceConfig
to indicate the desired guice
environment customisation.
This implementation is based on Jukito's JukitoRunner-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected List<org.junit.runners.model.FrameworkMethod>
protected Object
protected org.junit.runners.model.Statement
methodBlock
(org.junit.runners.model.FrameworkMethod method) protected org.junit.runners.model.Statement
methodInvoker
(org.junit.runners.model.FrameworkMethod method, Object test) void
run
(org.junit.runner.notification.RunNotifier notifier) protected String
testName
(org.junit.runners.model.FrameworkMethod method) protected void
validateInstanceMethods
(List<Throwable> errors) Deprecated.protected void
validatePublicVoidMethods
(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) Adds toerrors
if any method in this class is annotated with the providedannotation
, but: is not public, or returns something other than void, or is static (givenisStatic is false
), or is not static (givenisStatic is true
).protected void
validateTestMethods
(List<Throwable> errors) Adds toerrors
for each method annotated with@Test
that is not a public, void instance method.protected org.junit.runners.model.Statement
withAfters
(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement) Deprecated.deprecated inBlockJUnit4ClassRunner
and going away in a future version.protected org.junit.runners.model.Statement
withBefores
(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement) Deprecated.deprecated inBlockJUnit4ClassRunner
and going away in a future version.Methods inherited from class org.junit.runners.BlockJUnit4ClassRunner
collectInitializationErrors, createTest, describeChild, getChildren, getTestRules, isIgnored, possiblyExpectingExceptions, rules, runChild, validateConstructor, validateFields, validateNoNonStaticInnerClass, validateOnlyOneConstructor, validateZeroArgConstructor, withPotentialTimeout
Methods inherited from class org.junit.runners.ParentRunner
childrenInvoker, classBlock, classRules, createTestClass, filter, getDescription, getName, getRunnerAnnotations, getTestClass, order, runLeaf, setScheduler, sort, validatePublicVoidNoArgMethods, withAfterClasses, withBeforeClasses, withInterruptIsolation
Methods inherited from class org.junit.runner.Runner
testCount
-
Constructor Details
-
GuiceUnit
Creates a BlockJUnit4ClassRunner to runclazz
- Parameters:
clazz
-- Throws:
org.junit.runners.model.InitializationError
- if the test class is malformed.
-
-
Method Details
-
createTest
- Overrides:
createTest
in classorg.junit.runners.BlockJUnit4ClassRunner
- Throws:
Exception
-
methodBlock
protected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod method) - Overrides:
methodBlock
in classorg.junit.runners.BlockJUnit4ClassRunner
-
run
public void run(org.junit.runner.notification.RunNotifier notifier) - Overrides:
run
in classorg.junit.runners.ParentRunner<org.junit.runners.model.FrameworkMethod>
-
methodInvoker
protected org.junit.runners.model.Statement methodInvoker(org.junit.runners.model.FrameworkMethod method, Object test) - Overrides:
methodInvoker
in classorg.junit.runners.BlockJUnit4ClassRunner
-
withBefores
protected org.junit.runners.model.Statement withBefores(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement) Deprecated.deprecated inBlockJUnit4ClassRunner
and going away in a future version. Should be changed to use Rules.Wrap a statement with logic that must run before it executes- Overrides:
withBefores
in classorg.junit.runners.BlockJUnit4ClassRunner
- Parameters:
method
-target
-statement
-- Returns:
-
withAfters
protected org.junit.runners.model.Statement withAfters(org.junit.runners.model.FrameworkMethod method, Object target, org.junit.runners.model.Statement statement) Deprecated.deprecated inBlockJUnit4ClassRunner
and going away in a future version. Should be changed to use Rules.Wrap a statement with logic that must run after it executes- Overrides:
withAfters
in classorg.junit.runners.BlockJUnit4ClassRunner
- Parameters:
method
-target
-statement
-- Returns:
-
testName
- Overrides:
testName
in classorg.junit.runners.BlockJUnit4ClassRunner
-
computeTestMethods
- Overrides:
computeTestMethods
in classorg.junit.runners.BlockJUnit4ClassRunner
-
validateInstanceMethods
Deprecated.deprecated inBlockJUnit4ClassRunner
and going away in a future versionAdds toerrors
for each method annotated with@Test
,@Before
, or@After
that is not a public, void instance method with no arguments.- Overrides:
validateInstanceMethods
in classorg.junit.runners.BlockJUnit4ClassRunner
-
validateTestMethods
Adds toerrors
for each method annotated with@Test
that is not a public, void instance method. Note: it is permitted to have arguments (superclass requires that methods have no arguments)- Overrides:
validateTestMethods
in classorg.junit.runners.BlockJUnit4ClassRunner
-
validatePublicVoidMethods
protected void validatePublicVoidMethods(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors) Adds toerrors
if any method in this class is annotated with the providedannotation
, but:- is not public, or
- returns something other than void, or
- is static (given
isStatic is false
), or - is not static (given
isStatic is true
).
- See Also:
-
validatePublicVoidNoArgMethods for a no-arg version of this validation
-
BlockJUnit4ClassRunner
and going away in a future version