public abstract class ModuleTestBase
extends junit.framework.TestCase
Constructor and Description |
---|
ModuleTestBase()
Magical constructor that attempts to auto-create static key field
descriptions for your module class.
|
Modifier and Type | Method and Description |
---|---|
protected Class<?> |
getModuleClass()
Returns the class of the module to test.
|
protected File |
getResourceDir()
Returns the location of the Java resources directory for your project.
|
protected File |
getSourceCodeDir()
Returns the location of the source code directory for your project.
|
protected Object |
makeModule()
Return an example instance of the module.
|
protected void |
runTest() |
void |
testSerializationIfAppropriate()
Tests that the module can be serialized.
|
protected void |
verifySerialization(Object first,
byte[] firstBytes,
Object second,
byte[] secondBytes)
Verifies that serialization was successful.
|
countTestCases, createResult, getName, run, run, runBare, setName, setUp, tearDown, toString
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, failNotEquals, failNotSame, failSame
public ModuleTestBase()
If getSourceCodeDir()
and getResourceDir()
both return
non-null values, then the constructor will look in the resources
directory for an English resource file for the class. If it finds
one, nothing magical happens.
Otherwise, the source code for the module being tested is loaded, and parsed to extract the JavaDoc descriptions for the static key fields. The results are stored in the appropriate English locale file in the resource directory.
Note the parsing is naive; at minimum, you should load the resulting locale file and remove any HTML markup.
protected File getSourceCodeDir()
If you want to disable automatic key description generation, return null from this method.
protected File getResourceDir()
If you want to disable automatic key description generation, return null from this method.
protected Class<?> getModuleClass()
protected Object makeModule() throws Exception
Exception
- if the module cannot be constructed for any reasonpublic void testSerializationIfAppropriate() throws Exception
makeModule()
is serialized to a byte array, and then
deserialized, and then serialized to a second byte array. The results
are passed to verifySerialization(java.lang.Object, byte[], java.lang.Object, byte[])
, which will simply compare
the two byte arrays for equality. (That won't always work; see
that method for details).
If nothing else, this test is useful for catching NotSerializable exceptions for your module or classes it depends on.
Exception
- if the module cannot be serializedprotected void verifySerialization(Object first, byte[] firstBytes, Object second, byte[] secondBytes) throws Exception
By default, this method simply compares the first and second byte
arrays for equality. That may not work if you use custom serialization
-- for instance, if you're serializing a timestamp. If that's the case
you should override this method to compare the given objects, or to
simply do nothing. (If this method does nothing, then the
#testSerialization
test is still useful for catching
NotSerializable problems).
first
- the first object that was serializedfirstBytes
- the byte array the first object was serialized tosecond
- the second object that was serializedsecondBytes
- the byte array the second object was serialized toException
- if anyt problem occursCopyright © 2003-2014 Internet Archive. All Rights Reserved.