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

    Constructors
    Constructor
    Description
    GuiceUnit(Class<?> clazz)
    Creates a BlockJUnit4ClassRunner to run clazz
  • Method Summary

    Modifier and Type
    Method
    Description
    protected 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
    Deprecated.
    deprecated in BlockJUnit4ClassRunner and going away in a future version
    protected void
    validatePublicVoidMethods(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors)
    Adds to errors if any method in this class is annotated with the provided annotation, 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).
    protected void
    Adds to errors for each method annotated with @Testthat 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 in BlockJUnit4ClassRunner 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 in BlockJUnit4ClassRunner 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GuiceUnit

      public GuiceUnit(Class<?> clazz) throws org.junit.runners.model.InitializationError
      Creates a BlockJUnit4ClassRunner to run clazz
      Parameters:
      clazz -
      Throws:
      org.junit.runners.model.InitializationError - if the test class is malformed.
  • Method Details

    • createTest

      protected Object createTest() throws Exception
      Overrides:
      createTest in class org.junit.runners.BlockJUnit4ClassRunner
      Throws:
      Exception
    • methodBlock

      protected org.junit.runners.model.Statement methodBlock(org.junit.runners.model.FrameworkMethod method)
      Overrides:
      methodBlock in class org.junit.runners.BlockJUnit4ClassRunner
    • run

      public void run(org.junit.runner.notification.RunNotifier notifier)
      Overrides:
      run in class org.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 class org.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 in BlockJUnit4ClassRunner 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 class org.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 in BlockJUnit4ClassRunner 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 class org.junit.runners.BlockJUnit4ClassRunner
      Parameters:
      method -
      target -
      statement -
      Returns:
    • testName

      protected String testName(org.junit.runners.model.FrameworkMethod method)
      Overrides:
      testName in class org.junit.runners.BlockJUnit4ClassRunner
    • computeTestMethods

      protected List<org.junit.runners.model.FrameworkMethod> computeTestMethods()
      Overrides:
      computeTestMethods in class org.junit.runners.BlockJUnit4ClassRunner
    • validateInstanceMethods

      @Deprecated protected void validateInstanceMethods(List<Throwable> errors)
      Deprecated.
      deprecated in BlockJUnit4ClassRunner and going away in a future version
      Adds to errors for each method annotated with @Test, @Before, or @After that is not a public, void instance method with no arguments.
      Overrides:
      validateInstanceMethods in class org.junit.runners.BlockJUnit4ClassRunner
    • validateTestMethods

      protected void validateTestMethods(List<Throwable> errors)
      Adds to errors for each method annotated with @Testthat is not a public, void instance method.

      Note: it is permitted to have arguments (superclass requires that methods have no arguments)

      Overrides:
      validateTestMethods in class org.junit.runners.BlockJUnit4ClassRunner
    • validatePublicVoidMethods

      protected void validatePublicVoidMethods(Class<? extends Annotation> annotation, boolean isStatic, List<Throwable> errors)
      Adds to errors if any method in this class is annotated with the provided annotation, 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