001: /*
002: * Copyright 2001-2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.commons.codec.net;
018:
019: import org.apache.commons.codec.DecoderException;
020: import org.apache.commons.codec.EncoderException;
021:
022: import junit.framework.TestCase;
023:
024: /**
025: * RFC 1522 compliant codec test cases
026: *
027: * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
028: */
029: public class RFC1522CodecTest extends TestCase {
030:
031: public RFC1522CodecTest(String name) {
032: super (name);
033: }
034:
035: class RFC1522TestCodec extends RFC1522Codec {
036:
037: protected byte[] doDecoding(byte[] bytes)
038: throws DecoderException {
039: return bytes;
040: }
041:
042: protected byte[] doEncoding(byte[] bytes)
043: throws EncoderException {
044: return bytes;
045: }
046:
047: protected String getEncoding() {
048: return "T";
049: }
050:
051: }
052:
053: public void testNullInput() throws Exception {
054: RFC1522TestCodec testcodec = new RFC1522TestCodec();
055: assertNull(testcodec.decodeText(null));
056: assertNull(testcodec.encodeText(null, "UTF-8"));
057: }
058:
059: public void testDecodeInvalid() throws Exception {
060: RFC1522TestCodec testcodec = new RFC1522TestCodec();
061: try {
062: testcodec.decodeText("whatever");
063: fail("DecoderException should have been thrown");
064: } catch (DecoderException e) {
065: // Expected. Move on
066: }
067: try {
068: testcodec.decodeText("=?stuff?=");
069: fail("DecoderException should have been thrown");
070: } catch (DecoderException e) {
071: // Expected. Move on
072: }
073: try {
074: testcodec.decodeText("=?UTF-8?stuff?=");
075: fail("DecoderException should have been thrown");
076: } catch (DecoderException e) {
077: // Expected. Move on
078: }
079: try {
080: testcodec.decodeText("=?UTF-8?T?stuff");
081: fail("DecoderException should have been thrown");
082: } catch (DecoderException e) {
083: // Expected. Move on
084: }
085: try {
086: testcodec.decodeText("=??T?stuff?=");
087: fail("DecoderException should have been thrown");
088: } catch (DecoderException e) {
089: // Expected. Move on
090: }
091: try {
092: testcodec.decodeText("=?UTF-8??stuff?=");
093: fail("DecoderException should have been thrown");
094: } catch (DecoderException e) {
095: // Expected. Move on
096: }
097: try {
098: testcodec.decodeText("=?UTF-8?W?stuff?=");
099: fail("DecoderException should have been thrown");
100: } catch (DecoderException e) {
101: // Expected. Move on
102: }
103: }
104:
105: }
|