Skip to content

Commit 3f01818

Browse files
committed
Add CountingInputStream tests
1 parent 5d937c9 commit 3f01818

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/test/java/org/apache/commons/io/input/AbstractInputStreamTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public abstract class AbstractInputStreamTest {
4646

4747
protected InputStream[] inputStreams;
4848

49+
static final String ARRAY_LENGTHS_NAME = "org.apache.commons.io.input.AbstractInputStreamTest#getArrayLengths";
50+
51+
static final int[] ARRAY_LENGTHS = { 0, 1, 2, 4, 8, 16, 32, 64, 128 };
52+
4953
@BeforeEach
5054
public void setUp() throws IOException {
5155
// Create a byte array of size 2 MB with random bytes
@@ -177,4 +181,8 @@ public void testSkipFromFileChannel() throws IOException {
177181
}
178182
}
179183
}
184+
185+
static int[] getArrayLengths() {
186+
return ARRAY_LENGTHS;
187+
}
180188
}

src/test/java/org/apache/commons/io/input/CountingInputStreamTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.apache.commons.io.IOUtils;
2727
import org.junit.jupiter.api.Test;
2828
import org.junit.jupiter.params.ParameterizedTest;
29-
import org.junit.jupiter.params.provider.ValueSource;
29+
import org.junit.jupiter.params.provider.MethodSource;
3030

3131
/**
3232
* Tests {@link CountingInputStream}.
@@ -35,10 +35,10 @@ public class CountingInputStreamTest {
3535

3636
@SuppressWarnings("resource")
3737
@ParameterizedTest
38-
@ValueSource(ints = { 0, 1, 2, 4, 8, 16, 32, 64, 128 })
38+
@MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
3939
public void testAvailableAfterClose(final int len) throws Exception {
4040
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[len]);
41-
InputStream shadow;
41+
final InputStream shadow;
4242
try (InputStream in = CloseShieldInputStream.wrap(bais)) {
4343
assertEquals(len, in.available());
4444
shadow = in;
@@ -47,7 +47,7 @@ public void testAvailableAfterClose(final int len) throws Exception {
4747
}
4848

4949
@ParameterizedTest
50-
@ValueSource(ints = { 0, 1, 2, 4, 8, 16, 32, 64, 128 })
50+
@MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
5151
public void testAvailableAfterOpen(final int len) throws Exception {
5252
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[len]);
5353
try (InputStream in = CloseShieldInputStream.wrap(bais)) {
@@ -144,7 +144,7 @@ public void testLargeFiles_IO84() throws Exception {
144144
assertThrows(ArithmeticException.class, () -> cis.getCount());
145145
assertThrows(ArithmeticException.class, () -> cis.resetCount());
146146

147-
mock.close();
147+
mock.init();
148148

149149
// Test long methods
150150
IOUtils.consume(cis);
@@ -154,10 +154,10 @@ public void testLargeFiles_IO84() throws Exception {
154154

155155
@SuppressWarnings("resource")
156156
@ParameterizedTest
157-
@ValueSource(ints = { 0, 1, 2, 4, 8, 16, 32, 64, 128 })
157+
@MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
158158
public void testReadAfterClose(final int len) throws Exception {
159159
final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[len]);
160-
InputStream shadow;
160+
final InputStream shadow;
161161
try (InputStream in = CloseShieldInputStream.wrap(bais)) {
162162
assertEquals(len, in.available());
163163
shadow = in;

0 commit comments

Comments
 (0)