com.google.testing.threadtester
Class MainRunnableImpl<T>

java.lang.Object
  extended by com.google.testing.threadtester.MainRunnableImpl<T>
Type Parameters:
T - the type under test. It is expected that the runnable will invoke a method on this class in its ThrowingRunnable.run() method.
All Implemented Interfaces:
MainRunnable<T>, ThrowingRunnable

public abstract class MainRunnableImpl<T>
extends Object
implements MainRunnable<T>

Implementation of MainRunnable with empty methods. Provided as a convenience class, so that subclasses only need to implement the methods that they need.

Author:
alasdair.mackintosh@gmail.com (Alasdair Mackintosh)

Constructor Summary
MainRunnableImpl()
           
 
Method Summary
 Class<T> getClassUnderTest()
          Returns the class being tested by this runnable.
 T getMainObject()
          Gets the main object being tested.
 Method getMethod()
          Gets the method being tested by this runnable.
 String getMethodName()
          Gets the name of the method being tested by this runnable.
 void initialize()
          Invoked by the framework before running this runnable.
 void terminate()
          Invoked by the framework after running this runnable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.google.testing.threadtester.ThrowingRunnable
run
 

Constructor Detail

MainRunnableImpl

public MainRunnableImpl()
Method Detail

getClassUnderTest

public Class<T> getClassUnderTest()
Description copied from interface: MainRunnable
Returns the class being tested by this runnable. The class should be instrumented. If this runnable is not testing an instrumented class, then this method may return null.

Specified by:
getClassUnderTest in interface MainRunnable<T>
See Also:
ClassInstrumentation, Instrumentation

getMethodName

public String getMethodName()
Description copied from interface: MainRunnable
Gets the name of the method being tested by this runnable. The runnable is expected to call this method during its own Runnable.run() method. If this runnable is not testing an instrumented class, then this method may return null. May return null if MainRunnable.getMethod() does not.

Specified by:
getMethodName in interface MainRunnable<T>

getMethod

public Method getMethod()
                 throws NoSuchMethodException
Description copied from interface: MainRunnable
Gets the method being tested by this runnable. The runnable is expected to call this method during its own Thread.run() method. If this runnable is not testing an instrumented class, then this method may return null.

May throw a NoSuchMethodException if the method cannot be found. This will cause the InterleavedRunner to throw an IllegalArgumentException. May return null if MainRunnable.getMethodName() does not.

Specified by:
getMethod in interface MainRunnable<T>
Throws:
NoSuchMethodException

initialize

public void initialize()
                throws Exception
Description copied from interface: MainRunnable
Invoked by the framework before running this runnable. This method will be called once at the start of each iteration. Any object creation or initialization code can be placed here. Any exceptions thrown will be passed back to the caller of InterleavedRunner.interleave(M, com.google.testing.threadtester.SecondaryRunnable).

Specified by:
initialize in interface MainRunnable<T>
Throws:
Exception

getMainObject

public T getMainObject()
Description copied from interface: MainRunnable
Gets the main object being tested. The runnable is expected to invoke the test method (see MainRunnable.getMethod() on this object. This method will not be called until MainRunnable.initialize() has been called. Typical implementations will create a new instance of the test object in MainRunnable.initialize(), and return it here.

Specified by:
getMainObject in interface MainRunnable<T>
See Also:
SecondaryRunnable.initialize(M)

terminate

public void terminate()
               throws Exception
Description copied from interface: MainRunnable
Invoked by the framework after running this runnable. Any test verification code can be placed here. Note that any exceptions thrown will be passed back to the caller of InterleavedRunner.interleave(M, com.google.testing.threadtester.SecondaryRunnable).

Specified by:
terminate in interface MainRunnable<T>
Throws:
Exception
See Also:
RunResult


Copyright © 2013. All Rights Reserved.