org.rhq.test
Class JMockTest

java.lang.Object
  extended by org.rhq.test.JMockTest
All Implemented Interfaces:
org.testng.IHookable, org.testng.IInvokedMethodListener, org.testng.ITestNGListener

public class JMockTest
extends Object
implements org.testng.IHookable, org.testng.IInvokedMethodListener

This class can either be used as a base class for tests using JMock or it also can be used as a TestNG listener to provide the JMock context to test classes that need to inherit from another class.

In the former case, the JMock context is accessible through the context protected field, while in the latter case (when JMockTest is specified as a listener of a test class), the JMock context is accessible using the getCurrentMockContext() static method.

Unlike the default behavior of the Listeners annotation which makes the supplied classes the listeners on ALL test methods in ALL classes, this implementation behaves differntly. It checks whether the Listeners annotation is specified on the class that the current test method is being executed on (or its superclasses) and only if it does, the test method is "augmented". This means that the classes can specify if they want to be augmented by JMockTest by specifying it as their listener.

Author:
John Sanda, Lukas Krejci

Field Summary
protected  org.jmock.Mockery context
           
 
Constructor Summary
JMockTest()
           
 
Method Summary
 void afterInvocation(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)
          Runs tearDownAfterTest(ITestResult).
 void beforeInvocation(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)
          Runs #initBeforeTest(ITestResult).
static org.jmock.Mockery getCurrentMockContext()
           
protected  void initBeforeTest(Object testObject, Method testMethod)
          Does whatever needs done before the test is invoked.
 void initMockContext(Method testMethod)
           
 void run(org.testng.IHookCallBack iHookCallBack, org.testng.ITestResult iTestResult)
          This method runs #initBeforeTest(ITestResult), followed by the actual test, followed by tearDownAfterTest(ITestResult).
protected  void tearDownAfterTest(org.testng.ITestResult result)
          Does whatever needs done after the test has been invoked.
 void tearDownMockContext(org.testng.ITestResult testResult)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected org.jmock.Mockery context
Constructor Detail

JMockTest

public JMockTest()
Method Detail

getCurrentMockContext

public static org.jmock.Mockery getCurrentMockContext()
Returns:
the JMock context of the current test or null if the calling test class doesn't have this class set as a listener or doesn't inherit from this class.

initMockContext

public final void initMockContext(Method testMethod)

tearDownMockContext

public final void tearDownMockContext(org.testng.ITestResult testResult)

run

public final void run(org.testng.IHookCallBack iHookCallBack,
                      org.testng.ITestResult iTestResult)
This method runs #initBeforeTest(ITestResult), followed by the actual test, followed by tearDownAfterTest(ITestResult).

If you want to modify the behavior of this method, override the above mentioned methods.

Specified by:
run in interface org.testng.IHookable
See Also:
IHookable.run(IHookCallBack, ITestResult)

beforeInvocation

public final void beforeInvocation(org.testng.IInvokedMethod method,
                                   org.testng.ITestResult testResult)
Runs #initBeforeTest(ITestResult).

Specified by:
beforeInvocation in interface org.testng.IInvokedMethodListener
See Also:
IInvokedMethodListener.beforeInvocation(IInvokedMethod, ITestResult)

afterInvocation

public final void afterInvocation(org.testng.IInvokedMethod method,
                                  org.testng.ITestResult testResult)
Runs tearDownAfterTest(ITestResult).

Specified by:
afterInvocation in interface org.testng.IInvokedMethodListener
See Also:
IInvokedMethodListener.afterInvocation(IInvokedMethod, ITestResult)

initBeforeTest

protected void initBeforeTest(Object testObject,
                              Method testMethod)
Does whatever needs done before the test is invoked.

If you override this method, be sure to call this method before your code so that you gain access to the context.

Parameters:
testResult -

tearDownAfterTest

protected void tearDownAfterTest(org.testng.ITestResult result)
Does whatever needs done after the test has been invoked.

This method calls Mockery.assertIsSatisfied() and nulls out the context.

If you override this method, call this implmentation as the last call in your code.

Parameters:
result -


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.