/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.io.input;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.io.InputStream;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
 * JUnit Test Case for {@link BrokenInputStream}.
 */
@SuppressWarnings("ResultOfMethodCallIgnored")
public class BrokenInputStreamTest {

    private IOException exception;

    private InputStream stream;

    @BeforeEach
    public void setUp() {
        exception = new IOException("test exception");
        stream = new BrokenInputStream(exception);
    }

    @Test
    public void testRead() {
        try {
            stream.read();
            fail("Expected exception not thrown.");
        } catch (final IOException e) {
            assertEquals(exception, e);
        }

        try {
            stream.read(new byte[1]);
            fail("Expected exception not thrown.");
        } catch (final IOException e) {
            assertEquals(exception, e);
        }

        try {
            stream.read(new byte[1], 0, 1);
            fail("Expected exception not thrown.");
        } catch (final IOException e) {
            assertEquals(exception, e);
        }
    }

    @Test
    public void testAvailable() {
        try {
            stream.available();
            fail("Expected exception not thrown.");
        } catch (final IOException e) {
            assertEquals(exception, e);
        }
    }

    @Test
    public void testSkip() {
        try {
            stream.skip(1);
            fail("Expected exception not thrown.");
        } catch (final IOException e) {
            assertEquals(exception, e);
        }
    }

    @Test
    public void testReset() {
        try {
            stream.reset();
            fail("Expected exception not thrown.");
        } catch (final IOException e) {
            assertEquals(exception, e);
        }
    }

    @Test
    public void testClose() {
        try {
            stream.close();
            fail("Expected exception not thrown.");
        } catch (final IOException e) {
            assertEquals(exception, e);
        }
    }

}

@@ -942,20 +942,28 @@
 ertions.
-fail
+assertThrows
 ;%0A%0Aimpor
@@ -1153,55 +1153,8 @@
  */%0A
-@SuppressWarnings(%22ResultOfMethodCallIgnored%22)%0A
 publ
@@ -1445,12 +1445,17 @@
 test
-Read
+Available
 () %7B
@@ -1467,578 +1467,226 @@
     
-try %7B%0A            stream.read();%0A            fail(%22Expected exception not thrown.%22);%0A        %7D catch (final IOException e) %7B%0A            assertEquals(exception, e);%0A        %7D%0A%0A        try %7B%0A            stream.read(new byte%5B1%5D
+assertEquals(exception, assertThrows(IOException.class, () -%3E stream.available())
 );%0A    
+%7D%0A%0A
     
-    fail(%22Expected exception not thrown.%22);%0A        %7D catch (final IOException e) %7B%0A            assertEquals(exception, e);%0A        %7D%0A%0A        try %7B%0A            stream.read(new byte%5B1%5D, 0, 1);%0A            fail(%22Expected exception not thrown.%22);%0A        %7D catch (final IOException e) %7B%0A            assertEquals(exception, e);%0A        %7D
+@Test%0A    public void testClose() %7B%0A        assertEquals(exception, assertThrows(IOException.class, () -%3E stream.close()));
 %0A   
@@ -1715,33 +1715,28 @@
 ic void test
-Available
+Read
 () %7B%0A       
@@ -1740,648 +1740,423 @@
     
-try %7B%0A            stream.available();%0A            fail(%22Expected exception not thrown.%22);%0A        %7D catch (final IOException e) %7B%0A            assertEquals(exception, e);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testSkip() %7B%0A        try %7B%0A            stream.skip(1);%0A            fail(%22Expected exception not thrown.%22);%0A        %7D catch (final IOException e) %7B%0A            assertEquals(exception, e);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void testReset() %7B%0A        try %7B%0A            stream.reset();%0A            fail(%22Expected exception not thrown.%22);%0A        %7D catch (final IOException e) %7B%0A            assertEquals(exception, e);%0A        %7D
+assertEquals(exception, assertThrows(IOException.class, () -%3E stream.read()));%0A        assertEquals(exception, assertThrows(IOException.class, () -%3E stream.read(new byte%5B1%5D)));%0A        assertEquals(exception, assertThrows(IOException.class, () -%3E stream.read(new byte%5B1%5D, 0, 1)));%0A    %7D%0A%0A    @Test%0A    public void testReset() %7B%0A        assertEquals(exception, assertThrows(IOException.class, () -%3E stream.reset()));
 %0A   
@@ -2181,37 +2181,36 @@
 public void test
-Close
+Skip
 () %7B%0A        try
@@ -2210,183 +2210,87 @@
     
-try %7B%0A            stream.close();%0A            fail(%22Expected exception not thrown.%22);%0A        %7D catch (final IOException e) %7B%0A            assertEquals(exception, e);%0A        %7D
+assertEquals(exception, assertThrows(IOException.class, () -%3E stream.skip(1)));
 %0A   

Rewrite test using JUnit 5 APIs.