Skip to content

Commit 2fe8d88

Browse files
committed
BAEL-1609 Updated test to throw exception
1 parent cc48bd7 commit 2fe8d88

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.baeldung.guava;
2+
3+
public class CountingByteWritter {
4+
5+
}
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
package org.baeldung.guava;
22

3-
import static org.junit.Assert.assertEquals;
4-
3+
import java.io.ByteArrayInputStream;
54
import java.io.ByteArrayOutputStream;
65

76
import org.junit.Test;
87

98
import com.google.common.io.CountingOutputStream;
109

1110
public class GuavaCountingOutputStreamTest {
11+
public static final int MAX = 5;
1212

13-
@Test
14-
public void givenData_whenWrittenToStream_thenGetCorrectCount() throws Exception {
13+
@Test(expected = RuntimeException.class)
14+
public void givenData_whenCountReachesLimit_thenThrowException() throws Exception {
1515
ByteArrayOutputStream out = new ByteArrayOutputStream();
1616
CountingOutputStream cos = new CountingOutputStream(out);
17-
18-
byte[] data = new byte[10];
19-
20-
cos.write(data);
21-
22-
assertEquals(10, cos.getCount());
23-
17+
18+
byte[] data = new byte[1024];
19+
ByteArrayInputStream in = new ByteArrayInputStream(data);
20+
21+
while (in.read() != -1) {
22+
cos.write(data);
23+
cos.flush();
24+
if (cos.getCount() >= MAX) {
25+
throw new RuntimeException("Write limit reached");
26+
}
27+
}
2428
}
2529
}

0 commit comments

Comments
 (0)