|
JUnit-addons version 1.4 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--junitx.util.ResourceManager
Utility class that manages resources and allows separate tests to share them.
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(MyClassTest.class);
return new TestSetup(suite) {
public void setUp()
throws Exception {
ResourceManager.addResource("RESOURCE_ID", new Object());
}
};
}
}
The test class simply gets the resource from the ResourceManager during the
set up process:
public class MyClassTest extends TestCase {
private Object res;
public void setUp() {
res = ResourceManager.getResource("RESOURCE_ID");
}
public void testXYZ() {
res.XYZ();
}
}
To share a resource whithin the same TestCase:
public class MyClassTest extends TestCase {
private Object res;
public void setUp() {
if (!ResourceManager.contains("RESOURCE_ID")) {
ResourceManager.addResource("RESOURCE_ID", new Object());
}
res = ResourceManager.getResource("RESOURCE_ID");
}
public void testXYZ() {
res.XYZ();
}
}
| Method Summary | |
static void |
addResource(java.lang.String key,
java.lang.Object value)
Associates the resource to the key in the manager. |
static boolean |
containsResource(java.lang.String key)
Returns true if the ResourceManager contains a resource with the specified key. |
static java.lang.Object |
getResource(java.lang.String key)
Returns the resource to which the specified key is mapped in this ResourceManager or null if the resource was not found. |
static void |
removeResource(java.lang.String key)
Removes the key (and its corresponding resource) from this ResourceManager. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public static void addResource(java.lang.String key,
java.lang.Object value)
throws java.lang.IllegalArgumentException
key - the resource key.value - the resource.
java.lang.IllegalArgumentException - if the key is already used.
public static java.lang.Object getResource(java.lang.String key)
throws java.lang.NullPointerException
key - a key in the ResourceManager.
java.lang.NullPointerException - if the key is null.public static boolean containsResource(java.lang.String key)
public static void removeResource(java.lang.String key)
key - the key that needs to be removed.
|
JUnit-addons version 1.4 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||