Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Aug 5, 2024
1 parent 3e0af0a commit 4048b6d
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,48 @@

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.concurrent.ThreadLocalRandom;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class AsyncPositionOutputStreamTest {

@Test
public void testHugeWriteByteArray() throws IOException {
ByteArrayPositionOutputStream result = new ByteArrayPositionOutputStream();
AsyncPositionOutputStream out = new AsyncPositionOutputStream(result);
int len = 10 * 1024;
ByteArrayOutputStream expected = new ByteArrayOutputStream(len);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < len; i++) {
byte[] bytes = new byte[rnd.nextInt(20)];
rnd.nextBytes(bytes);
expected.write(bytes);
out.write(bytes);
}
out.close();

assertThat(result.out.toByteArray()).isEqualTo(expected.toByteArray());
}

@Test
public void testHugeWriteByte() throws IOException {
ByteArrayPositionOutputStream result = new ByteArrayPositionOutputStream();
AsyncPositionOutputStream out = new AsyncPositionOutputStream(result);
int len = 32 * 1024 + 20;
ByteArrayOutputStream expected = new ByteArrayOutputStream(len);
ThreadLocalRandom rnd = ThreadLocalRandom.current();
for (int i = 0; i < len; i++) {
int b = rnd.nextInt();
expected.write(b);
out.write(b);
}
out.close();

assertThat(result.out.toByteArray()).isEqualTo(expected.toByteArray());
}

@Test
public void testNormal() throws IOException {
ByteArrayPositionOutputStream byteOut = new ByteArrayPositionOutputStream();
Expand Down

0 comments on commit 4048b6d

Please sign in to comment.