public class ResourceManager
extends java.lang.Object
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();
}
}
| Modifier and Type | Method and Description |
|---|---|
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.
|
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.Copyright © ${project.year} ${project.holder}. All Rights Reserved.