InputStreamReaderTest.java revision cc05ad238516f1303687aba4a978e24e57c0c07a
1/* Licensed to the Apache Software Foundation (ASF) under one or more 2 * contributor license agreements. See the NOTICE file distributed with 3 * this work for additional information regarding copyright ownership. 4 * The ASF licenses this file to You under the Apache License, Version 2.0 5 * (the "License"); you may not use this file except in compliance with 6 * the License. You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package org.apache.harmony.luni.tests.java.io; 18 19import dalvik.annotation.TestTargets; 20import dalvik.annotation.TestLevel; 21import dalvik.annotation.TestTargetNew; 22import dalvik.annotation.TestTargetClass; 23 24import java.io.ByteArrayInputStream; 25import java.io.IOException; 26import java.io.InputStreamReader; 27import java.io.UnsupportedEncodingException; 28 29import junit.framework.TestCase; 30@TestTargetClass(InputStreamReader.class) 31public class InputStreamReaderTest extends TestCase { 32 33 @TestTargets({ 34 @TestTargetNew( 35 level = TestLevel.COMPLETE, 36 notes = "", 37 method = "InputStreamReader", 38 args = {java.io.InputStream.class, java.lang.String.class} 39 ), 40 @TestTargetNew( 41 level = TestLevel.COMPLETE, 42 notes = "", 43 method = "getEncoding", 44 args = {} 45 ) 46 }) 47 public void testGetEncoding_StreamClosed() throws IOException { 48 InputStreamReader in = null; 49 byte b[] = new byte[5]; 50 in = new InputStreamReader(new ByteArrayInputStream(b), "UTF-16BE"); 51 in.close(); 52 String result = in.getEncoding(); 53 assertNull(result); 54 } 55 56 @TestTargets({ 57 @TestTargetNew( 58 level = TestLevel.COMPLETE, 59 notes = "", 60 method = "InputStreamReader", 61 args = {java.io.InputStream.class, java.lang.String.class} 62 ), 63 @TestTargetNew( 64 level = TestLevel.COMPLETE, 65 notes = "", 66 method = "getEncoding", 67 args = {} 68 ) 69 }) 70 public void testGetEncoding_NotHistorical() { 71 InputStreamReader in = null; 72 try { 73 in = new InputStreamReader(System.in, "UTF-16BE"); 74 } catch (UnsupportedEncodingException e) { 75 // ok 76 } 77 String result = in.getEncoding(); 78 assertEquals("UnicodeBigUnmarked", result); 79 80 } 81 82} 83