1cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath/* 2cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Licensed to the Apache Software Foundation (ASF) under one or more 3cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * contributor license agreements. See the NOTICE file distributed with 4cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * this work for additional information regarding copyright ownership. 5cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * The ASF licenses this file to You under the Apache License, Version 2.0 6cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * (the "License"); you may not use this file except in compliance with 7cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * the License. You may obtain a copy of the License at 8cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 9cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * http://www.apache.org/licenses/LICENSE-2.0 10cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 11cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Unless required by applicable law or agreed to in writing, software 12cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * distributed under the License is distributed on an "AS IS" BASIS, 13cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * See the License for the specific language governing permissions and 15cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * limitations under the License. 16cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 17cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 18ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathpackage org.apache.harmony.tests.java.io; 19cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 20cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.IOException; 21cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 22cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport junit.framework.TestCase; 23cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 24cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathpublic class IOExceptionTest extends TestCase { 25cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 26cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 27cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.IOException#IOException() 28cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 29cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_Constructor() { 30cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 31cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (true) { 32cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath throw new IOException(); 33cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 34cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Exception during IOException test"); 35cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IOException e) { 36cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 37cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 38cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 39cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 40cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 41cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.IOException#IOException(java.lang.String) 42cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 43cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ConstructorLjava_lang_String() { 44cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 45cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (true) { 46cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath throw new IOException("Some error message"); 47cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 48cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Failed to generate exception"); 49cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IOException e) { 50cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 51cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 52cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 53cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 54cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 55cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.IOException#IOException(java.lang.String, 56cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath *java.lang.Throwable) 57cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 58cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 59cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ConstructorLString_LThrowable() { 60cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for constructor java.io.IOException(java.lang.String, java.lang.Throwable) 61cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 62cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath IOException ioException = new IOException( 63cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "A dummy IOException", new Throwable("A dummy Throwable")); //$NON-NLS-1$//$NON-NLS-2$ 64cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("A dummy IOException", ioException.getMessage()); //$NON-NLS-1$ 65cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 66cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 67cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath throw new IOException( 68cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath "A dummy error", new Throwable("Some error message")); //$NON-NLS-1$ //$NON-NLS-2$ 69cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IOException e) { 70cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath return; 71cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (Exception e) { 72cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Exception during IOException test" + e.toString()); //$NON-NLS-1$ 73cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 74cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Failed to generate exception"); //$NON-NLS-1$ 75cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 76cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 77cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 78cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.IOException#IOException(java.lang.Throwable) 79cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * @since 1.6 80cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 81cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_Constructor_LThrowable() { 82cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Test for constructor java.io.IOException(java.lang.Throwable) 83cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath Throwable cause = new Throwable("A dummy Throwable"); //$NON-NLS-1$ 84cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath IOException ioException = new IOException(cause); 85cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(cause.toString(), ioException.getMessage()); 86cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 87cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath ioException = new IOException((Throwable) null); 88cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertNull(ioException.getMessage()); 89cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 90cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 91cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath throw new IOException(new Throwable("Some error message")); //$NON-NLS-1$ 92cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IOException e) { 93cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath return; 94cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (Exception e) { 95cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Exception during IOException test" + e.toString()); //$NON-NLS-1$ 96cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 97cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Failed to generate exception"); //$NON-NLS-1$ 98cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 99cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 100cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 101cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Sets up the fixture, for example, open a network connection. This method 102cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * is called before a test is executed. 103cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 104cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath protected void setUp() { 105cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 106cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 107cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 108cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Tears down the fixture, for example, close a network connection. This 109cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * method is called after a test is executed. 110cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 111cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath protected void tearDown() { 112cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 113cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath} 114