|
15 | 15 |
|
16 | 16 | package software.amazon.awssdk.utils;
|
17 | 17 |
|
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
18 | 19 | import static org.junit.Assert.assertEquals;
|
19 | 20 | import static org.junit.Assert.assertFalse;
|
20 | 21 | import static org.junit.Assert.assertNull;
|
@@ -159,4 +160,45 @@ public void testCopyBytesFrom_DirectByteBuffer_Idempotent() {
|
159 | 160 | assertTrue(partial1.length == 3);
|
160 | 161 | assertTrue(Arrays.equals(new byte[] {2, 3, 4}, partial1));
|
161 | 162 | }
|
| 163 | + |
| 164 | + @Test |
| 165 | + public void testCopyRemainingBytesFrom_nullBuffer() { |
| 166 | + assertThat(BinaryUtils.copyRemainingBytesFrom(null)).isNull(); |
| 167 | + } |
| 168 | + |
| 169 | + @Test |
| 170 | + public void testCopyRemainingBytesFrom_noRemainingBytes() { |
| 171 | + ByteBuffer bb = ByteBuffer.allocate(1); |
| 172 | + bb.put(new byte[]{1}); |
| 173 | + bb.flip(); |
| 174 | + |
| 175 | + bb.get(); |
| 176 | + |
| 177 | + assertThat(BinaryUtils.copyRemainingBytesFrom(bb)).hasSize(0); |
| 178 | + } |
| 179 | + |
| 180 | + @Test |
| 181 | + public void testCopyRemainingBytesFrom_fullBuffer() { |
| 182 | + ByteBuffer bb = ByteBuffer.allocate(4); |
| 183 | + bb.put(new byte[]{1, 2, 3, 4}); |
| 184 | + bb.flip(); |
| 185 | + |
| 186 | + byte[] copy = BinaryUtils.copyRemainingBytesFrom(bb); |
| 187 | + assertThat(bb).isEqualTo(ByteBuffer.wrap(copy)); |
| 188 | + assertThat(copy).hasSize(4); |
| 189 | + } |
| 190 | + |
| 191 | + @Test |
| 192 | + public void testCopyRemainingBytesFrom_partiallyReadBuffer() { |
| 193 | + ByteBuffer bb = ByteBuffer.allocate(4); |
| 194 | + bb.put(new byte[]{1, 2, 3, 4}); |
| 195 | + bb.flip(); |
| 196 | + |
| 197 | + bb.get(); |
| 198 | + bb.get(); |
| 199 | + |
| 200 | + byte[] copy = BinaryUtils.copyRemainingBytesFrom(bb); |
| 201 | + assertThat(bb).isEqualTo(ByteBuffer.wrap(copy)); |
| 202 | + assertThat(copy).hasSize(2); |
| 203 | + } |
162 | 204 | }
|
0 commit comments