|
65 | 65 | import org.apache.commons.io.output.AppendableWriter; |
66 | 66 | import org.apache.commons.io.output.CountingOutputStream; |
67 | 67 | import org.apache.commons.io.output.NullOutputStream; |
| 68 | +import org.apache.commons.io.output.NullWriter; |
68 | 69 | import org.apache.commons.io.output.StringBuilderWriter; |
69 | 70 | import org.apache.commons.io.test.TestUtils; |
70 | 71 | import org.apache.commons.io.test.ThrowOnCloseReader; |
@@ -251,49 +252,17 @@ public int read(final char[] cbuf, final int off, final int len) throws IOExcept |
251 | 252 |
|
252 | 253 | @Test |
253 | 254 | public void testAsBufferedWriter() { |
254 | | - final Writer is = new Writer() { |
255 | | - @Override |
256 | | - public void close() throws IOException { |
257 | | - } |
258 | | - |
259 | | - @Override |
260 | | - public void flush() throws IOException { |
261 | | - } |
262 | | - |
263 | | - @Override |
264 | | - public void write(final char[] cbuf, final int off, final int len) throws IOException { |
265 | | - } |
266 | | - |
267 | | - @Override |
268 | | - public void write(final int b) throws IOException { |
269 | | - } |
270 | | - }; |
271 | | - final BufferedWriter bis = IOUtils.buffer(is); |
272 | | - assertNotSame(is, bis); |
| 255 | + final Writer nullWriter = NullWriter.INSTANCE; |
| 256 | + final BufferedWriter bis = IOUtils.buffer(nullWriter); |
| 257 | + assertNotSame(nullWriter, bis); |
273 | 258 | assertSame(bis, IOUtils.buffer(bis)); |
274 | 259 | } |
275 | 260 |
|
276 | 261 | @Test |
277 | 262 | public void testAsBufferedWriterWithBufferSize() { |
278 | | - final Writer w = new Writer() { |
279 | | - @Override |
280 | | - public void close() throws IOException { |
281 | | - } |
282 | | - |
283 | | - @Override |
284 | | - public void flush() throws IOException { |
285 | | - } |
286 | | - |
287 | | - @Override |
288 | | - public void write(final char[] cbuf, final int off, final int len) throws IOException { |
289 | | - } |
290 | | - |
291 | | - @Override |
292 | | - public void write(final int b) throws IOException { |
293 | | - } |
294 | | - }; |
295 | | - final BufferedWriter bw = IOUtils.buffer(w, 2024); |
296 | | - assertNotSame(w, bw); |
| 263 | + final Writer nullWriter = NullWriter.INSTANCE; |
| 264 | + final BufferedWriter bw = IOUtils.buffer(nullWriter, 2024); |
| 265 | + assertNotSame(nullWriter, bw); |
297 | 266 | assertSame(bw, IOUtils.buffer(bw)); |
298 | 267 | assertSame(bw, IOUtils.buffer(bw, 1024)); |
299 | 268 | } |
|
0 commit comments