View Javadoc

1   package com.atlassian.webdriver.testing.runner;
2   
3   import com.atlassian.pageobjects.inject.InjectionContext;
4   import org.junit.runner.notification.RunNotifier;
5   import org.junit.runners.BlockJUnit4ClassRunner;
6   import org.junit.runners.model.FrameworkMethod;
7   import org.junit.runners.model.InitializationError;
8   import org.junit.runners.model.Statement;
9   
10  /**
11   * A JUnit runner that injects all the page bindery things into your tests.
12   *
13   * @since 2.1.
14   */
15  public abstract class AbstractInjectingRunner extends BlockJUnit4ClassRunner
16  {
17  
18      /**
19       * Constructor compatible with the underlying default JUnit4 runner.
20       *
21       * @throws org.junit.runners.model.InitializationError
22       *          if the test class is malformed.
23       */
24      public AbstractInjectingRunner(Class<?> klass) throws InitializationError
25      {
26          super(klass);
27      }
28  
29      @Override
30      protected Statement classBlock(RunNotifier notifier)
31      {
32          getInjectionContext().injectStatic(getTestClass().getJavaClass());
33          return super.classBlock(notifier);
34      }
35  
36      @Override
37      protected Statement methodInvoker(FrameworkMethod method, Object test)
38      {
39          getInjectionContext().injectMembers(test);
40          return super.methodInvoker(method, test);
41      }
42  
43  
44      protected abstract InjectionContext getInjectionContext();
45  }