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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -9,17 +8,22 @@ import org.junit.Test;
|
|||
import com.google.common.io.CountingOutputStream;
|
||||
|
||||
public class GuavaCountingOutputStreamTest {
|
||||
public static final int MAX = 5;
|
||||
|
||||
@Test
|
||||
public void givenData_whenWrittenToStream_thenGetCorrectCount() throws Exception {
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void givenData_whenCountReachesLimit_thenThrowException() throws Exception {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
CountingOutputStream cos = new CountingOutputStream(out);
|
||||
|
||||
byte[] data = new byte[10];
|
||||
byte[] data = new byte[1024];
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(data);
|
||||
|
||||
while (in.read() != -1) {
|
||||
cos.write(data);
|
||||
|
||||
assertEquals(10, cos.getCount());
|
||||
|
||||
cos.flush();
|
||||
if (cos.getCount() >= MAX) {
|
||||
throw new RuntimeException("Write limit reached");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue