|
28 | 28 | import java.nio.charset.Charset; |
29 | 29 | import java.nio.charset.StandardCharsets; |
30 | 30 | import java.util.Arrays; |
| 31 | +import java.util.stream.IntStream; |
31 | 32 |
|
32 | 33 | import org.apache.commons.codec.CodecPolicy; |
33 | 34 | import org.apache.commons.codec.DecoderException; |
34 | 35 | import org.apache.commons.lang3.ArrayUtils; |
35 | 36 | import org.junit.jupiter.api.Test; |
| 37 | +import org.junit.jupiter.params.ParameterizedTest; |
| 38 | +import org.junit.jupiter.params.provider.MethodSource; |
36 | 39 |
|
37 | 40 | /** |
38 | 41 | * Tests {@link Base32}. |
@@ -211,6 +214,10 @@ private static void assertBase32DecodingOfTrailingBits(final int nbits) { |
211 | 214 | } |
212 | 215 | } |
213 | 216 |
|
| 217 | + static IntStream rangeProvider() { |
| 218 | + return IntStream.range(0, 21); |
| 219 | + } |
| 220 | + |
214 | 221 | @Test |
215 | 222 | void testBase32AtBufferEnd() { |
216 | 223 | testBase32InBuffer(100, 0); |
@@ -509,51 +516,47 @@ void testIsInAlphabet() { |
509 | 516 | assertFalse(b32.isInAlphabet((byte) ('v' + 1))); |
510 | 517 | } |
511 | 518 |
|
512 | | - @Test |
513 | | - void testRandomBytes() { |
514 | | - for (int i = 0; i < 20; i++) { |
515 | | - final Base32 codec = new Base32(); |
516 | | - final byte[][] b = BaseNTestData.randomData(codec, i); |
517 | | - assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength); |
518 | | - // assertEquals(b[0], codec.decode(b[1])); |
519 | | - } |
520 | | - } |
521 | | - |
522 | | - @Test |
523 | | - void testRandomBytesChunked() { |
524 | | - for (int i = 0; i < 20; i++) { |
525 | | - final Base32 codec = new Base32(10); |
526 | | - final byte[][] b = BaseNTestData.randomData(codec, i); |
527 | | - assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength); |
528 | | - // assertEquals(b[0], codec.decode(b[1])); |
529 | | - } |
| 519 | + @ParameterizedTest |
| 520 | + @MethodSource("rangeProvider") |
| 521 | + void testRandomBytes(final int i) { |
| 522 | + final Base32 codec = new Base32(); |
| 523 | + final byte[][] b = BaseNTestData.randomData(codec, i); |
| 524 | + assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength); |
| 525 | + // assertEquals(b[0], codec.decode(b[1])); |
530 | 526 | } |
531 | 527 |
|
532 | | - @Test |
533 | | - void testRandomBytesHex() { |
534 | | - for (int i = 0; i < 20; i++) { |
535 | | - final Base32 codec = new Base32(true); |
536 | | - final byte[][] b = BaseNTestData.randomData(codec, i); |
537 | | - assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength); |
538 | | - // assertEquals(b[0], codec.decode(b[1])); |
539 | | - } |
| 528 | + @ParameterizedTest |
| 529 | + @MethodSource("rangeProvider") |
| 530 | + void testRandomBytesChunked(final int i) { |
| 531 | + final Base32 codec = new Base32(10); |
| 532 | + final byte[][] b = BaseNTestData.randomData(codec, i); |
| 533 | + assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength); |
| 534 | + // assertEquals(b[0], codec.decode(b[1])); |
540 | 535 | } |
541 | 536 |
|
542 | | - @Test |
543 | | - void testSingleCharEncoding() { |
544 | | - for (int i = 0; i < 20; i++) { |
545 | | - Base32 codec = new Base32(); |
546 | | - final BaseNCodec.Context context = new BaseNCodec.Context(); |
547 | | - final byte[] unencoded = new byte[i]; |
548 | | - final byte[] allInOne = codec.encode(unencoded); |
549 | | - codec = new Base32(); |
550 | | - for (int j = 0; j < unencoded.length; j++) { |
551 | | - codec.encode(unencoded, j, 1, context); |
552 | | - } |
553 | | - codec.encode(unencoded, 0, -1, context); |
554 | | - final byte[] singly = new byte[allInOne.length]; |
555 | | - codec.readResults(singly, 0, 100, context); |
556 | | - assertArrayEquals(allInOne, singly); |
| 537 | + @ParameterizedTest |
| 538 | + @MethodSource("rangeProvider") |
| 539 | + void testRandomBytesHex(final int i) { |
| 540 | + final Base32 codec = new Base32(true); |
| 541 | + final byte[][] b = BaseNTestData.randomData(codec, i); |
| 542 | + assertEquals(b[1].length, codec.getEncodedLength(b[0]), i + " " + codec.lineLength); |
| 543 | + // assertEquals(b[0], codec.decode(b[1])); |
| 544 | + } |
| 545 | + |
| 546 | + @ParameterizedTest |
| 547 | + @MethodSource("rangeProvider") |
| 548 | + void testSingleCharEncoding(final int i) { |
| 549 | + Base32 codec = new Base32(); |
| 550 | + final BaseNCodec.Context context = new BaseNCodec.Context(); |
| 551 | + final byte[] unencoded = new byte[i]; |
| 552 | + final byte[] allInOne = codec.encode(unencoded); |
| 553 | + codec = new Base32(); |
| 554 | + for (int j = 0; j < unencoded.length; j++) { |
| 555 | + codec.encode(unencoded, j, 1, context); |
557 | 556 | } |
| 557 | + codec.encode(unencoded, 0, -1, context); |
| 558 | + final byte[] singly = new byte[allInOne.length]; |
| 559 | + codec.readResults(singly, 0, 100, context); |
| 560 | + assertArrayEquals(allInOne, singly); |
558 | 561 | } |
559 | 562 | } |
0 commit comments