|
| 1 | +/* |
| 2 | + * Copyright The Hypertrace Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.hypertrace.agent.core; |
| 18 | + |
| 19 | +import java.io.IOException; |
| 20 | +import org.junit.jupiter.api.Assertions; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | + |
| 23 | +public class BoundedByteArrayOutputStreamTest { |
| 24 | + |
| 25 | + private static final String ONE_TO_TEN = "0123456789"; |
| 26 | + |
| 27 | + @Test |
| 28 | + public void writeArrTheSameSizeAsBuffer() throws IOException { |
| 29 | + BoundedByteArrayOutputStream boundedBuffer = new BoundedByteArrayOutputStream(10); |
| 30 | + |
| 31 | + boundedBuffer.write(ONE_TO_TEN.getBytes()); |
| 32 | + Assertions.assertEquals(10, boundedBuffer.size()); |
| 33 | + boundedBuffer.write("01234".getBytes()); |
| 34 | + Assertions.assertEquals(10, boundedBuffer.size()); |
| 35 | + Assertions.assertEquals(ONE_TO_TEN, boundedBuffer.toString()); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void writeArrSmallerSizeAsBuffer() throws IOException { |
| 40 | + BoundedByteArrayOutputStream boundedBuffer = new BoundedByteArrayOutputStream(15); |
| 41 | + |
| 42 | + boundedBuffer.write(ONE_TO_TEN.getBytes()); |
| 43 | + Assertions.assertEquals(10, boundedBuffer.size()); |
| 44 | + boundedBuffer.write("0123456".getBytes()); |
| 45 | + Assertions.assertEquals(15, boundedBuffer.size()); |
| 46 | + Assertions.assertEquals(ONE_TO_TEN + "01234", boundedBuffer.toString()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void writeByteSmallerSizeAsBuffer() throws IOException { |
| 51 | + BoundedByteArrayOutputStream boundedBuffer = new BoundedByteArrayOutputStream(5); |
| 52 | + |
| 53 | + boundedBuffer.write('0'); |
| 54 | + boundedBuffer.write('1'); |
| 55 | + boundedBuffer.write('2'); |
| 56 | + boundedBuffer.write('3'); |
| 57 | + boundedBuffer.write('4'); |
| 58 | + Assertions.assertEquals(5, boundedBuffer.size()); |
| 59 | + boundedBuffer.write('5'); |
| 60 | + Assertions.assertEquals(5, boundedBuffer.size()); |
| 61 | + boundedBuffer.write("01234".getBytes()); |
| 62 | + Assertions.assertEquals(5, boundedBuffer.size()); |
| 63 | + Assertions.assertEquals("01234", boundedBuffer.toString()); |
| 64 | + } |
| 65 | +} |
0 commit comments