1 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 30 public class RFC1522CodecTest extends TestCase { 31 32 public RFC1522CodecTest(String 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 getEncoding() { 48 return "T"; 49 } 50 51 } 52 53 public void testNullInput() throws Exception { 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 { 60 RFC1522TestCodec testcodec = new RFC1522TestCodec(); 61 try { 62 testcodec.decodeText("whatever"); 63 fail("DecoderException should have been thrown"); 64 } catch(DecoderException e) { 65 } 67 try { 68 testcodec.decodeText("=?stuff?="); 69 fail("DecoderException should have been thrown"); 70 } catch(DecoderException e) { 71 } 73 try { 74 testcodec.decodeText("=?UTF-8?stuff?="); 75 fail("DecoderException should have been thrown"); 76 } catch(DecoderException e) { 77 } 79 try { 80 testcodec.decodeText("=?UTF-8?T?stuff"); 81 fail("DecoderException should have been thrown"); 82 } catch(DecoderException e) { 83 } 85 try { 86 testcodec.decodeText("=??T?stuff?="); 87 fail("DecoderException should have been thrown"); 88 } catch(DecoderException e) { 89 } 91 try { 92 testcodec.decodeText("=?UTF-8??stuff?="); 93 fail("DecoderException should have been thrown"); 94 } catch(DecoderException e) { 95 } 97 try { 98 testcodec.decodeText("=?UTF-8?W?stuff?="); 99 fail("DecoderException should have been thrown"); 100 } catch(DecoderException e) { 101 } 103 } 104 105 } 106 | Popular Tags |