2016/02/07 - Apache Onami has been retired.

For more information, please explore the Attic.

public class

OnamiRunner

extends BlockJUnit4ClassRunner
java.lang.Object
   ↳ org.junit.runner.Runner
     ↳ org.junit.runners.ParentRunner<T>
       ↳ org.junit.runners.BlockJUnit4ClassRunner
         ↳ org.apache.onami.test.OnamiRunner

Class Overview

It's a BlockJUnit4ClassRunner runner.

This class creates a Google Guice Injector configured by GuiceModules annotation (only fr modules with default constructor) and GuiceProvidedModules annotation and Mock.

Example #1:

 
 @org.junit.runner.RunWith( OnamiRunner.class )
 @GuiceModules( SimpleModule.class )
 public class AcmeTestCase
 {
 
     @GuiceProvidedModules
     static public Module getProperties()
     {
         ...
         return Modules.combine(new ComplexModule( loadProperies() ), ...  );
     }
 
 

Example #2:

 
 @org.junit.runner.RunWith( OnamiRunner.class )
 public class AcmeTestCase
     extends com.google.inject.AbstractModule
 {
 
     public void configure()
     {
         // Configure your proper modules
         ...
         bind( Service.class ).annotatedWith( TestAnnotation.class ).to( ServiceTestImpl.class );
         ...
     }
 
     @Mock
     private AnotherService serviceMock;
 
     @Inject
     private Service serviceTest;
 
     @org.junit.Test
     public void test()
     {
         assertNotNull( serviceMock );
         assertNotNull( serviceTest );
     }
 

See Also

Summary

Public Constructors
OnamiRunner(Class<?> klass)
OnamiRunner constructor to create the core JUnice class.
Public Methods
void run(RunNotifier notifier)
Protected Methods
Injector createInjector(List<Module> modules)
Shortcut to create the Injector given a list of Modules.
Object createTest()
Creates test instance via Google-Guice to inject all not-static dependencies.
<T> List<Module> inizializeInjector(Class<T> clazz)
This method collects modules from GuiceModules, GuiceProvidedModules, Mock.
void runChild(FrameworkMethod method, RunNotifier notifier)
[Expand]
Inherited Methods
From class org.junit.runners.BlockJUnit4ClassRunner
From class org.junit.runners.ParentRunner
From class org.junit.runner.Runner
From class java.lang.Object
From interface org.junit.runner.Describable
From interface org.junit.runner.manipulation.Filterable
From interface org.junit.runner.manipulation.Sortable

Public Constructors

public OnamiRunner (Class<?> klass)

OnamiRunner constructor to create the core JUnice class.

Parameters
klass The test case class to run.
Throws
InitializationError if any error occurs.
See Also
  • org.junit.runner.RunWith

Public Methods

public void run (RunNotifier notifier)

Protected Methods

protected Injector createInjector (List<Module> modules)

Shortcut to create the Injector given a list of Modules.

Parameters
modules the list of modules have to be load
Returns
  • an Injector instance built using the input Module list

protected Object createTest ()

Creates test instance via Google-Guice to inject all not-static dependencies.

Returns
  • The instance of the test case.
Throws
Exception when an error occurs.

protected List<Module> inizializeInjector (Class<T> clazz)

This method collects modules from GuiceModules, GuiceProvidedModules, Mock.

Parameters
clazz the input class has to be analyzed
Returns
  • a List of Guice Modules built after input class analysis.
Throws
IllegalAccessException when a n error occurs.
InstantiationException when a n error occurs.
HandleException when a n error occurs.

protected void runChild (FrameworkMethod method, RunNotifier notifier)