ClassTest2.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
1/*
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
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 */
17
18package org.apache.harmony.luni.tests.java.lang;
19
20import dalvik.annotation.TestInfo;
21import dalvik.annotation.TestLevel;
22import dalvik.annotation.TestTarget;
23import dalvik.annotation.TestTargetClass;
24
25import java.io.IOException;
26import java.io.InputStream;
27
28@TestTargetClass(Class.class)
29public class ClassTest2 extends junit.framework.TestCase {
30
31    /**
32     * Sets up the fixture, for example, open a network connection. This method
33     * is called before a test is executed.
34     */
35    protected void setUp() {
36    }
37
38    /**
39     * Tears down the fixture, for example, close a network connection. This
40     * method is called after a test is executed.
41     */
42    protected void tearDown() {
43    }
44
45    /**
46     *  Tests loading a resource with a relative name.
47     */
48    @TestInfo(
49      level = TestLevel.PARTIAL,
50      purpose = "Checks positive functionality.",
51      targets = {
52        @TestTarget(
53          methodName = "getResourceAsStream",
54          methodArgs = {java.lang.String.class}
55        )
56    })
57    public void testGetResourceAsStream1() throws IOException {
58        Class clazz = getClass();
59
60        InputStream stream = clazz.getResourceAsStream("HelloWorld.txt");
61        assert(stream != null);
62
63        byte[] buffer = new byte[20];
64        int length = stream.read(buffer);
65        String s = new String(buffer, 0, length);
66        assert("Hello, World.".equals(s));
67
68        stream.close();
69    }
70
71    /**
72     *  Tests loading a resource with a global name.
73     */
74    @TestInfo(
75      level = TestLevel.PARTIAL,
76      purpose = "Checks positive functionality.",
77      targets = {
78        @TestTarget(
79          methodName = "getResourceAsStream",
80          methodArgs = {java.lang.String.class}
81        )
82    })
83    public void testGetResourceAsStream2() throws IOException {
84        Class clazz = getClass();
85
86        InputStream stream = clazz.getResourceAsStream("/org/apache/harmony/luni/tests/java/lang/HelloWorld.txt");
87        assert(stream != null);
88
89        byte[] buffer = new byte[20];
90        int length = stream.read(buffer);
91        String s = new String(buffer, 0, length);
92        assert("Hello, World.".equals(s));
93
94        stream.close();
95    }
96}
97