-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle NPE * Add Unit Test
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/io/lettuce/core/codec/ByteArrayCodecUnitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.lettuce.core.codec; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ByteArrayCodecUnitTests { | ||
|
||
@Test | ||
void testDecodeValue_withNonEmptyByteBuffer() { | ||
final ByteArrayCodec byteArrayCodec = ByteArrayCodec.INSTANCE; | ||
final byte[] expectedBytes = { 1, 2, 3, 4, 5 }; | ||
final ByteBuffer buffer = ByteBuffer.wrap(expectedBytes); | ||
final byte[] result = byteArrayCodec.decodeValue(buffer); | ||
assertThat(result).isEqualTo(expectedBytes); | ||
} | ||
|
||
@Test | ||
void testDecodeValue_withEmptyByteBuffer() { | ||
final ByteArrayCodec byteArrayCodec = ByteArrayCodec.INSTANCE; | ||
final ByteBuffer buffer = ByteBuffer.allocate(0); | ||
final byte[] result = byteArrayCodec.decodeValue(buffer); | ||
assertThat(result).isEmpty(); | ||
} | ||
|
||
@Test | ||
void testDecodeValue_withNullByteBuffer() { | ||
final ByteArrayCodec byteArrayCodec = ByteArrayCodec.INSTANCE; | ||
final byte[] result = byteArrayCodec.decodeValue(null); | ||
assertThat(result).isEmpty(); | ||
} | ||
|
||
} |