This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new bb361e487 Add test for CircularByteBuffer clear() (#620)
bb361e487 is described below
commit bb361e48754f28af34c601fdf82585ece2185e2f
Author: sullis
AuthorDate: Wed May 8 05:21:29 2024 -0700
Add test for CircularByteBuffer clear() (#620)
---
.../io/input/buffer/CircularByteBufferTest.java | 21 +
1 file changed, 21 insertions(+)
diff --git
a/src/test/java/org/apache/commons/io/input/buffer/CircularByteBufferTest.java
b/src/test/java/org/apache/commons/io/input/buffer/CircularByteBufferTest.java
index 9d5a230f4..2c3bfe234 100644
---
a/src/test/java/org/apache/commons/io/input/buffer/CircularByteBufferTest.java
+++
b/src/test/java/org/apache/commons/io/input/buffer/CircularByteBufferTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.io.input.buffer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
@@ -81,4 +82,24 @@ public class CircularByteBufferTest {
public void testPeekWithValidArguments() {
assertFalse(new CircularByteBuffer().peek(new byte[] { 5, 10, 15, 20,
25 }, 0, 5));
}
+
+@Test
+public void testClear() {
+ final byte[] data = new byte[] { 1, 2, 3 };
+ final CircularByteBuffer buffer = new CircularByteBuffer(10);
+ assertEquals(0, buffer.getCurrentNumberOfBytes());
+ assertFalse(buffer.hasBytes());
+
+ buffer.add(data, 0, data.length);
+ assertEquals(3, buffer.getCurrentNumberOfBytes());
+ assertEquals(7, buffer.getSpace());
+ assertTrue(buffer.hasBytes());
+ assertTrue(buffer.hasSpace());
+
+ buffer.clear();
+ assertEquals(0, buffer.getCurrentNumberOfBytes());
+ assertEquals(10, buffer.getSpace());
+ assertFalse(buffer.hasBytes());
+ assertTrue(buffer.hasSpace());
+}
}