Skip to content

Commit

Permalink
Add CharSequenceInputStreamTest.testReadAfterClose()
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Jul 7, 2024
1 parent c958b31 commit 6a625e9
Showing 1 changed file with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ private boolean isOddBallLegacyCharsetThatDoesNotSupportFrenchCharacters(final S
"Shift_JIS".equalsIgnoreCase(csName);
}

/**
* IO-781 available() returns 2 but only 1 byte is read afterwards.
*/
@Test
public void testAvailable() throws IOException {
final Charset charset = Charset.forName("Big5");
final CharSequenceInputStream in = new CharSequenceInputStream("\uD800\uDC00", charset);
final int available = in.available();
final byte[] data = new byte[available];
final int bytesRead = in.read(data);
assertEquals(available, bytesRead);
}

@ParameterizedTest(name = "{0}")
@MethodSource(CharsetsTest.AVAIL_CHARSETS)
public void testAvailable(final String csName) throws Exception {
Expand Down Expand Up @@ -128,6 +115,20 @@ public void testAvailableAfterClose() throws Exception {
assertEquals(0, shadow.available());
}

/**
* IO-781 available() returns 2 but only 1 byte is read afterwards.
*/
@Test
public void testAvailableAfterOpen() throws IOException {
final Charset charset = Charset.forName("Big5");
try (CharSequenceInputStream in = new CharSequenceInputStream("\uD800\uDC00", charset)) {
final int available = in.available();
final byte[] data = new byte[available];
final int bytesRead = in.read(data);
assertEquals(available, bytesRead);
}
}

private void testAvailableRead(final String csName) throws Exception {
final String input = "test";
try (InputStream r = new CharSequenceInputStream(input, csName)) {
Expand Down Expand Up @@ -447,6 +448,16 @@ public void testNullCharsetName() throws IOException {
}
}

@Test
public void testReadAfterClose() throws Exception {
final InputStream shadow;
try (InputStream in = CharSequenceInputStream.builder().setCharSequence("Hi").get()) {
assertTrue(in.available() > 0);
shadow = in;
}
assertEquals(IOUtils.EOF, shadow.read());
}

private void testReadZero(final String csName) throws Exception {
try (InputStream r = new CharSequenceInputStream("test", csName)) {
final byte[] bytes = new byte[30];
Expand Down

0 comments on commit 6a625e9

Please sign in to comment.