This is an automated email from the ASF dual-hosted git repository. aldettinger pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new fb26761 CAMEL-12209: Made StringHelperTest.testHumanReadableBytes() repeatable fb26761 is described below commit fb267614d15051b1c5cedd95069b97520ca95e8a Author: aldettinger <aldettin...@gmail.com> AuthorDate: Mon Jan 29 19:39:00 2018 +0100 CAMEL-12209: Made StringHelperTest.testHumanReadableBytes() repeatable --- .../java/org/apache/camel/util/StringHelper.java | 19 +++++++++++++-- .../org/apache/camel/util/StringHelperTest.java | 27 ++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) 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 e028f9f..6a68a8f 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,32 @@ public final class StringHelper { /** * Outputs the bytes in human readable format in units of KB,MB,GB etc. * + * @param locale The locale to apply during formatting. If l is {@code null} then no localization is applied. * @param bytes number of bytes * @return human readable output + * @see java.lang.String#format(Locale, String, Object...) */ - 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. + * + * The locale always used is the one returned by {@link java.util.Locale#getDefault()}. + * + * @param bytes number of bytes + * @return human readable output + * @see org.apache.camel.util.StringHelper#humanReadableBytes(Locale, long) + */ + 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 85ec48c..6fb3169 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,22 @@ public class StringHelperTest extends TestCase { } 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)); + } + + public void testHumanReadableBytesNullLocale() { + assertEquals("1.3 KB", StringHelper.humanReadableBytes(null, 1280)); + } + + public void testHumanReadableBytesDefaultLocale() { + assertNotNull(StringHelper.humanReadableBytes(110592)); } } -- To stop receiving notification emails like this one, please contact aldettin...@apache.org.