[ 
https://issues.apache.org/jira/browse/CAMEL-12209?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16348124#comment-16348124
 ] 

ASF GitHub Bot commented on CAMEL-12209:
----------------------------------------

oscerd closed pull request #2198: CAMEL-12209: Proposal to fix by adding an 
overload
URL: https://github.com/apache/camel/pull/2198
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java 
b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
index e028f9f5dc0..1fe5dfb9a6c 100644
--- a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java
@@ -711,17 +711,28 @@ public static boolean containsIgnoreCase(String src, 
String what) {
     /**
      * Outputs the bytes in human readable format in units of KB,MB,GB etc.
      *
+     * @param locale the locale used to format into a human readable 
representation
      * @param bytes number of bytes
      * @return human readable output
      */
-    public static String humanReadableBytes(long bytes) {
+    public static String humanReadableBytes(Locale locale, long bytes) {
         int unit = 1024;
         if (bytes < unit) {
             return bytes + " B";
         }
         int exp = (int) (Math.log(bytes) / Math.log(unit));
         String pre = "KMGTPE".charAt(exp - 1) + "";
-        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
+        return String.format(locale, "%.1f %sB", bytes / Math.pow(unit, exp), 
pre);
+    }
+
+    /**
+     * Outputs the bytes in human readable format in units of KB,MB,GB etc.
+     *
+     * @param bytes number of bytes
+     * @return human readable output
+     */
+    public static String humanReadableBytes(long bytes) {
+        return humanReadableBytes(Locale.getDefault(), bytes);
     }
 
 }
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/StringHelperTest.java 
b/camel-core/src/test/java/org/apache/camel/util/StringHelperTest.java
index 85ec48cef7c..1707f174463 100644
--- a/camel-core/src/test/java/org/apache/camel/util/StringHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/StringHelperTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.util;
 
 import java.util.List;
+import java.util.Locale;
 
 import junit.framework.TestCase;
 
@@ -250,14 +251,14 @@ public void testTrimToNull() {
     }
 
     public void testHumanReadableBytes() {
-        assertEquals("0 B",  StringHelper.humanReadableBytes(0));
-        assertEquals("32 B",  StringHelper.humanReadableBytes(32));
-        assertEquals("1.0 KB",  StringHelper.humanReadableBytes(1024));
-        assertEquals("1.7 KB",  StringHelper.humanReadableBytes(1730));
-        assertEquals("108.0 KB",  StringHelper.humanReadableBytes(110592));
-        assertEquals("6.8 MB",  StringHelper.humanReadableBytes(7077888));
-        assertEquals("432.0 MB",  StringHelper.humanReadableBytes(452984832));
-        assertEquals("27.0 GB",  
StringHelper.humanReadableBytes(28991029248L));
-        assertEquals("1.7 TB",  
StringHelper.humanReadableBytes(1855425871872L));
+        assertEquals("0 B",  StringHelper.humanReadableBytes(Locale.ENGLISH, 
0));
+        assertEquals("32 B",  StringHelper.humanReadableBytes(Locale.ENGLISH, 
32));
+        assertEquals("1.0 KB",  
StringHelper.humanReadableBytes(Locale.ENGLISH, 1024));
+        assertEquals("1.7 KB",  
StringHelper.humanReadableBytes(Locale.ENGLISH, 1730));
+        assertEquals("108.0 KB",  
StringHelper.humanReadableBytes(Locale.ENGLISH, 110592));
+        assertEquals("6.8 MB",  
StringHelper.humanReadableBytes(Locale.ENGLISH, 7077888));
+        assertEquals("432.0 MB",  
StringHelper.humanReadableBytes(Locale.ENGLISH, 452984832));
+        assertEquals("27.0 GB",  
StringHelper.humanReadableBytes(Locale.ENGLISH, 28991029248L));
+        assertEquals("1.7 TB",  
StringHelper.humanReadableBytes(Locale.ENGLISH, 1855425871872L));
     }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> StringHelperTest.testHumanReadableBytes() is not repeatable
> -----------------------------------------------------------
>
>                 Key: CAMEL-12209
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12209
>             Project: Camel
>          Issue Type: Test
>            Reporter: Alex Dettinger
>            Assignee: Alex Dettinger
>            Priority: Minor
>             Fix For: 2.21.0
>
>
> This test expects a byte number (e.g. 1024) to be formatted into a string 
> (e.g. 1.0 KB).
> The implementation is dependent upon the default locale, so this test fails, 
> for instance on a french machine:
> {code:java}
> [ERROR]   Run 1: StringHelperTest.testHumanReadableBytes:262 expected:<1[.]0 
> KB> but was:<1[,]0 KB>
> [ERROR]   Run 2: StringHelperTest.testHumanReadableBytes:262 expected:<1[.]0 
> KB> but was:<1[,]0 KB>
> [ERROR]   Run 3: StringHelperTest.testHumanReadableBytes:262 expected:<1[.]0 
> KB> but was:<1[,]0 KB>{code}
>  
> I will setup a PR to discuss this.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to