mirror of https://github.com/apache/nifi.git
NIFI-4856 Removed deprecated ByteArrayInputStream references in ByteCountingInputStreamTest.
Added failing unit test for #available() at various states (initial, during read, after read). Implemented #available() delegation. All tests pass. This closes #2461. Signed-off-by: Kevin Doran <kdoran@apache.org>
This commit is contained in:
parent
34b678d30d
commit
336d3cf1f2
|
@ -107,4 +107,9 @@ public class ByteCountingInputStream extends InputStream {
|
|||
public void close() throws IOException {
|
||||
in.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return in.available();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
*/
|
||||
package org.apache.nifi.stream.io;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ByteCountingInputStreamTest extends TestCase {
|
||||
|
||||
final ByteArrayInputStream reader = new ByteArrayInputStream("abcdefghijklmnopqrstuvwxyz".getBytes());
|
||||
|
||||
public void testReset() throws Exception {
|
||||
|
||||
final ByteArrayInputStream reader = new ByteArrayInputStream("abcdefghijklmnopqrstuvwxyz".getBytes());
|
||||
final ByteArrayInputStream reader = new ByteArrayInputStream("abcdefghijklmnopqrstuvwxyz".getBytes(StandardCharsets.UTF_8));
|
||||
final ByteCountingInputStream bcis = new ByteCountingInputStream(reader);
|
||||
int tmp;
|
||||
|
||||
|
@ -52,4 +52,30 @@ public class ByteCountingInputStreamTest extends TestCase {
|
|||
bcis.reset();
|
||||
assertEquals(bytesAtMark, bcis.getBytesRead());
|
||||
}
|
||||
|
||||
public void testAvailableShouldReturnCorrectCount() throws Exception {
|
||||
// Arrange
|
||||
final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";
|
||||
final ByteArrayInputStream inputStream = new ByteArrayInputStream(ALPHABET.getBytes(StandardCharsets.UTF_8));
|
||||
final ByteCountingInputStream bcis = new ByteCountingInputStream(inputStream);
|
||||
int tmp;
|
||||
int initialAvailableBytes = bcis.available();
|
||||
assertEquals(ALPHABET.length(), initialAvailableBytes);
|
||||
|
||||
// Act
|
||||
/* verify first 2 bytes */
|
||||
tmp = bcis.read();
|
||||
assertEquals(tmp, 97);
|
||||
tmp = bcis.read();
|
||||
assertEquals(tmp, 98);
|
||||
|
||||
int availableBytes = bcis.available();
|
||||
assertEquals(ALPHABET.length() - 2, availableBytes);
|
||||
|
||||
bcis.skip(24);
|
||||
|
||||
// Assert
|
||||
int finalAvailableBytes = bcis.available();
|
||||
assertEquals(0, finalAvailableBytes);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue