FileDocCategorySizeDatePackage
ClassTest2.javaAPI DocAndroid 1.5 API3285Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.tests.java.lang

ClassTest2

public class ClassTest2 extends TestCase

Fields Summary
Constructors Summary
Methods Summary
protected voidsetUp()
Sets up the fixture, for example, open a network connection. This method is called before a test is executed.

    
protected voidtearDown()
Tears down the fixture, for example, close a network connection. This method is called after a test is executed.

    
public voidtestGetResourceAsStream1()
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 voidtestGetResourceAsStream2()
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"));