Copied: commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/QuotedPrintableStringCodecTest.java
(from r1157197, commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/QuotedPrintableCodecTest.java)
URL: http://svn.apache.org/viewvc/commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/QuotedPrintableStringCodecTest.java?p2=commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/QuotedPrintableStringCodecTest.java&p1=commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/QuotedPrintableCodecTest.java&r1=1157197&r2=1157231&rev=1157231&view=diff
==============================================================================
--- commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
(original)
+++ commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/QuotedPrintableStringCodecTest.java
Fri Aug 12 19:50:56 2011
@@ -33,7 +33,7 @@ import org.junit.Test;
* @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
* @version $Id$
*/
-public class QuotedPrintableCodecTest {
+public class QuotedPrintableStringCodecTest {
static final int SWISS_GERMAN_STUFF_UNICODE [] = {
0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4
@@ -60,7 +60,7 @@ public class QuotedPrintableCodecTest {
String ru_msg = constructString(RUSSIAN_STUFF_UNICODE);
String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE);
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
assertEquals(
"=D0=92=D1=81=D0=B5=D0=BC_=D0=BF=D1=80=D0=B8=D0=B2=D0=B5=D1=82",
@@ -74,7 +74,7 @@ public class QuotedPrintableCodecTest {
@Test
public void testBasicEncodeDecode() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
String plain = "= Hello there =\r\n";
String encoded = qpcodec.encode(plain);
assertEquals("Basic quoted-printable encoding test",
@@ -85,7 +85,7 @@ public class QuotedPrintableCodecTest {
@Test
public void testSafeCharEncodeDecode() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
String plain = "abc123_-.*~!@#$%^&()+{}\"\\;:`,/[]";
String encoded = qpcodec.encode(plain);
assertEquals("Safe chars quoted-printable encoding test",
@@ -97,7 +97,7 @@ public class QuotedPrintableCodecTest {
@Test
public void testUnsafeEncodeDecode() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
String plain = "=\r\n";
String encoded = qpcodec.encode(plain);
assertEquals("Unsafe chars quoted-printable encoding test",
@@ -108,7 +108,7 @@ public class QuotedPrintableCodecTest {
@Test
public void testEncodeDecodeNull() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
assertNull("Null string quoted-printable encoding test",
qpcodec.encode((String)null));
assertNull("Null string quoted-printable decoding test",
@@ -118,7 +118,7 @@ public class QuotedPrintableCodecTest {
@Test
public void testDecodeInvalid() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
try {
qpcodec.decode("=");
fail("DecoderException should have been thrown");
@@ -141,7 +141,7 @@ public class QuotedPrintableCodecTest {
@Test
public void testEncodeNull() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
byte[] plain = null;
byte[] encoded = qpcodec.encode(plain);
assertEquals("Encoding a null string should return null",
@@ -150,9 +150,9 @@ public class QuotedPrintableCodecTest {
@Test
public void testEncodeUrlWithNullBitSet() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
String plain = "1+1 = 2";
- String encoded = new String(QuotedPrintableCodec.
+ String encoded = new String(QuotedPrintableStringCodec.
encodeQuotedPrintable(null, plain.getBytes("UTF-8")));
assertEquals("Basic quoted-printable encoding test",
"1+1 =3D 2", encoded);
@@ -164,13 +164,13 @@ public class QuotedPrintableCodecTest {
@Test
public void testDecodeWithNullArray() throws Exception {
byte[] plain = null;
- byte[] result = QuotedPrintableCodec.decodeQuotedPrintable( plain );
+ byte[] result = QuotedPrintableStringCodec.decodeQuotedPrintable( plain );
assertEquals("Result should be null", null, result);
}
@Test
public void testEncodeStringWithNull() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
String test = null;
String result = qpcodec.encode( test, "charset" );
assertEquals("Result should be null", null, result);
@@ -178,41 +178,33 @@ public class QuotedPrintableCodecTest {
@Test
public void testDecodeStringWithNull() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
String test = null;
String result = qpcodec.decode( test, "charset" );
assertEquals("Result should be null", null, result);
}
@Test
- public void testEncodeObjects() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ public void testEncodeStrings() throws Exception {
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
String plain = "1+1 = 2";
- String encoded = (String) qpcodec.encode((Object) plain);
+ String encoded = qpcodec.encode(plain);
assertEquals("Basic quoted-printable encoding test",
"1+1 =3D 2", encoded);
byte[] plainBA = plain.getBytes("UTF-8");
- byte[] encodedBA = (byte[]) qpcodec.encode((Object) plainBA);
+ byte[] encodedBA = qpcodec.encode(plainBA);
encoded = new String(encodedBA);
assertEquals("Basic quoted-printable encoding test",
"1+1 =3D 2", encoded);
- Object result = qpcodec.encode((Object) null);
- assertEquals( "Encoding a null Object should return null", null, result);
-
- try {
- Object dObj = new Double(3.0);
- qpcodec.encode( dObj );
- fail( "Trying to url encode a Double object should cause an exception.");
- } catch (EncoderException ee) {
- // Exception expected, test segment passes.
- }
+ Object result = qpcodec.encode((String)null);
+ assertEquals( "Encoding a null Object should return null", null, result);
}
@Test
public void testInvalidEncoding() {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec("NONSENSE");
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec("NONSENSE");
String plain = "Hello there!";
try {
qpcodec.encode(plain);
@@ -229,35 +221,27 @@ public class QuotedPrintableCodecTest {
}
@Test
- public void testDecodeObjects() throws Exception {
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
+ public void testDecodeStrings() throws Exception {
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec();
String plain = "1+1 =3D 2";
- String decoded = (String) qpcodec.decode((Object) plain);
+ String decoded = qpcodec.decode(plain);
assertEquals("Basic quoted-printable decoding test",
"1+1 = 2", decoded);
byte[] plainBA = plain.getBytes("UTF-8");
- byte[] decodedBA = (byte[]) qpcodec.decode((Object) plainBA);
+ byte[] decodedBA = qpcodec.decode(plainBA);
decoded = new String(decodedBA);
assertEquals("Basic quoted-printable decoding test",
"1+1 = 2", decoded);
- Object result = qpcodec.decode((Object) null);
- assertEquals( "Decoding a null Object should return null", null, result);
-
- try {
- Object dObj = new Double(3.0);
- qpcodec.decode( dObj );
- fail( "Trying to url encode a Double object should cause an exception.");
- } catch (DecoderException ee) {
- // Exception expected, test segment passes.
- }
+ String result = qpcodec.decode((String)null);
+ assertEquals( "Decoding a null Object should return null", null, result);
}
@Test
public void testDefaultEncoding() throws Exception {
String plain = "Hello there!";
- QuotedPrintableCodec qpcodec = new QuotedPrintableCodec("UnicodeBig");
+ QuotedPrintableStringCodec qpcodec = new QuotedPrintableStringCodec("UnicodeBig");
qpcodec.encode(plain); // To work around a weird quirk in Java 1.2.2
String encoded1 = qpcodec.encode(plain, "UnicodeBig");
String encoded2 = qpcodec.encode(plain);
@@ -267,7 +251,7 @@ public class QuotedPrintableCodecTest {
@Test
@Ignore
/**
- * The QuotedPrintableCodec documentation states that this is not supported.
+ * The QuotedPrintableStringCodec documentation states that this is not supported.
*
* @throws Exception
* @see <a href="https://issues.apache.org/jira/browse/CODEC-121">CODEC-121</a>
@@ -275,13 +259,13 @@ public class QuotedPrintableCodecTest {
public void testSoftLineBreakDecode() throws Exception {
String qpdata = "If you believe that truth=3Dbeauty, then surely=20=\r\nmathematics
is the most beautiful branch of philosophy.";
String expected = "If you believe that truth=beauty, then surely mathematics is the
most beautiful branch of philosophy.";
- assertEquals(expected, new QuotedPrintableCodec().decode(qpdata));
+ assertEquals(expected, new QuotedPrintableStringCodec().decode(qpdata));
}
@Test
@Ignore
/**
- * The QuotedPrintableCodec documentation states that this is not supported.
+ * The QuotedPrintableStringCodec documentation states that this is not supported.
*
* @throws Exception
* @see <a href="https://issues.apache.org/jira/browse/CODEC-121">CODEC-121</a>
@@ -289,6 +273,6 @@ public class QuotedPrintableCodecTest {
public void testSoftLineBreakEncode() throws Exception {
String qpdata = "If you believe that truth=3Dbeauty, then surely=20=\r\nmathematics
is the most beautiful branch of philosophy.";
String expected = "If you believe that truth=beauty, then surely mathematics is the
most beautiful branch of philosophy.";
- assertEquals(qpdata, new QuotedPrintableCodec().encode(expected));
+ assertEquals(qpdata, new QuotedPrintableStringCodec().encode(expected));
}
}
Added: commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecBinaryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecBinaryTest.java?rev=1157231&view=auto
==============================================================================
--- commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecBinaryTest.java
(added)
+++ commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecBinaryTest.java
Fri Aug 12 19:50:56 2011
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.codec.net;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.codec.DecoderException;
+import org.junit.Test;
+
+/**
+ * URL codec test cases
+ *
+ * @author Apache Software Foundation
+ * @version $Id: URLCodecStringTest.java 1156841 2011-08-11 21:33:42Z ggregory $
+ */
+public class URLCodecBinaryTest {
+
+ static final int SWISS_GERMAN_STUFF_UNICODE [] = {
+ 0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4
+ };
+
+ static final int RUSSIAN_STUFF_UNICODE [] = {
+ 0x412, 0x441, 0x435, 0x43C, 0x5F, 0x43F, 0x440, 0x438,
+ 0x432, 0x435, 0x442
+ };
+
+ private void validateState(URLBinaryCodec urlCodec) {
+ // no tests for now.
+ }
+
+ private String constructString(int [] unicodeChars) {
+ StringBuffer buffer = new StringBuffer();
+ if (unicodeChars != null) {
+ for (int unicodeChar : unicodeChars) {
+ buffer.append((char)unicodeChar);
+ }
+ }
+ return buffer.toString();
+ }
+
+ @Test
+ public void testEncodeDecodeNull() throws Exception {
+ URLBinaryCodec urlCodec = new URLBinaryCodec();
+ assertNull("Null string URL encoding test", urlCodec.encode(null));
+ assertNull("Null string URL decoding test", urlCodec.decode(null));
+ this.validateState(urlCodec);
+ }
+
+ @Test
+ public void testDecodeInvalidContent() throws UnsupportedEncodingException, DecoderException
{
+ String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE);
+ URLBinaryCodec urlCodec = new URLBinaryCodec();
+ byte[] input = ch_msg.getBytes("ISO-8859-1");
+ byte[] output = urlCodec.decode(input);
+ assertEquals(input.length, output.length);
+ for (int i = 0; i < input.length; i++) {
+ assertEquals(input[i], output[i]);
+ }
+ this.validateState(urlCodec);
+ }
+
+ @Test
+ public void testEncodeNull() throws Exception {
+ URLBinaryCodec urlCodec = new URLBinaryCodec();
+ byte[] plain = null;
+ byte[] encoded = urlCodec.encode(plain);
+ assertEquals("Encoding a null string should return null",
+ null, encoded);
+ this.validateState(urlCodec);
+ }
+
+ @Test
+ public void testDecodeWithNullArray() throws Exception {
+ byte[] plain = null;
+ byte[] result = URLBinaryCodec.decodeUrl( plain );
+ assertEquals("Result should be null", null, result);
+ }
+
+ @Test
+ public void testEncodeObjects() throws Exception {
+ URLBinaryCodec urlCodec = new URLBinaryCodec();
+ String plain = "Hello there!";
+
+ byte[] plainBA = plain.getBytes("UTF-8");
+ byte[] encodedBA = urlCodec.encode(plainBA);
+ String encoded = new String(encodedBA);
+ assertEquals("Basic URL encoding test",
+ "Hello+there%21", encoded);
+
+ byte[] result = urlCodec.encode(null);
+ assertEquals( "Encoding a null Object should return null", null, result);
+
+ this.validateState(urlCodec);
+ }
+
+ @Test
+ public void testDecodeObjects() throws Exception {
+ URLBinaryCodec urlCodec = new URLBinaryCodec();
+ String plain = "Hello+there%21";
+
+ byte[] plainBA = plain.getBytes("UTF-8");
+ byte[] decodedBA = (byte[]) urlCodec.decode(plainBA);
+ String decoded = new String(decodedBA);
+ assertEquals("Basic URL decoding test",
+ "Hello there!", decoded);
+
+ byte[] result = urlCodec.decode((byte[]) null);
+ assertEquals( "Decoding a null Object should return null", null, result);
+
+ this.validateState(urlCodec);
+ }
+}
Copied: commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecStringTest.java
(from r1157197, commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecTest.java)
URL: http://svn.apache.org/viewvc/commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecStringTest.java?p2=commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecStringTest.java&p1=commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecTest.java&r1=1157197&r2=1157231&rev=1157231&view=diff
==============================================================================
--- commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecTest.java
(original)
+++ commons/proper/codec/branches/generics/src/test/org/apache/commons/codec/net/URLCodecStringTest.java
Fri Aug 12 19:50:56 2011
@@ -34,7 +34,7 @@ import org.junit.Test;
* @author Apache Software Foundation
* @version $Id$
*/
-public class URLCodecTest {
+public class URLCodecStringTest {
static final int SWISS_GERMAN_STUFF_UNICODE [] = {
0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4
@@ -45,7 +45,7 @@ public class URLCodecTest {
0x432, 0x435, 0x442
};
- private void validateState(URLCodec urlCodec) {
+ private void validateState(URLStringCodec urlCodec) {
// no tests for now.
}
@@ -65,7 +65,7 @@ public class URLCodecTest {
String ru_msg = constructString(RUSSIAN_STUFF_UNICODE);
String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE);
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
this.validateState(urlCodec);
assertEquals(
@@ -81,7 +81,7 @@ public class URLCodecTest {
@Test
public void testBasicEncodeDecode() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
String plain = "Hello there!";
String encoded = urlCodec.encode(plain);
assertEquals("Basic URL encoding test",
@@ -94,7 +94,7 @@ public class URLCodecTest {
@Test
public void testSafeCharEncodeDecode() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
String plain = "abc123_-.*";
String encoded = urlCodec.encode(plain);
assertEquals("Safe chars URL encoding test",
@@ -107,7 +107,7 @@ public class URLCodecTest {
@Test
public void testUnsafeEncodeDecode() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
String plain = "~!@#$%^&()+{}\"\\;:`,/[]";
String encoded = urlCodec.encode(plain);
assertEquals("Unsafe chars URL encoding test",
@@ -120,7 +120,7 @@ public class URLCodecTest {
@Test
public void testEncodeDecodeNull() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
assertNull("Null string URL encoding test",
urlCodec.encode((String)null));
assertNull("Null string URL decoding test",
@@ -131,7 +131,7 @@ public class URLCodecTest {
@Test
public void testDecodeInvalid() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
try {
urlCodec.decode("%");
fail("DecoderException should have been thrown");
@@ -164,7 +164,7 @@ public class URLCodecTest {
@Test
public void testDecodeInvalidContent() throws UnsupportedEncodingException, DecoderException
{
String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE);
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
byte[] input = ch_msg.getBytes("ISO-8859-1");
byte[] output = urlCodec.decode(input);
assertEquals(input.length, output.length);
@@ -176,7 +176,7 @@ public class URLCodecTest {
@Test
public void testEncodeNull() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
byte[] plain = null;
byte[] encoded = urlCodec.encode(plain);
assertEquals("Encoding a null string should return null",
@@ -186,9 +186,9 @@ public class URLCodecTest {
@Test
public void testEncodeUrlWithNullBitSet() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
String plain = "Hello there!";
- String encoded = new String( URLCodec.encodeUrl(null, plain.getBytes("UTF-8")));
+ String encoded = new String( URLStringCodec.encodeUrl(null, plain.getBytes("UTF-8")));
assertEquals("Basic URL encoding test",
"Hello+there%21", encoded);
assertEquals("Basic URL decoding test",
@@ -199,13 +199,13 @@ public class URLCodecTest {
@Test
public void testDecodeWithNullArray() throws Exception {
byte[] plain = null;
- byte[] result = URLCodec.decodeUrl( plain );
+ byte[] result = URLStringCodec.decodeUrl( plain );
assertEquals("Result should be null", null, result);
}
@Test
public void testEncodeStringWithNull() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
String test = null;
String result = urlCodec.encode( test, "charset" );
assertEquals("Result should be null", null, result);
@@ -213,7 +213,7 @@ public class URLCodecTest {
@Test
public void testDecodeStringWithNull() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
String test = null;
String result = urlCodec.decode( test, "charset" );
assertEquals("Result should be null", null, result);
@@ -221,34 +221,27 @@ public class URLCodecTest {
@Test
public void testEncodeObjects() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
String plain = "Hello there!";
- String encoded = (String) urlCodec.encode((Object) plain);
+ String encoded = urlCodec.encode(plain);
assertEquals("Basic URL encoding test",
"Hello+there%21", encoded);
byte[] plainBA = plain.getBytes("UTF-8");
- byte[] encodedBA = (byte[]) urlCodec.encode((Object) plainBA);
+ byte[] encodedBA = (byte[]) urlCodec.encode(plainBA);
encoded = new String(encodedBA);
assertEquals("Basic URL encoding test",
"Hello+there%21", encoded);
- Object result = urlCodec.encode((Object) null);
+ String result = urlCodec.encode((String)null);
assertEquals( "Encoding a null Object should return null", null, result);
- try {
- Object dObj = new Double(3.0);
- urlCodec.encode( dObj );
- fail( "Trying to url encode a Double object should cause an exception.");
- } catch (EncoderException ee) {
- // Exception expected, test segment passes.
- }
this.validateState(urlCodec);
}
@Test
public void testInvalidEncoding() {
- URLCodec urlCodec = new URLCodec("NONSENSE");
+ URLStringCodec urlCodec = new URLStringCodec("NONSENSE");
String plain = "Hello there!";
try {
urlCodec.encode(plain);
@@ -267,35 +260,28 @@ public class URLCodecTest {
@Test
public void testDecodeObjects() throws Exception {
- URLCodec urlCodec = new URLCodec();
+ URLStringCodec urlCodec = new URLStringCodec();
String plain = "Hello+there%21";
- String decoded = (String) urlCodec.decode((Object) plain);
+ String decoded = urlCodec.decode(plain);
assertEquals("Basic URL decoding test",
"Hello there!", decoded);
byte[] plainBA = plain.getBytes("UTF-8");
- byte[] decodedBA = (byte[]) urlCodec.decode((Object) plainBA);
+ byte[] decodedBA = urlCodec.decode(plainBA);
decoded = new String(decodedBA);
assertEquals("Basic URL decoding test",
"Hello there!", decoded);
- Object result = urlCodec.decode((Object) null);
+ String result = urlCodec.decode((String) null);
assertEquals( "Decoding a null Object should return null", null, result);
-
- try {
- Object dObj = new Double(3.0);
- urlCodec.decode( dObj );
- fail( "Trying to url encode a Double object should cause an exception.");
- } catch (DecoderException ee) {
- // Exception expected, test segment passes.
- }
+
this.validateState(urlCodec);
}
@Test
public void testDefaultEncoding() throws Exception {
String plain = "Hello there!";
- URLCodec urlCodec = new URLCodec("UnicodeBig");
+ URLStringCodec urlCodec = new URLStringCodec("UnicodeBig");
urlCodec.encode(plain); // To work around a weird quirk in Java 1.2.2
String encoded1 = urlCodec.encode(plain, "UnicodeBig");
String encoded2 = urlCodec.encode(plain);
|