cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [2/3] git commit: updated refs/heads/master to d632d63
Date Thu, 23 Jul 2015 06:09:01 GMT
CLOUDSTACK-8660 - Adding a method to check if UTF-8 is supported

   - Changing the test to call isUtf8Supported() before checking if the preferred charset
is actually UTF-8

Signed-off-by: wilderrodrigues <wrodrigues@schubergphilis.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/245c976a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/245c976a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/245c976a

Branch: refs/heads/master
Commit: 245c976ad03bc7a8b91a44878ddfe8e30c734d5a
Parents: 59d7bc3
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Wed Jul 22 13:37:43 2015 +0200
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Thu Jul 23 08:08:46 2015 +0200

----------------------------------------------------------------------
 utils/src/com/cloud/utils/StringUtils.java      | 10 +++++++---
 utils/test/com/cloud/utils/StringUtilsTest.java | 19 ++++++++++++-------
 2 files changed, 19 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/245c976a/utils/src/com/cloud/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java
index d1225c5..02a616b 100644
--- a/utils/src/com/cloud/utils/StringUtils.java
+++ b/utils/src/com/cloud/utils/StringUtils.java
@@ -34,11 +34,11 @@ public class StringUtils {
     private static final char[] hexChar = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'};
 
     private static Charset preferredACSCharset;
+    private static final String UTF8 = "UTF-8";
 
     static {
-        final String preferredCharset = "UTF-8";
-        if (Charset.isSupported(preferredCharset)) {
-            preferredACSCharset = Charset.forName(preferredCharset);
+        if (isUtf8Supported()) {
+            preferredACSCharset = Charset.forName(UTF8);
         } else {
             preferredACSCharset = Charset.defaultCharset();
         }
@@ -48,6 +48,10 @@ public class StringUtils {
         return preferredACSCharset;
     }
 
+    public static boolean isUtf8Supported() {
+        return Charset.isSupported(UTF8);
+    }
+
     public static String join(final Iterable<? extends Object> iterable, final String
delim) {
         final StringBuilder sb = new StringBuilder();
         if (iterable != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/245c976a/utils/test/com/cloud/utils/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/StringUtilsTest.java b/utils/test/com/cloud/utils/StringUtilsTest.java
index 7671cff..a9eeac7 100644
--- a/utils/test/com/cloud/utils/StringUtilsTest.java
+++ b/utils/test/com/cloud/utils/StringUtilsTest.java
@@ -20,24 +20,29 @@
 package com.cloud.utils;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 
-import junit.framework.Assert;
-
 import org.junit.Test;
 
 public class StringUtilsTest {
+
     @Test
-    public void testGetPrefferedCharset() {
-        assertEquals(StringUtils.getPreferredCharset(), Charset.forName("UTF-8"));
+    public void testGetPreferredCharset() {
+        final boolean ifUtf8Supported = StringUtils.isUtf8Supported();
+        if (ifUtf8Supported) {
+            assertEquals(StringUtils.getPreferredCharset(), Charset.forName("UTF-8"));
+        } else {
+            assertNotEquals(StringUtils.getPreferredCharset(), Charset.forName("UTF-8"));
+        }
     }
 
     @Test
     public void testGetDefaultCharset() {
-        assertEquals(StringUtils.getPreferredCharset(),Charset.defaultCharset());
+        assertEquals(StringUtils.getPreferredCharset(), Charset.defaultCharset());
     }
 
     @Test
@@ -238,7 +243,7 @@ public class StringUtilsTest {
 
     @Test
     public void listToCsvTags() {
-        Assert.assertEquals("a,b,c", StringUtils.listToCsvTags(Arrays.asList("a","b", "c")));
-        Assert.assertEquals("", StringUtils.listToCsvTags(new ArrayList<String>()));
+        assertEquals("a,b,c", StringUtils.listToCsvTags(Arrays.asList("a","b", "c")));
+        assertEquals("", StringUtils.listToCsvTags(new ArrayList<String>()));
     }
 }


Mime
View raw message