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.Assert.assertNull;
21 import static org.junit.Assert.fail;
22
23 import org.apache.commons.codec.CharEncoding;
24 import org.apache.commons.codec.DecoderException;
25 import org.junit.Test;
26
27
28
29
30
31
32 public class RFC1522CodecTest {
33
34 static class RFC1522TestCodec extends RFC1522Codec {
35
36 @Override
37 protected byte[] doDecoding(final byte[] bytes) {
38 return bytes;
39 }
40
41 @Override
42 protected byte[] doEncoding(final byte[] bytes) {
43 return bytes;
44 }
45
46 @Override
47 protected String getEncoding() {
48 return "T";
49 }
50
51 }
52
53 @Test
54 public void testNullInput() throws Exception {
55 final RFC1522TestCodec testcodec = new RFC1522TestCodec();
56 assertNull(testcodec.decodeText(null));
57 assertNull(testcodec.encodeText(null, CharEncoding.UTF_8));
58 }
59
60 private void assertExpectedDecoderException(final String s) throws Exception {
61 final RFC1522TestCodec testcodec = new RFC1522TestCodec();
62 try {
63 testcodec.decodeText(s);
64 fail("DecoderException should have been thrown");
65 } catch (final DecoderException e) {
66
67 }
68 }
69
70 @Test
71 public void testDecodeInvalid() throws Exception {
72 assertExpectedDecoderException("whatever");
73 assertExpectedDecoderException("=?");
74 assertExpectedDecoderException("?=");
75 assertExpectedDecoderException("==");
76 assertExpectedDecoderException("=??=");
77 assertExpectedDecoderException("=?stuff?=");
78 assertExpectedDecoderException("=?UTF-8??=");
79 assertExpectedDecoderException("=?UTF-8?stuff?=");
80 assertExpectedDecoderException("=?UTF-8?T?stuff");
81 assertExpectedDecoderException("=??T?stuff?=");
82 assertExpectedDecoderException("=?UTF-8??stuff?=");
83 assertExpectedDecoderException("=?UTF-8?W?stuff?=");
84 }
85
86 }