1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.io.input;
18
19 import java.io.IOException;
20 import java.io.Reader;
21 import java.nio.CharBuffer;
22
23 import org.junit.jupiter.api.Test;
24
25
26
27
28 class ProxyReaderTest {
29
30
31 private static final class CustomNullReader extends NullReader {
32 CustomNullReader(final int len) {
33 super(len);
34 }
35
36 @Override
37 public int read(final char[] chars) throws IOException {
38 return chars == null ? 0 : super.read(chars);
39 }
40
41 @Override
42 public int read(final char[] chars, final int offset, final int length) throws IOException {
43 return chars == null ? 0 : super.read(chars, offset, length);
44 }
45
46 @Override
47 public int read(final CharBuffer target) throws IOException {
48 return target == null ? 0 : super.read(target);
49 }
50 }
51
52
53 private static final class ProxyReaderImpl extends ProxyReader {
54 ProxyReaderImpl(final Reader proxy) {
55 super(proxy);
56 }
57 }
58
59 @Test
60 void testNullCharArray() throws Exception {
61 try (ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0))) {
62 proxy.read((char[]) null);
63 proxy.read(null, 0, 0);
64 }
65 }
66
67 @Test
68 void testNullCharBuffer() throws Exception {
69 try (ProxyReader proxy = new ProxyReaderImpl(new CustomNullReader(0))) {
70 proxy.read((CharBuffer) null);
71 }
72 }
73 }