2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.harmony.luni.tests.java.lang;
20 import dalvik.annotation.TestTargets;
21 import dalvik.annotation.TestLevel;
22 import dalvik.annotation.TestTargetNew;
23 import dalvik.annotation.TestTargetClass;
25 import java.io.IOException;
26 import java.io.InputStream;
28 @TestTargetClass(Class.class)
29 public class ClassTest2 extends junit.framework.TestCase {
32 * Sets up the fixture, for example, open a network connection. This method
33 * is called before a test is executed.
35 protected void setUp() {
39 * Tears down the fixture, for example, close a network connection. This
40 * method is called after a test is executed.
42 protected void tearDown() {
46 * Tests loading a resource with a relative name.
49 level = TestLevel.PARTIAL_COMPLETE,
51 method = "getResourceAsStream",
52 args = {java.lang.String.class}
54 public void testGetResourceAsStream1() throws IOException {
55 Class clazz = getClass();
57 InputStream stream = clazz.getResourceAsStream("HelloWorld.txt");
58 assert(stream != null);
60 byte[] buffer = new byte[20];
61 int length = stream.read(buffer);
62 String s = new String(buffer, 0, length);
63 assert("Hello, World.".equals(s));
69 * Tests loading a resource with a global name.
72 level = TestLevel.PARTIAL_COMPLETE,
74 method = "getResourceAsStream",
75 args = {java.lang.String.class}
77 public void testGetResourceAsStream2() throws IOException {
78 Class clazz = getClass();
80 InputStream stream = clazz.getResourceAsStream("/org/apache/harmony/luni/tests/java/lang/HelloWorld.txt");
81 assert(stream != null);
83 byte[] buffer = new byte[20];
84 int length = stream.read(buffer);
85 String s = new String(buffer, 0, length);
86 assert("Hello, World.".equals(s));
91 clazz.getResourceAsStream(null);
92 fail("NullPointerException is not thrown.");
93 } catch(NullPointerException npe) {
96 assertNull(clazz.getResourceAsStream("/NonExistentResource"));
97 assertNull(clazz.getResourceAsStream("org/apache/harmony/luni/tests/java/lang/HelloWorld.txt"));