camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/3] camel git commit: CAMEL-8356 Polish the code
Date Mon, 02 Mar 2015 05:39:28 GMT
CAMEL-8356 Polish the code


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9a10aa86
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9a10aa86
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9a10aa86

Branch: refs/heads/master
Commit: 9a10aa86387911c250da7970e2621cae302b1630
Parents: 1a4fde1
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Mon Mar 2 13:37:14 2015 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Mon Mar 2 13:39:04 2015 +0800

----------------------------------------------------------------------
 .../camel/converter/IOConverterCharsetTest.java | 32 ++++++++++++--------
 1 file changed, 20 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9a10aa86/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
b/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
index 52f2d10..b96175e 100644
--- a/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/converter/IOConverterCharsetTest.java
@@ -29,9 +29,16 @@ import org.apache.camel.ContextTestSupport;
 
 public class IOConverterCharsetTest extends ContextTestSupport {
     private static final String CONTENT = "G\u00f6tzend\u00e4mmerung,Joseph und seine Br\u00fcder";
+    private static final Charset DEFAULT_CHARSET = Charset.defaultCharset();
+    
+    // Just set the default charset back
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        switchToDefaultCharset(DEFAULT_CHARSET.displayName());
+    }
 
     public void testToInputStreamFileWithCharsetUTF8() throws Exception {
-    	switchToDefaultCharset("UTF-8");
+        switchToDefaultCharset("UTF-8");
         File file = new File("src/test/resources/org/apache/camel/converter/german.utf-8.txt");
         InputStream in = IOConverter.toInputStream(file, "UTF-8");
         // do read with default charset!
@@ -50,7 +57,7 @@ public class IOConverterCharsetTest extends ContextTestSupport {
     }
 
     public void testToInputStreamFileWithCharsetUTF8withOtherDefaultEncoding() throws Exception
{
-    	switchToDefaultCharset("ISO-8859-1");
+        switchToDefaultCharset("ISO-8859-1");
         File file = new File("src/test/resources/org/apache/camel/converter/german.utf-8.txt");
         InputStream in = IOConverter.toInputStream(file, "UTF-8");
         // do read with default charset!
@@ -69,7 +76,7 @@ public class IOConverterCharsetTest extends ContextTestSupport {
     }
 
     public void testToInputStreamFileWithCharsetLatin1() throws Exception {
-    	switchToDefaultCharset("UTF-8");
+        switchToDefaultCharset("UTF-8");
         File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
         InputStream in = IOConverter.toInputStream(file, "ISO-8859-1");
         // do read with default charset!
@@ -87,7 +94,7 @@ public class IOConverterCharsetTest extends ContextTestSupport {
     }
 
     public void testToInputStreamFileDirectByteDumpWithCharsetLatin1() throws Exception {
-    	switchToDefaultCharset("UTF-8");
+        switchToDefaultCharset("UTF-8");
         File file = new File("src/test/resources/org/apache/camel/converter/german.iso-8859-1.txt");
         InputStream in = IOConverter.toInputStream(file, "ISO-8859-1");
         InputStream naiveIn = new FileInputStream(file);
@@ -134,12 +141,13 @@ public class IOConverterCharsetTest extends ContextTestSupport {
     }
 
 
-	private void switchToDefaultCharset(String charset) {
-		try {
-			Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
-			defaultCharset.setAccessible(true);
-			defaultCharset.set(null, Charset.forName(charset));
-		} catch (Exception e) {
-		}
-	}
+    private void switchToDefaultCharset(String charset) {
+        try {
+            Field defaultCharset = Charset.class.getDeclaredField("defaultCharset");
+            defaultCharset.setAccessible(true);
+            defaultCharset.set(null, Charset.forName(charset));
+        } catch (Exception e) {
+            // Do nothing here
+        }
+    }
 }


Mime
View raw message