This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 01e1b45 Add BrokenWriter.INSTANCE.
01e1b45 is described below
commit 01e1b45895c175fdf7a14789323a1d3b1c55dc68
Author: Gary Gregory <[email protected]>
AuthorDate: Mon Jul 12 14:38:51 2021 -0400
Add BrokenWriter.INSTANCE.
---
src/changes/changes.xml | 3 ++
.../org/apache/commons/io/output/BrokenWriter.java | 9 +++++
.../io/output/ProxyCollectionWriterTest.java | 42 +++++++++++-----------
.../apache/commons/io/output/TeeWriterTest.java | 42 +++++++++++-----------
4 files changed, 54 insertions(+), 42 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4859f43..3e66e25 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -78,6 +78,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add ClosedReader.INSTANCE and deprecate CLOSED_READER.
</action>
+ <action dev="ggregory" type="add" due-to="Gary Gregory">
+ Add BrokenWriter.INSTANCE.
+ </action>
<!-- UPDATE -->
<action dev="ggregory" type="update" due-to="Dependabot">
Bump Maven Javadoc plugin from 3.2.0 to 3.3.0.
diff --git a/src/main/java/org/apache/commons/io/output/BrokenWriter.java
b/src/main/java/org/apache/commons/io/output/BrokenWriter.java
index 547de29..571a8d9 100644
--- a/src/main/java/org/apache/commons/io/output/BrokenWriter.java
+++ b/src/main/java/org/apache/commons/io/output/BrokenWriter.java
@@ -19,6 +19,8 @@ package org.apache.commons.io.output;
import java.io.IOException;
import java.io.Writer;
+import org.apache.commons.io.input.ClosedReader;
+
/**
* Broken writer. This writer always throws an {@link IOException} from
* all {@link Writer} methods.
@@ -32,6 +34,13 @@ import java.io.Writer;
public class BrokenWriter extends Writer {
/**
+ * The singleton instance.
+ *
+ * @since 2.12.0
+ */
+ public static final BrokenWriter INSTANCE = new BrokenWriter();
+
+ /**
* The exception that is thrown by all methods of this class.
*/
private final IOException exception;
diff --git
a/src/test/java/org/apache/commons/io/output/ProxyCollectionWriterTest.java
b/src/test/java/org/apache/commons/io/output/ProxyCollectionWriterTest.java
index 2fd5374..880dd3e 100644
--- a/src/test/java/org/apache/commons/io/output/ProxyCollectionWriterTest.java
+++ b/src/test/java/org/apache/commons/io/output/ProxyCollectionWriterTest.java
@@ -39,7 +39,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnAppendChar1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -56,7 +56,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnAppendChar2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -73,7 +73,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnAppendCharSequence1() throws IOException
{
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -90,7 +90,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnAppendCharSequence2() throws IOException
{
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -107,7 +107,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnAppendCharSequenceIntInt1() throws
IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -124,7 +124,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnAppendCharSequenceIntInt2() throws
IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -141,7 +141,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnClose1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -157,7 +157,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnClose2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -173,7 +173,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnFlush1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -189,7 +189,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnFlush2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -205,7 +205,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteCharArray1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -222,7 +222,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteCharArray2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -239,7 +239,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteCharArrayIntInt1() throws
IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -256,7 +256,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteCharArrayIntInt2() throws
IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -273,7 +273,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteInt1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -290,7 +290,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteInt2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -307,7 +307,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteString1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -324,7 +324,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteString2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -342,7 +342,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteStringIntInt1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
@@ -359,7 +359,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testArrayIOExceptionOnWriteStringIntInt2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
@@ -377,7 +377,7 @@ public class ProxyCollectionWriterTest {
@Test
public void testCollectionCloseBranchIOException() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
@SuppressWarnings("resource") // not necessary to close this
final ProxyCollectionWriter tw = new
ProxyCollectionWriter(Arrays.asList(goodW, badW, null));
diff --git a/src/test/java/org/apache/commons/io/output/TeeWriterTest.java
b/src/test/java/org/apache/commons/io/output/TeeWriterTest.java
index 7a98877..10a13a1 100644
--- a/src/test/java/org/apache/commons/io/output/TeeWriterTest.java
+++ b/src/test/java/org/apache/commons/io/output/TeeWriterTest.java
@@ -40,7 +40,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnAppendChar1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final ProxyCollectionWriter tw = new ProxyCollectionWriter(badW,
goodW, null);
final char data = 'A';
@@ -56,7 +56,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnAppendChar2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final ProxyCollectionWriter tw = new ProxyCollectionWriter(goodW,
badW, null);
final char data = 'A';
@@ -72,7 +72,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnAppendCharSequence1() throws IOException
{
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(badW, goodW, null);
final String data = "A";
@@ -88,7 +88,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnAppendCharSequence2() throws IOException
{
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(goodW, badW, null);
final String data = "A";
@@ -104,7 +104,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnAppendCharSequenceIntInt1() throws
IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(badW, goodW, null);
final String data = "A";
@@ -120,7 +120,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnAppendCharSequenceIntInt2() throws
IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(goodW, badW, null);
final String data = "A";
@@ -136,7 +136,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnClose1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(badW, goodW, null);
try {
@@ -151,7 +151,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnClose2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(goodW, badW, null);
try {
@@ -166,7 +166,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnFlush1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(badW, goodW, null);
try {
@@ -181,7 +181,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnFlush2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(goodW, badW, null);
try {
@@ -196,7 +196,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteCharArray1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(badW, goodW, null);
final char[] data = { 'a' };
@@ -212,7 +212,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteCharArray2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(goodW, badW, null);
final char[] data = { 'a' };
@@ -228,7 +228,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteCharArrayIntInt1() throws
IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(badW, goodW, null);
final char[] data = { 'a' };
@@ -244,7 +244,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteCharArrayIntInt2() throws
IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(goodW, badW, null);
final char[] data = { 'a' };
@@ -260,7 +260,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteInt1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(badW, goodW, null);
final int data = 32;
@@ -276,7 +276,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteInt2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(goodW, badW, null);
try {
@@ -292,7 +292,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteString1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(badW, goodW, null);
final String data = "A";
@@ -308,7 +308,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteString2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(goodW, badW, null);
final String data = "A";
@@ -325,7 +325,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteStringIntInt1() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(badW, goodW, null);
final String data = "A";
@@ -341,7 +341,7 @@ public class TeeWriterTest {
@Test
public void testArrayIOExceptionOnWriteStringIntInt2() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(goodW, badW, null);
final String data = "A";
@@ -358,7 +358,7 @@ public class TeeWriterTest {
@Test
public void testCollectionCloseBranchIOException() throws IOException {
- final Writer badW = new BrokenWriter();
+ final Writer badW = BrokenWriter.INSTANCE;
final StringWriter goodW = mock(StringWriter.class);
final TeeWriter tw = new TeeWriter(Arrays.asList(goodW, badW, null));
try {