1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.codec.net;
19
20 import static org.junit.jupiter.api.Assertions.assertNull;
21 import static org.junit.jupiter.api.Assertions.assertThrows;
22
23 import java.nio.charset.StandardCharsets;
24
25 import org.apache.commons.codec.CharEncoding;
26 import org.apache.commons.codec.DecoderException;
27 import org.junit.jupiter.api.Test;
28 import org.junit.jupiter.params.ParameterizedTest;
29 import org.junit.jupiter.params.provider.ValueSource;
30
31
32
33
34 class RFC1522CodecTest {
35
36 static class RFC1522TestCodec extends RFC1522Codec {
37
38 RFC1522TestCodec() {
39 super(StandardCharsets.UTF_8);
40 }
41
42 @Override
43 protected byte[] doDecoding(final byte[] bytes) {
44 return bytes;
45 }
46
47 @Override
48 protected byte[] doEncoding(final byte[] bytes) {
49 return bytes;
50 }
51
52 @Override
53 protected String getEncoding() {
54 return "T";
55 }
56 }
57
58 static void assertExpectedDecoderException(final String text) {
59 assertThrows(DecoderException.class, () -> new RFC1522TestCodec().decodeText(text));
60 }
61
62 @ParameterizedTest
63
64 @ValueSource(strings = {
65 "whatever",
66 "=?",
67 "?=",
68 "==",
69 "=?=",
70 "=??=",
71 "=?stuff?=",
72 "=?UTF-8??=",
73 "=?UTF-8?stuff?=",
74 "=?UTF-8?T?stuff",
75 "=??T?stuff?=",
76 "=?UTF-8??stuff?=",
77 "=?UTF-8?W?stuff?=",
78 "=?UTF-8?T?stuff?more?=",
79 "=?UTF-8?T?stuff??=",
80 "=?UTF-8?T???="
81 })
82
83 void testDecodeInvalid(final String text) throws Exception {
84 assertExpectedDecoderException(text);
85 }
86
87 @Test
88 void testNullInput() throws Exception {
89 final RFC1522TestCodec testCodec = new RFC1522TestCodec();
90 assertNull(testCodec.decodeText(null));
91 assertNull(testCodec.encodeText(null, CharEncoding.UTF_8));
92 }
93 }