BAEL-1609 Updated test to throw exception
This commit is contained in:
parent
cc48bd7558
commit
2fe8d8810d
@ -0,0 +1,5 @@
|
|||||||
|
package org.baeldung.guava;
|
||||||
|
|
||||||
|
public class CountingByteWritter {
|
||||||
|
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package org.baeldung.guava;
|
package org.baeldung.guava;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import java.io.ByteArrayInputStream;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -9,17 +8,22 @@ import org.junit.Test;
|
|||||||
import com.google.common.io.CountingOutputStream;
|
import com.google.common.io.CountingOutputStream;
|
||||||
|
|
||||||
public class GuavaCountingOutputStreamTest {
|
public class GuavaCountingOutputStreamTest {
|
||||||
|
public static final int MAX = 5;
|
||||||
|
|
||||||
@Test
|
@Test(expected = RuntimeException.class)
|
||||||
public void givenData_whenWrittenToStream_thenGetCorrectCount() throws Exception {
|
public void givenData_whenCountReachesLimit_thenThrowException() throws Exception {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
CountingOutputStream cos = new CountingOutputStream(out);
|
CountingOutputStream cos = new CountingOutputStream(out);
|
||||||
|
|
||||||
byte[] data = new byte[10];
|
byte[] data = new byte[1024];
|
||||||
|
ByteArrayInputStream in = new ByteArrayInputStream(data);
|
||||||
cos.write(data);
|
|
||||||
|
while (in.read() != -1) {
|
||||||
assertEquals(10, cos.getCount());
|
cos.write(data);
|
||||||
|
cos.flush();
|
||||||
|
if (cos.getCount() >= MAX) {
|
||||||
|
throw new RuntimeException("Write limit reached");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user