KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > codec > net > RFC1522CodecTest


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.commons.codec.net;
19
20 import org.apache.commons.codec.DecoderException;
21 import org.apache.commons.codec.EncoderException;
22
23 import junit.framework.TestCase;
24
25 /**
26  * RFC 1522 compliant codec test cases
27  *
28  * @author <a HREF="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
29  */

30 public class RFC1522CodecTest extends TestCase {
31     
32     public RFC1522CodecTest(String JavaDoc name) {
33         super(name);
34     }
35
36
37     class RFC1522TestCodec extends RFC1522Codec {
38
39         protected byte[] doDecoding(byte[] bytes) throws DecoderException {
40             return bytes;
41         }
42
43         protected byte[] doEncoding(byte[] bytes) throws EncoderException {
44             return bytes;
45         }
46
47         protected String JavaDoc getEncoding() {
48             return "T";
49         }
50
51     }
52
53     public void testNullInput() throws Exception JavaDoc {
54         RFC1522TestCodec testcodec = new RFC1522TestCodec();
55         assertNull(testcodec.decodeText(null));
56         assertNull(testcodec.encodeText(null, "UTF-8"));
57     }
58
59     public void testDecodeInvalid() throws Exception JavaDoc {
60         RFC1522TestCodec testcodec = new RFC1522TestCodec();
61         try {
62             testcodec.decodeText("whatever");
63             fail("DecoderException should have been thrown");
64         } catch(DecoderException e) {
65             // Expected. Move on
66
}
67         try {
68             testcodec.decodeText("=?stuff?=");
69             fail("DecoderException should have been thrown");
70         } catch(DecoderException e) {
71             // Expected. Move on
72
}
73         try {
74             testcodec.decodeText("=?UTF-8?stuff?=");
75             fail("DecoderException should have been thrown");
76         } catch(DecoderException e) {
77             // Expected. Move on
78
}
79         try {
80             testcodec.decodeText("=?UTF-8?T?stuff");
81             fail("DecoderException should have been thrown");
82         } catch(DecoderException e) {
83             // Expected. Move on
84
}
85         try {
86             testcodec.decodeText("=??T?stuff?=");
87             fail("DecoderException should have been thrown");
88         } catch(DecoderException e) {
89             // Expected. Move on
90
}
91         try {
92             testcodec.decodeText("=?UTF-8??stuff?=");
93             fail("DecoderException should have been thrown");
94         } catch(DecoderException e) {
95             // Expected. Move on
96
}
97         try {
98             testcodec.decodeText("=?UTF-8?W?stuff?=");
99             fail("DecoderException should have been thrown");
100         } catch(DecoderException e) {
101             // Expected. Move on
102
}
103     }
104
105 }
106
Popular Tags