commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r928757 - in /commons/proper/codec/trunk/src/test/org/apache/commons/codec: binary/Base64Test.java binary/BinaryCodecTest.java binary/HexTest.java net/QuotedPrintableCodecTest.java net/URLCodecTest.java
Date Mon, 29 Mar 2010 12:39:21 GMT
Author: sebb
Date: Mon Mar 29 12:39:21 2010
New Revision: 928757

URL: http://svn.apache.org/viewvc?rev=928757&view=rev
Log:
getBytes() relies on the current encoding; use UTF-8 for portability

Modified:
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.java
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/BinaryCodecTest.java
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/HexTest.java
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
    commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/URLCodecTest.java

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.java?rev=928757&r1=928756&r2=928757&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.java (original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/Base64Test.java Mon
Mar 29 12:39:21 2010
@@ -17,6 +17,7 @@
 
 package org.apache.commons.codec.binary;
 
+import java.io.UnsupportedEncodingException;
 import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.Random;
@@ -100,33 +101,33 @@ public class Base64Test extends TestCase
         Base64.decodeBase64(x);
     }
 
-    public void testCodeInteger1() {
+    public void testCodeInteger1() throws UnsupportedEncodingException {
         String encodedInt1 = "li7dzDacuo67Jg7mtqEm2TRuOMU=";
         BigInteger bigInt1 = new BigInteger("85739377120809420210425962799" + "0318636601332086981");
 
         assertEquals(encodedInt1, new String(Base64.encodeInteger(bigInt1)));
-        assertEquals(bigInt1, Base64.decodeInteger(encodedInt1.getBytes()));
+        assertEquals(bigInt1, Base64.decodeInteger(encodedInt1.getBytes("UTF-8")));
     }
 
-    public void testCodeInteger2() {
+    public void testCodeInteger2() throws UnsupportedEncodingException {
         String encodedInt2 = "9B5ypLY9pMOmtxCeTDHgwdNFeGs=";
         BigInteger bigInt2 = new BigInteger("13936727572861167254666467268" + "91466679477132949611");
 
         assertEquals(encodedInt2, new String(Base64.encodeInteger(bigInt2)));
-        assertEquals(bigInt2, Base64.decodeInteger(encodedInt2.getBytes()));
+        assertEquals(bigInt2, Base64.decodeInteger(encodedInt2.getBytes("UTF-8")));
     }
 
-    public void testCodeInteger3() {
+    public void testCodeInteger3() throws UnsupportedEncodingException {
         String encodedInt3 = "FKIhdgaG5LGKiEtF1vHy4f3y700zaD6QwDS3IrNVGzNp2" + "rY+1LFWTK6D44AyiC1n8uWz1itkYMZF0/aKDK0Yjg==";
         BigInteger bigInt3 = new BigInteger("10806548154093873461951748545"
             + "1196989136416448805819079363524309897749044958112417136240557"
             + "4495062430572478766856090958495998158114332651671116876320938126");
 
         assertEquals(encodedInt3, new String(Base64.encodeInteger(bigInt3)));
-        assertEquals(bigInt3, Base64.decodeInteger(encodedInt3.getBytes()));
+        assertEquals(bigInt3, Base64.decodeInteger(encodedInt3.getBytes("UTF-8")));
     }
 
-    public void testCodeInteger4() {
+    public void testCodeInteger4() throws UnsupportedEncodingException {
         String encodedInt4 = "ctA8YGxrtngg/zKVvqEOefnwmViFztcnPBYPlJsvh6yKI"
             + "4iDm68fnp4Mi3RrJ6bZAygFrUIQLxLjV+OJtgJAEto0xAs+Mehuq1DkSFEpP3o"
             + "DzCTOsrOiS1DwQe4oIb7zVk/9l7aPtJMHW0LVlMdwZNFNNJoqMcT2ZfCPrfvYv"
@@ -139,7 +140,7 @@ public class Base64Test extends TestCase
             + "53542091716518238707344493641683483917");
 
         assertEquals(encodedInt4, new String(Base64.encodeInteger(bigInt4)));
-        assertEquals(bigInt4, Base64.decodeInteger(encodedInt4.getBytes()));
+        assertEquals(bigInt4, Base64.decodeInteger(encodedInt4.getBytes("UTF-8")));
     }
 
     public void testCodeIntegerEdgeCases() {
@@ -216,43 +217,43 @@ public class Base64Test extends TestCase
     /**
      * Tests conditional true branch for "marker0" test.
      */
-    public void testDecodePadMarkerIndex2() {
-        assertEquals("A", new String(Base64.decodeBase64("QQ==".getBytes())));
+    public void testDecodePadMarkerIndex2() throws UnsupportedEncodingException {
+        assertEquals("A", new String(Base64.decodeBase64("QQ==".getBytes("UTF-8"))));
     }
 
     /**
      * Tests conditional branches for "marker1" test.
      */
-    public void testDecodePadMarkerIndex3() {
-        assertEquals("AA", new String(Base64.decodeBase64("QUE=".getBytes())));
-        assertEquals("AAA", new String(Base64.decodeBase64("QUFB".getBytes())));
+    public void testDecodePadMarkerIndex3() throws UnsupportedEncodingException {
+        assertEquals("AA", new String(Base64.decodeBase64("QUE=".getBytes("UTF-8"))));
+        assertEquals("AAA", new String(Base64.decodeBase64("QUFB".getBytes("UTF-8"))));
     }
 
-    public void testDecodePadOnly() {
-        assertTrue(Base64.decodeBase64("====".getBytes()).length == 0);
-        assertEquals("", new String(Base64.decodeBase64("====".getBytes())));
+    public void testDecodePadOnly() throws UnsupportedEncodingException {
+        assertTrue(Base64.decodeBase64("====".getBytes("UTF-8")).length == 0);
+        assertEquals("", new String(Base64.decodeBase64("====".getBytes("UTF-8"))));
         // Test truncated padding
-        assertTrue(Base64.decodeBase64("===".getBytes()).length == 0);
-        assertTrue(Base64.decodeBase64("==".getBytes()).length == 0);
-        assertTrue(Base64.decodeBase64("=".getBytes()).length == 0);
-        assertTrue(Base64.decodeBase64("".getBytes()).length == 0);
+        assertTrue(Base64.decodeBase64("===".getBytes("UTF-8")).length == 0);
+        assertTrue(Base64.decodeBase64("==".getBytes("UTF-8")).length == 0);
+        assertTrue(Base64.decodeBase64("=".getBytes("UTF-8")).length == 0);
+        assertTrue(Base64.decodeBase64("".getBytes("UTF-8")).length == 0);
     }
 
-    public void testDecodePadOnlyChunked() {
-        assertTrue(Base64.decodeBase64("====\n".getBytes()).length == 0);
-        assertEquals("", new String(Base64.decodeBase64("====\n".getBytes())));
+    public void testDecodePadOnlyChunked() throws UnsupportedEncodingException {
+        assertTrue(Base64.decodeBase64("====\n".getBytes("UTF-8")).length == 0);
+        assertEquals("", new String(Base64.decodeBase64("====\n".getBytes("UTF-8"))));
         // Test truncated padding
-        assertTrue(Base64.decodeBase64("===\n".getBytes()).length == 0);
-        assertTrue(Base64.decodeBase64("==\n".getBytes()).length == 0);
-        assertTrue(Base64.decodeBase64("=\n".getBytes()).length == 0);
-        assertTrue(Base64.decodeBase64("\n".getBytes()).length == 0);
+        assertTrue(Base64.decodeBase64("===\n".getBytes("UTF-8")).length == 0);
+        assertTrue(Base64.decodeBase64("==\n".getBytes("UTF-8")).length == 0);
+        assertTrue(Base64.decodeBase64("=\n".getBytes("UTF-8")).length == 0);
+        assertTrue(Base64.decodeBase64("\n".getBytes("UTF-8")).length == 0);
     }
 
     public void testDecodeWithWhitespace() throws Exception {
 
         String orig = "I am a late night coder.";
 
-        byte[] encodedArray = Base64.encodeBase64(orig.getBytes());
+        byte[] encodedArray = Base64.encodeBase64(orig.getBytes("UTF-8"));
         StringBuffer intermediate = new StringBuffer(new String(encodedArray));
 
         intermediate.insert(2, ' ');
@@ -260,7 +261,7 @@ public class Base64Test extends TestCase
         intermediate.insert(10, '\r');
         intermediate.insert(15, '\n');
 
-        byte[] encodedWithWS = intermediate.toString().getBytes();
+        byte[] encodedWithWS = intermediate.toString().getBytes("UTF-8");
         byte[] decodedWithWS = Base64.decodeBase64(encodedWithWS);
 
         String dest = new String(decodedWithWS);
@@ -272,7 +273,7 @@ public class Base64Test extends TestCase
 
         String orig = "I am a late night coder.";
 
-        byte[] encodedArray = Base64.encodeBase64(orig.getBytes());
+        byte[] encodedArray = Base64.encodeBase64(orig.getBytes("UTF-8"));
         StringBuffer intermediate = new StringBuffer(new String(encodedArray));
 
         intermediate.insert(2, ' ');
@@ -280,7 +281,7 @@ public class Base64Test extends TestCase
         intermediate.insert(10, '\r');
         intermediate.insert(15, '\n');
 
-        byte[] encodedWithWS = intermediate.toString().getBytes();
+        byte[] encodedWithWS = intermediate.toString().getBytes("UTF-8");
         byte[] encodedNoWS = Base64.discardWhitespace(encodedWithWS);
         byte[] decodedWithWS = Base64.decodeBase64(encodedWithWS);
         byte[] decodedNoWS = Base64.decodeBase64(encodedNoWS);
@@ -349,7 +350,7 @@ public class Base64Test extends TestCase
 
     public void testIgnoringNonBase64InDecode() throws Exception {
         assertEquals("The quick brown fox jumped over the lazy dogs.", new String(Base64
-                .decodeBase64("VGhlIH@$#$@%F1aWN@#@#@@rIGJyb3duIGZve\n\r\t%#%#%#%CBqd##$#$W1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes())));
+                .decodeBase64("VGhlIH@$#$@%F1aWN@#@#@@rIGJyb3duIGZve\n\r\t%#%#%#%CBqd##$#$W1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes("UTF-8"))));
     }
 
     public void testIsArrayByteBase64() {
@@ -380,38 +381,38 @@ public class Base64Test extends TestCase
         assertTrue("Base64.isArrayByteBase64(whiteSpace)=true", Base64.isArrayByteBase64(whiteSpace));
     }
 
-    public void testKnownDecodings() {
+    public void testKnownDecodings() throws UnsupportedEncodingException {
         assertEquals("The quick brown fox jumped over the lazy dogs.", new String(Base64
-                .decodeBase64("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes())));
+                .decodeBase64("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==".getBytes("UTF-8"))));
         assertEquals("It was the best of times, it was the worst of times.", new String(Base64
-                .decodeBase64("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==".getBytes())));
+                .decodeBase64("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==".getBytes("UTF-8"))));
         assertEquals("http://jakarta.apache.org/commmons", new String(Base64
-                .decodeBase64("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==".getBytes())));
+                .decodeBase64("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==".getBytes("UTF-8"))));
         assertEquals("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz", new String(Base64
-                .decodeBase64("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==".getBytes())));
+                .decodeBase64("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==".getBytes("UTF-8"))));
         assertEquals("{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }", new String(Base64.decodeBase64("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0="
-                .getBytes())));
-        assertEquals("xyzzy!", new String(Base64.decodeBase64("eHl6enkh".getBytes())));
+                .getBytes("UTF-8"))));
+        assertEquals("xyzzy!", new String(Base64.decodeBase64("eHl6enkh".getBytes("UTF-8"))));
     }
 
-    public void testKnownEncodings() {
+    public void testKnownEncodings() throws UnsupportedEncodingException {
         assertEquals("VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2dzLg==",
new String(Base64
-                .encodeBase64("The quick brown fox jumped over the lazy dogs.".getBytes())));
+                .encodeBase64("The quick brown fox jumped over the lazy dogs.".getBytes("UTF-8"))));
         assertEquals(
                 "YmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJs\r\nYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFo\r\nIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBibGFoIGJsYWggYmxhaCBi\r\nbGFoIGJsYWg=\r\n",
                 new String(
                         Base64
                                 .encodeBase64Chunked("blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
blah blah blah blah blah blah blah blah blah blah blah"
-                                        .getBytes())));
+                                        .getBytes("UTF-8"))));
         assertEquals("SXQgd2FzIHRoZSBiZXN0IG9mIHRpbWVzLCBpdCB3YXMgdGhlIHdvcnN0IG9mIHRpbWVzLg==",
new String(Base64
-                .encodeBase64("It was the best of times, it was the worst of times.".getBytes())));
+                .encodeBase64("It was the best of times, it was the worst of times.".getBytes("UTF-8"))));
         assertEquals("aHR0cDovL2pha2FydGEuYXBhY2hlLm9yZy9jb21tbW9ucw==", new String(Base64
-                .encodeBase64("http://jakarta.apache.org/commmons".getBytes())));
+                .encodeBase64("http://jakarta.apache.org/commmons".getBytes("UTF-8"))));
         assertEquals("QWFCYkNjRGRFZUZmR2dIaElpSmpLa0xsTW1Obk9vUHBRcVJyU3NUdFV1VnZXd1h4WXlaeg==",
new String(Base64
-                .encodeBase64("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz".getBytes())));
+                .encodeBase64("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz".getBytes("UTF-8"))));
         assertEquals("eyAwLCAxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5IH0=", new String(Base64.encodeBase64("{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }"
-                .getBytes())));
-        assertEquals("eHl6enkh", new String(Base64.encodeBase64("xyzzy!".getBytes())));
+                .getBytes("UTF-8"))));
+        assertEquals("eHl6enkh", new String(Base64.encodeBase64("xyzzy!".getBytes("UTF-8"))));
     }
 
     public void testNonBase64Test() throws Exception {
@@ -450,7 +451,7 @@ public class Base64Test extends TestCase
     public void testObjectDecodeWithValidParameter() throws Exception {
 
         String original = "Hello World!";
-        Object o = Base64.encodeBase64(original.getBytes());
+        Object o = Base64.encodeBase64(original.getBytes("UTF-8"));
 
         Base64 b64 = new Base64();
         Object oDecoded = b64.decode(o);
@@ -473,7 +474,7 @@ public class Base64Test extends TestCase
     public void testObjectEncodeWithValidParameter() throws Exception {
 
         String original = "Hello World!";
-        Object origObj = original.getBytes();
+        Object origObj = original.getBytes("UTF-8");
 
         Base64 b64 = new Base64();
         Object oEncoded = b64.encode(origObj);

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/BinaryCodecTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/BinaryCodecTest.java?rev=928757&r1=928756&r2=928757&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/BinaryCodecTest.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/BinaryCodecTest.java
Mon Mar 29 12:39:21 2010
@@ -17,6 +17,8 @@
 
 package org.apache.commons.codec.binary;
 
+import java.io.UnsupportedEncodingException;
+
 import junit.framework.TestCase;
 
 import org.apache.commons.codec.DecoderException;
@@ -183,14 +185,14 @@ public class BinaryCodecTest extends Tes
      * @param encodeMe
      *            data to encode and compare
      */
-    void assertDecodeObject(byte[] bits, String encodeMe) throws DecoderException {
+    void assertDecodeObject(byte[] bits, String encodeMe) throws DecoderException, UnsupportedEncodingException
{
         byte[] decoded;
         decoded = (byte[]) instance.decode(encodeMe);
         assertEquals(new String(bits), new String(decoded));
         if (encodeMe == null) {
             decoded = instance.decode((byte[]) null);
         } else {
-            decoded = (byte[]) instance.decode((Object) encodeMe.getBytes());
+            decoded = (byte[]) instance.decode((Object) encodeMe.getBytes("UTF-8"));
         }
         assertEquals(new String(bits), new String(decoded));
         if (encodeMe == null) {
@@ -204,87 +206,87 @@ public class BinaryCodecTest extends Tes
     /*
      * Tests for byte[] decode(byte[])
      */
-    public void testDecodeByteArray() {
+    public void testDecodeByteArray() throws UnsupportedEncodingException {
         // With a single raw binary
         byte[] bits = new byte[1];
-        byte[] decoded = instance.decode("00000000".getBytes());
+        byte[] decoded = instance.decode("00000000".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0;
-        decoded = instance.decode("00000001".getBytes());
+        decoded = instance.decode("00000001".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1;
-        decoded = instance.decode("00000011".getBytes());
+        decoded = instance.decode("00000011".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2;
-        decoded = instance.decode("00000111".getBytes());
+        decoded = instance.decode("00000111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3;
-        decoded = instance.decode("00001111".getBytes());
+        decoded = instance.decode("00001111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4;
-        decoded = instance.decode("00011111".getBytes());
+        decoded = instance.decode("00011111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5;
-        decoded = instance.decode("00111111".getBytes());
+        decoded = instance.decode("00111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6;
-        decoded = instance.decode("01111111".getBytes());
+        decoded = instance.decode("01111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("11111111".getBytes());
+        decoded = instance.decode("11111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         // With a two raw binaries
         bits = new byte[2];
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("0000000011111111".getBytes());
+        decoded = instance.decode("0000000011111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("0000000111111111".getBytes());
+        decoded = instance.decode("0000000111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("0000001111111111".getBytes());
+        decoded = instance.decode("0000001111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("0000011111111111".getBytes());
+        decoded = instance.decode("0000011111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("0000111111111111".getBytes());
+        decoded = instance.decode("0000111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("0001111111111111".getBytes());
+        decoded = instance.decode("0001111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("0011111111111111".getBytes());
+        decoded = instance.decode("0011111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("0111111111111111".getBytes());
+        decoded = instance.decode("0111111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = instance.decode("1111111111111111".getBytes());
+        decoded = instance.decode("1111111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
     }
 
@@ -484,89 +486,89 @@ public class BinaryCodecTest extends Tes
     /*
      * Tests for byte[] fromAscii(byte[])
      */
-    public void testFromAsciiByteArray() {
+    public void testFromAsciiByteArray() throws UnsupportedEncodingException {
         assertEquals(0, BinaryCodec.fromAscii((byte[]) null).length);
         assertEquals(0, BinaryCodec.fromAscii(new byte[0]).length);
         // With a single raw binary
         byte[] bits = new byte[1];
-        byte[] decoded = BinaryCodec.fromAscii("00000000".getBytes());
+        byte[] decoded = BinaryCodec.fromAscii("00000000".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0;
-        decoded = BinaryCodec.fromAscii("00000001".getBytes());
+        decoded = BinaryCodec.fromAscii("00000001".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1;
-        decoded = BinaryCodec.fromAscii("00000011".getBytes());
+        decoded = BinaryCodec.fromAscii("00000011".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2;
-        decoded = BinaryCodec.fromAscii("00000111".getBytes());
+        decoded = BinaryCodec.fromAscii("00000111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3;
-        decoded = BinaryCodec.fromAscii("00001111".getBytes());
+        decoded = BinaryCodec.fromAscii("00001111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4;
-        decoded = BinaryCodec.fromAscii("00011111".getBytes());
+        decoded = BinaryCodec.fromAscii("00011111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5;
-        decoded = BinaryCodec.fromAscii("00111111".getBytes());
+        decoded = BinaryCodec.fromAscii("00111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6;
-        decoded = BinaryCodec.fromAscii("01111111".getBytes());
+        decoded = BinaryCodec.fromAscii("01111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[1];
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("11111111".getBytes());
+        decoded = BinaryCodec.fromAscii("11111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         // With a two raw binaries
         bits = new byte[2];
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("0000000011111111".getBytes());
+        decoded = BinaryCodec.fromAscii("0000000011111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("0000000111111111".getBytes());
+        decoded = BinaryCodec.fromAscii("0000000111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("0000001111111111".getBytes());
+        decoded = BinaryCodec.fromAscii("0000001111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("0000011111111111".getBytes());
+        decoded = BinaryCodec.fromAscii("0000011111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("0000111111111111".getBytes());
+        decoded = BinaryCodec.fromAscii("0000111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("0001111111111111".getBytes());
+        decoded = BinaryCodec.fromAscii("0001111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("0011111111111111".getBytes());
+        decoded = BinaryCodec.fromAscii("0011111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6;
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("0111111111111111".getBytes());
+        decoded = BinaryCodec.fromAscii("0111111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         bits = new byte[2];
         bits[1] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
         bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7);
-        decoded = BinaryCodec.fromAscii("1111111111111111".getBytes());
+        decoded = BinaryCodec.fromAscii("1111111111111111".getBytes("UTF-8"));
         assertEquals(new String(bits), new String(decoded));
         assertEquals(0, BinaryCodec.fromAscii((byte[]) null).length);
     }

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/HexTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/HexTest.java?rev=928757&r1=928756&r2=928757&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/HexTest.java (original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/binary/HexTest.java Mon Mar
29 12:39:21 2010
@@ -175,9 +175,9 @@ public class HexTest extends TestCase {
         assertEquals(name, sourceString, actualStringFromBytes);
     }
 
-    public void testCustomCharsetBadNameEncodeByteArray() {
+    public void testCustomCharsetBadNameEncodeByteArray() throws UnsupportedEncodingException
{
         try {
-            new Hex(BAD_ENCODING_NAME).encode("Hello World".getBytes());
+            new Hex(BAD_ENCODING_NAME).encode("Hello World".getBytes("UTF-8"));
             fail("Expected " + IllegalStateException.class.getName());
         } catch (IllegalStateException e) {
             // Expected
@@ -193,9 +193,9 @@ public class HexTest extends TestCase {
         }
     }
 
-    public void testCustomCharsetBadNameDecodeObject() {
+    public void testCustomCharsetBadNameDecodeObject() throws UnsupportedEncodingException
{
         try {
-            new Hex(BAD_ENCODING_NAME).decode("Hello World".getBytes());
+            new Hex(BAD_ENCODING_NAME).decode("Hello World".getBytes("UTF-8"));
             fail("Expected " + DecoderException.class.getName());
         } catch (DecoderException e) {
             // Expected

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/QuotedPrintableCodecTest.java?rev=928757&r1=928756&r2=928757&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
(original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/QuotedPrintableCodecTest.java
Mon Mar 29 12:39:21 2010
@@ -145,7 +145,7 @@ public class QuotedPrintableCodecTest ex
         QuotedPrintableCodec qpcodec = new QuotedPrintableCodec();
         String plain = "1+1 = 2";
         String encoded = new String(QuotedPrintableCodec.
-            encodeQuotedPrintable(null, plain.getBytes()));
+            encodeQuotedPrintable(null, plain.getBytes("UTF-8")));
         assertEquals("Basic quoted-printable encoding test", 
             "1+1 =3D 2", encoded);
         assertEquals("Basic quoted-printable decoding test", 
@@ -180,7 +180,7 @@ public class QuotedPrintableCodecTest ex
         assertEquals("Basic quoted-printable encoding test", 
             "1+1 =3D 2", encoded);
 
-        byte[] plainBA = plain.getBytes();
+        byte[] plainBA = plain.getBytes("UTF-8");
         byte[] encodedBA = (byte[]) qpcodec.encode((Object) plainBA);
         encoded = new String(encodedBA);
         assertEquals("Basic quoted-printable encoding test", 
@@ -222,7 +222,7 @@ public class QuotedPrintableCodecTest ex
         assertEquals("Basic quoted-printable decoding test", 
             "1+1 = 2", decoded);
 
-        byte[] plainBA = plain.getBytes();
+        byte[] plainBA = plain.getBytes("UTF-8");
         byte[] decodedBA = (byte[]) qpcodec.decode((Object) plainBA);
         decoded = new String(decodedBA);
         assertEquals("Basic quoted-printable decoding test", 

Modified: commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/URLCodecTest.java
URL: http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/URLCodecTest.java?rev=928757&r1=928756&r2=928757&view=diff
==============================================================================
--- commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/URLCodecTest.java (original)
+++ commons/proper/codec/trunk/src/test/org/apache/commons/codec/net/URLCodecTest.java Mon
Mar 29 12:39:21 2010
@@ -180,7 +180,7 @@ public class URLCodecTest extends TestCa
     public void testEncodeUrlWithNullBitSet() throws Exception {
         URLCodec urlCodec = new URLCodec();
         String plain = "Hello there!";
-        String encoded = new String( URLCodec.encodeUrl(null, plain.getBytes()));
+        String encoded = new String( URLCodec.encodeUrl(null, plain.getBytes("UTF-8")));
         assertEquals("Basic URL encoding test", 
             "Hello+there%21", encoded);
         assertEquals("Basic URL decoding test", 
@@ -215,7 +215,7 @@ public class URLCodecTest extends TestCa
         assertEquals("Basic URL encoding test", 
             "Hello+there%21", encoded);
 
-        byte[] plainBA = plain.getBytes();
+        byte[] plainBA = plain.getBytes("UTF-8");
         byte[] encodedBA = (byte[]) urlCodec.encode((Object) plainBA);
         encoded = new String(encodedBA);
         assertEquals("Basic URL encoding test", 
@@ -259,7 +259,7 @@ public class URLCodecTest extends TestCa
         assertEquals("Basic URL decoding test", 
             "Hello there!", decoded);
 
-        byte[] plainBA = plain.getBytes();
+        byte[] plainBA = plain.getBytes("UTF-8");
         byte[] decodedBA = (byte[]) urlCodec.decode((Object) plainBA);
         decoded = new String(decodedBA);
         assertEquals("Basic URL decoding test", 



Mime
View raw message