Skip to content

Commit

Permalink
Add MarkShieldInputStream tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jul 8, 2024
1 parent 3f01818 commit c553b0b
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Tests {@link MarkTestableInputStream}.
* Tests {@link MarkShieldInputStream}.
*/
public class MarkShieldInputStreamTest {

Expand All @@ -50,6 +53,41 @@ public void mark(final int readLimit) {
}
}

@SuppressWarnings("resource")
@ParameterizedTest
@MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
public void testAvailableAfterClose(final int len) throws Exception {
final InputStream shadow;
try (MarkTestableInputStream in = new MarkTestableInputStream(new NullInputStream(len, false, false));
final MarkShieldInputStream msis = new MarkShieldInputStream(in)) {
assertEquals(len, in.available());
shadow = in;
}
assertEquals(0, shadow.available());
}

@SuppressWarnings("resource")
@ParameterizedTest
@MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
public void testReadAfterClose(final int len) throws Exception {
final InputStream shadow;
try (MarkTestableInputStream in = new MarkTestableInputStream(new NullInputStream(len, false, false));
final MarkShieldInputStream msis = new MarkShieldInputStream(in)) {
assertEquals(len, in.available());
shadow = in;
}
assertEquals(IOUtils.EOF, shadow.read());
}

@ParameterizedTest
@MethodSource(AbstractInputStreamTest.ARRAY_LENGTHS_NAME)
public void testAvailableAfterOpen(final int len) throws Exception {
try (MarkTestableInputStream in = new MarkTestableInputStream(new NullInputStream(len, false, false));
final MarkShieldInputStream msis = new MarkShieldInputStream(in)) {
assertEquals(len, in.available());
}
}

@Test
public void testMarkIsNoOpWhenUnderlyingDoesNotSupport() throws IOException {
try (MarkTestableInputStream in = new MarkTestableInputStream(new NullInputStream(64, false, false));
Expand Down

0 comments on commit c553b0b

Please sign in to comment.