Skip to content

Commit

Permalink
CODEC-314: Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
  • Loading branch information
arthurscchan committed Nov 24, 2023
1 parent b60bbf7 commit 46991d0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/test/java/org/apache/commons/codec/net/PercentCodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ public void testEncodeUnsupportedObject() {
assertThrows(EncoderException.class, () -> percentCodec.encode("test"));
}

@Test
public void testInvalidByte() throws Exception {
final byte[] invalid = {(byte)-1, (byte)'A'};
final byte[] data = {(byte)'A', (byte)'B'};
final byte[] expected = {(byte)'%', (byte)'4', (byte)'1', (byte)'B'};

final PercentCodec percentCodec = new PercentCodec(invalid, true);
final byte[] result = percentCodec.encode(data);
assertArrayEquals(result, expected);
}

@Test
public void testPercentEncoderDecoderWithNullOrEmptyInput() throws Exception {
final PercentCodec percentCodec = new PercentCodec(null, true);
Expand Down

0 comments on commit 46991d0

Please sign in to comment.