|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object junit.framework.Assert junit.framework.TestCase org.apache.hivemind.test.HiveMindTestCase
public abstract class HiveMindTestCase
Contains some support for creating HiveMind tests; this is useful enough that has been moved into the main framework, to simplify creation of tests in the dependent libraries.
Field Summary | |
---|---|
protected org.apache.hivemind.test.StoreAppender |
_appender
|
protected java.lang.String |
_interceptedLoggerName
|
Constructor Summary | |
---|---|
HiveMindTestCase()
|
Method Summary | |
---|---|
protected void |
addControl(org.easymock.MockControl control)
Adds the control to the list of managed controls used by replayControls() and
verifyControls() . |
protected void |
assertExceptionRegexp(java.lang.Throwable ex,
java.lang.String pattern)
Checks that the message for an exception matches a regular expression. |
protected void |
assertExceptionSubstring(java.lang.Throwable ex,
java.lang.String substring)
Checks that the provided substring exists in the exceptions message. |
protected static void |
assertListsEqual(java.lang.Object[] expected,
java.util.List actual)
Converts the actual list to an array and invokes assertListsEqual(Object[], Object[]) . |
protected static void |
assertListsEqual(java.lang.Object[] expected,
java.lang.Object[] actual)
Asserts that the two arrays are equal; same length and all elements equal. |
protected void |
assertLoggedMessage(java.lang.String message)
Asserts that some capture log event matches the given message exactly. |
protected void |
assertLoggedMessage(java.lang.String message,
java.util.List events)
Asserts that some capture log event matches the given message exactly. |
protected void |
assertLoggedMessagePattern(java.lang.String pattern)
|
protected void |
assertLoggedMessagePattern(java.lang.String pattern,
java.util.List events)
|
protected void |
assertLoggedMessages(java.lang.String[] messages)
Checks the messages for all logged events for exact match against the supplied list. |
protected void |
assertRegexp(java.lang.String pattern,
java.lang.String actual)
|
protected Registry |
buildFrameworkRegistry(ModuleDefinition customModule)
|
protected Registry |
buildFrameworkRegistry(ModuleDefinition[] customModules)
Builds a registry, containing only the modules delivered the parameter customModules , plus the master module descriptor
(i.e., those visible on the classpath). |
protected Registry |
buildMinimalRegistry(Resource l)
Builds a registry from exactly the provided resource; this registry will not include the hivemind module. |
protected Location |
fabricateLocation(int line)
Deprecated. To be removed in 1.2. Use newLocation() instead. |
protected java.lang.Throwable |
findNestedException(ApplicationRuntimeException ex)
Digs down through (potentially) a stack of ApplicationRuntimeExceptions until it reaches the originating exception, which is returned. |
protected ClassResolver |
getClassResolver()
Returns a DefaultClassResolver . |
protected org.easymock.MockControl |
getControl(java.lang.Object mock)
Accesses the control for a previously created mock object. |
protected java.util.List |
getInterceptedLogEvents()
Gets the list of events most recently intercepted. |
protected Resource |
getResource(java.lang.String file)
Returns the given file as a Resource from the classpath. |
protected void |
interceptLogging(java.lang.String loggerName)
Sets up an appender to intercept logging for the specified logger. |
protected boolean |
matches(java.lang.String input,
java.lang.String pattern)
|
protected org.easymock.MockControl |
newControl(java.lang.Class mockClass)
Creates a managed control via MockControl.createStrictControl(java.lang.Class) . |
protected Location |
newLocation()
Returns a new Location instance. |
protected java.lang.Object |
newMock(java.lang.Class mockClass)
Convienience for invoking newControl(Class) and then invoking
MockControl.getMock() on the result. |
protected void |
replayControls()
Invokes MockControl.replay() on all controls created by newControl(Class) . |
protected void |
resetControls()
Invokes MockControl.reset() on all controls. |
protected void |
setReturnValue(java.lang.Object mock,
boolean returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setReturnValue(java.lang.Object mock,
double returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setReturnValue(java.lang.Object mock,
float returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setReturnValue(java.lang.Object mock,
long returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setReturnValue(java.lang.Object mock,
java.lang.Object returnValue)
Invoked when training a mock object to set the return value for the most recently invoked method. |
protected void |
setThrowable(java.lang.Object mock,
java.lang.Throwable t)
Invoked when training a mock object to set the Throwable for the most recently invoked method. |
protected void |
tearDown()
Removes the appender that may have been setup by interceptLogging(String) . |
protected static void |
unreachable()
Called when code should not be reachable (because a test is expected to throw an exception); throws AssertionFailedError always. |
protected void |
verifyControls()
Invokes MockControl.verify() and MockControl.reset() on all
controls created by newControl(Class) . |
Methods inherited from class junit.framework.TestCase |
---|
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, toString |
Methods inherited from class junit.framework.Assert |
---|
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.lang.String _interceptedLoggerName
protected org.apache.hivemind.test.StoreAppender _appender
Constructor Detail |
---|
public HiveMindTestCase()
Method Detail |
---|
protected Resource getResource(java.lang.String file)
Resource
from the classpath. Typically, this is to find
files in the same folder as the invoking class.
protected static void assertListsEqual(java.lang.Object[] expected, java.util.List actual)
assertListsEqual(Object[], Object[])
.
protected static void assertListsEqual(java.lang.Object[] expected, java.lang.Object[] actual)
protected static void unreachable()
protected void interceptLogging(java.lang.String loggerName)
getInterceptedLogEvents()
.
protected java.util.List getInterceptedLogEvents()
interceptLogging(String)
protected void tearDown() throws java.lang.Exception
interceptLogging(String)
. Also,
invokes PropertyUtils.clearCache()
.
tearDown
in class junit.framework.TestCase
java.lang.Exception
protected void assertExceptionSubstring(java.lang.Throwable ex, java.lang.String substring)
protected void assertExceptionRegexp(java.lang.Throwable ex, java.lang.String pattern) throws java.lang.Exception
java.lang.Exception
protected void assertRegexp(java.lang.String pattern, java.lang.String actual) throws java.lang.Exception
java.lang.Exception
protected java.lang.Throwable findNestedException(ApplicationRuntimeException ex)
protected void assertLoggedMessages(java.lang.String[] messages)
protected void assertLoggedMessage(java.lang.String message)
protected void assertLoggedMessage(java.lang.String message, java.util.List events)
message
- to search for; success is finding a logged message contain the parameter as a
substringevents
- from getInterceptedLogEvents()
protected void assertLoggedMessagePattern(java.lang.String pattern) throws java.lang.Exception
java.lang.Exception
protected void assertLoggedMessagePattern(java.lang.String pattern, java.util.List events) throws java.lang.Exception
java.lang.Exception
protected Registry buildFrameworkRegistry(ModuleDefinition customModule)
protected Registry buildFrameworkRegistry(ModuleDefinition[] customModules)
customModules
, plus the master module descriptor
(i.e., those visible on the classpath).
protected Registry buildMinimalRegistry(Resource l) throws java.lang.Exception
hivemind
module.
java.lang.Exception
protected org.easymock.MockControl newControl(java.lang.Class mockClass)
MockControl.createStrictControl(java.lang.Class)
. The created control is remembered,
and will be invoked by replayControls()
, verifyControls()
, etc.
The class to mock may be either an interface or a class. The EasyMock class extension (easymockclassextension-1.1.jar) and CGLIB (cglib-full-2.01.jar) must be present in the latter case (new since 1.1).
This method is not deprecated, but is rarely used; typically newMock(Class)
is used
to create the control and the mock, and setReturnValue(Object, Object)
and
setThrowable(Object, Throwable)
are used to while training it.
getControl(Object)
is used for the rare cases where the MockControl itself is
needed.
protected org.easymock.MockControl getControl(java.lang.Object mock)
mock
- object whose control is needed
java.lang.IllegalArgumentException
- if not foundprotected void setThrowable(java.lang.Object mock, java.lang.Throwable t)
mock
- the mock object being trainedt
- the exception the object should throw when it replaysprotected void setReturnValue(java.lang.Object mock, java.lang.Object returnValue)
mock
- the mock object being trainedreturnValue
- the value to return from the most recently invoked methodsprotected void setReturnValue(java.lang.Object mock, long returnValue)
mock
- the mock object being trainedreturnValue
- the value to return from the most recently invoked methodsprotected void setReturnValue(java.lang.Object mock, float returnValue)
mock
- the mock object being trainedreturnValue
- the value to return from the most recently invoked methodsprotected void setReturnValue(java.lang.Object mock, double returnValue)
mock
- the mock object being trainedreturnValue
- the value to return from the most recently invoked methodsprotected void setReturnValue(java.lang.Object mock, boolean returnValue)
mock
- the mock object being trainedreturnValue
- the value to return from the most recently invoked methodsprotected void addControl(org.easymock.MockControl control)
replayControls()
and
verifyControls()
.
protected java.lang.Object newMock(java.lang.Class mockClass)
newControl(Class)
and then invoking
MockControl.getMock()
on the result.
protected void replayControls()
MockControl.replay()
on all controls created by newControl(Class)
.
protected void verifyControls()
MockControl.verify()
and MockControl.reset()
on all
controls created by newControl(Class)
.
protected void resetControls()
MockControl.reset()
on all controls.
protected Location fabricateLocation(int line)
newLocation()
instead.
protected Location newLocation()
Location
instance. The resource is the test class, and the line number
increments by one from one for each invocation (thus each call will get a unique instance not
equal to any previously obtained instance).
protected ClassResolver getClassResolver()
DefaultClassResolver
. Repeated calls in the same test return the same
value.
protected boolean matches(java.lang.String input, java.lang.String pattern) throws java.lang.Exception
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |