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.tests.java.io;
19
20import java.io.StringBufferInputStream;
21import java.io.UnsupportedEncodingException;
22
23@SuppressWarnings("deprecation")
24public class StringBufferInputStreamTest extends junit.framework.TestCase {
25
26    StringBufferInputStream sbis;
27
28    /**
29     * java.io.StringBufferInputStream#StringBufferInputStream(java.lang.String)
30     */
31    public void test_ConstructorLjava_lang_String() {
32        // Test for method java.io.StringBufferInputStream(java.lang.String)
33    }
34
35    /**
36     * java.io.StringBufferInputStream#available()
37     */
38    public void test_available() {
39        // Test for method int java.io.StringBufferInputStream.available()
40        assertEquals("Returned incorrect number of available bytes", 11, sbis
41                .available());
42    }
43
44    /**
45     * java.io.StringBufferInputStream#read()
46     */
47    public void test_read() throws UnsupportedEncodingException {
48        // Test for method int java.io.StringBufferInputStream.read()
49        byte[] buf = new byte[5];
50        sbis.skip(6);
51        sbis.read(buf, 0, 5);
52        assertEquals("Returned incorrect chars", "World", new String(buf, "UTF-8"));
53    }
54
55    /**
56     * java.io.StringBufferInputStream#read(byte[], int, int)
57     */
58    public void test_read$BII() {
59        // Test for method int java.io.StringBufferInputStream.read(byte [],
60        // int, int)
61        assertEquals("Read returned incorrect char", 'H', sbis.read());
62    }
63
64    /**
65     * java.io.StringBufferInputStream#reset()
66     */
67    public void test_reset() {
68        // Test for method void java.io.StringBufferInputStream.reset()
69        long s = sbis.skip(6);
70        assertEquals("Unable to skip correct umber of chars", 6, s);
71        sbis.reset();
72        assertEquals("Failed to reset", 'H', sbis.read());
73    }
74
75    /**
76     * java.io.StringBufferInputStream#skip(long)
77     */
78    public void test_skipJ() {
79        // Test for method long java.io.StringBufferInputStream.skip(long)
80        long s = sbis.skip(6);
81        assertEquals("Unable to skip correct umber of chars", 6, s);
82        assertEquals("Skip positioned at incorrect char", 'W', sbis.read());
83    }
84
85    /**
86     * Sets up the fixture, for example, open a network connection. This method
87     * is called before a test is executed.
88     */
89    protected void setUp() {
90        sbis = new StringBufferInputStream("Hello World");
91    }
92
93    /**
94     * Tears down the fixture, for example, close a network connection. This
95     * method is called after a test is executed.
96     */
97    protected void tearDown() {
98    }
99}
100