ClassTest2public class ClassTest2 extends TestCase
Methods Summary |
---|
protected void | setUp()Sets up the fixture, for example, open a network connection. This method
is called before a test is executed.
| protected void | tearDown()Tears down the fixture, for example, close a network connection. This
method is called after a test is executed.
| public void | testGetResourceAsStream1()Tests loading a resource with a relative name.
Class clazz = getClass();
InputStream stream = clazz.getResourceAsStream("HelloWorld.txt");
assert(stream != null);
byte[] buffer = new byte[20];
int length = stream.read(buffer);
String s = new String(buffer, 0, length);
assert("Hello, World.".equals(s));
stream.close();
| public void | testGetResourceAsStream2()Tests loading a resource with a global name.
Class clazz = getClass();
InputStream stream = clazz.getResourceAsStream("/org/apache/harmony/luni/tests/java/lang/HelloWorld.txt");
assert(stream != null);
byte[] buffer = new byte[20];
int length = stream.read(buffer);
String s = new String(buffer, 0, length);
assert("Hello, World.".equals(s));
stream.close();
try {
clazz.getResourceAsStream(null);
fail("NullPointerException is not thrown.");
} catch(NullPointerException npe) {
//expected
}
assertNull(clazz.getResourceAsStream("/NonExistentResource"));
assertNull(clazz.getResourceAsStream("org/apache/harmony/luni/tests/java/lang/HelloWorld.txt"));
|
|