/*
 * 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.output;

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

import java.io.IOException;
import java.io.Writer;

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

/**
 * JUnit Test Case for {@link BrokenWriter}.
 */
public class BrokenWriterTest {

    private IOException exception;

    private Writer writer;

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

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

        try {
            writer.write(new char[1]);
            fail("Expected exception not thrown.");
        } catch (final IOException e) {
            assertEquals(exception, e);
        }

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

    @Test
    public void testFlush() {
        try {
            writer.flush();
            fail("Expected exception not thrown.");
        } catch (final IOException e) {
            assertEquals(exception, e);
        }
    }

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

}

@@ -943,20 +943,28 @@
 ertions.
-fail
+assertThrows
 ;%0A%0Aimpor
@@ -1228,17 +1228,23 @@
  Writer 
-w
+brokenW
 riter;%0A%0A
@@ -1344,25 +1344,31 @@
 %22);%0A        
-w
+brokenW
 riter = new 
@@ -1434,16 +1434,19 @@
 estWrite
+Int
 () %7B%0A   
@@ -1454,213 +1454,77 @@
     
-try %7B%0A            writer.write(1);%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            w
+assertEquals(exception, assertThrows(IOException.class, () -%3E brokenW
 rite
@@ -1535,192 +1535,147 @@
 ite(
-new char%5B1%5D
+1))
 );%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            w
+@Test%0A    public void testWriteCharArray() %7B%0A        assertEquals(exception, assertThrows(IOException.class, () -%3E brokenW
 rite
@@ -1697,620 +1697,468 @@
 r%5B1%5D
-, 0, 1
+))
 );%0A    
+%7D%0A%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 testFlush() %7B%0A        try %7B%0A            writer.flush();%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 testClose() %7B%0A        try %7B%0A            writer.close();%0A            fail(%22Expected exception not thrown.%22);%0A        %7D catch (final IOException e) %7B%0A            assertEquals(exception, e);%0A        %7D
+@Test%0A    public void testWriteCharArrayIndexed() %7B%0A        assertEquals(exception, assertThrows(IOException.class, () -%3E brokenWriter.write(new char%5B1%5D, 0, 1)));%0A    %7D%0A%0A    @Test%0A    public void testFlush() %7B%0A        assertEquals(exception, assertThrows(IOException.class, () -%3E brokenWriter.flush()));%0A    %7D%0A%0A    @Test%0A    public void testClose() %7B%0A        assertEquals(exception, assertThrows(IOException.class, () -%3E brokenWriter.close()));
 %0A   

Rewrite test using JUnit 5 APIs.