From 9ae054b7c894706fcaea519a14f48cc773835069 Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Sun, 30 Jan 2011 03:48:40 +0000 Subject: [PATCH] Removed isJavaVersionAtLeast(float) and (int), and added an enum variant with the new JavaVersion enum. Updated the rest of the code, switched isJavaVersionAtLeast over to using java.specification.version and not java.version (the vendor code) and dropped JAVA_VERSION_TRIMMED, JAVA_VERSION_FLOAT and JAVA_VERSION_INT. See: LANG-624 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1065174 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang3/ClassUtils.java | 4 +- .../org/apache/commons/lang3/JavaVersion.java | 82 +++++ .../org/apache/commons/lang3/SystemUtils.java | 346 +----------------- .../commons/lang3/CharEncodingTest.java | 14 +- .../apache/commons/lang3/ClassUtilsTest.java | 8 +- .../apache/commons/lang3/LocaleUtilsTest.java | 4 +- .../apache/commons/lang3/SystemUtilsTest.java | 60 +-- .../commons/lang3/math/NumberUtilsTest.java | 3 +- .../lang3/text/ExtendedMessageFormatTest.java | 3 +- .../commons/lang3/time/DateUtilsTest.java | 13 +- 10 files changed, 118 insertions(+), 419 deletions(-) create mode 100644 src/main/java/org/apache/commons/lang3/JavaVersion.java diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java b/src/main/java/org/apache/commons/lang3/ClassUtils.java index 6593a460b..80b784a06 100644 --- a/src/main/java/org/apache/commons/lang3/ClassUtils.java +++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java @@ -436,7 +436,7 @@ public class ClassUtils { * @return true if assignment possible */ public static boolean isAssignable(Class[] classArray, Class[] toClassArray) { - return isAssignable(classArray, toClassArray, SystemUtils.isJavaVersionAtLeast(1.5f)); + return isAssignable(classArray, toClassArray, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5)); } /** @@ -521,7 +521,7 @@ public class ClassUtils { * @return true if assignment possible */ public static boolean isAssignable(Class cls, Class toClass) { - return isAssignable(cls, toClass, SystemUtils.isJavaVersionAtLeast(1.5f)); + return isAssignable(cls, toClass, SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_5)); } /** diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java new file mode 100644 index 000000000..ce2be7da3 --- /dev/null +++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.lang3; + +/** + *

An enum representing all the versions of the Java specification. + * This is intended to mirror available values from the + * java.specification.version System property.

+ * + * @author Apache Software Foundation + * @since 3.0 + * @version $Id: $ + */ +public enum JavaVersion { + JAVA_0_9(1.5f, "0.9"), // Android + JAVA_1_1(1.1f, "1.1"), + JAVA_1_2(1.2f, "1.2"), + JAVA_1_3(1.3f, "1.3"), + JAVA_1_4(1.4f, "1.4"), + JAVA_1_5(1.5f, "1.5"), + JAVA_1_6(1.6f, "1.6"), + JAVA_1_7(1.7f, "1.7"); + + private float value; + private String name; + + JavaVersion(final float value, final String name) { + this.value = value; + this.name = name; + } + + public boolean atLeast(JavaVersion requiredVersion) { + return this.value >= requiredVersion.value; + } + + // helper for static importing + static JavaVersion getJavaVersion(final String nom) { + return getJavaVersion(nom); + } + static JavaVersion get(final String nom) { + if("0.9".equals(nom)) { + return JAVA_0_9; + } else + if("1.1".equals(nom)) { + return JAVA_1_1; + } else + if("1.2".equals(nom)) { + return JAVA_1_2; + } else + if("1.3".equals(nom)) { + return JAVA_1_3; + } else + if("1.4".equals(nom)) { + return JAVA_1_4; + } else + if("1.5".equals(nom)) { + return JAVA_1_5; + } else + if("1.6".equals(nom)) { + return JAVA_1_6; + } else + if("1.7".equals(nom)) { + return JAVA_1_7; + } else { + return null; + } + } +} diff --git a/src/main/java/org/apache/commons/lang3/SystemUtils.java b/src/main/java/org/apache/commons/lang3/SystemUtils.java index 72b3fe850..24875ea5e 100644 --- a/src/main/java/org/apache/commons/lang3/SystemUtils.java +++ b/src/main/java/org/apache/commons/lang3/SystemUtils.java @@ -473,6 +473,7 @@ public class SystemUtils { * @since Java 1.3 */ public static final String JAVA_SPECIFICATION_VERSION = getSystemProperty("java.specification.version"); + private static final JavaVersion JAVA_SPECIFICATION_VERSION_AS_ENUM = JavaVersion.get(JAVA_SPECIFICATION_VERSION); /** *

@@ -898,71 +899,6 @@ public class SystemUtils { */ public static final String USER_TIMEZONE = getSystemProperty("user.timezone"); - // Java version - // ----------------------------------------------------------------------- - // This MUST be declared after those above as it depends on the - // values being set up - - /** - *

- * Gets the Java version as a String trimming leading letters. - *

- * - *

- * The field will return null if {@link #JAVA_VERSION} is null. - *

- * - * @since 2.1 - */ - public static final String JAVA_VERSION_TRIMMED = getJavaVersionTrimmed(); - - // Java version values - // ----------------------------------------------------------------------- - // These MUST be declared after the trim above as they depend on the - // value being set up - - /** - *

- * Gets the Java version as a float. - *

- * - *

- * Example return values: - *

- * - * - *

- * The field will return zero if {@link #JAVA_VERSION} is null. - *

- * - * @since 2.0 - */ - public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat(); - - /** - *

- * Gets the Java version as an int. - *

- * - *

- * Example return values: - *

- * - * - *

- * The field will return zero if {@link #JAVA_VERSION} is null. - *

- * - * @since 2.0 - */ - public static final int JAVA_VERSION_INT = getJavaVersionAsInt(); - // Java version checks // ----------------------------------------------------------------------- // These MUST be declared after those above as they depend on the @@ -1340,54 +1276,6 @@ public class SystemUtils { return new File(System.getProperty(JAVA_IO_TMPDIR_KEY)); } - /** - *

- * Gets the Java version number as a float. - *

- * - *

- * Example return values: - *

- * - * - *

- * Patch releases are not reported. - *

- * - * @return the version, for example 1.31f for Java 1.3.1 - */ - private static float getJavaVersionAsFloat() { - return toVersionFloat(toJavaVersionIntArray(SystemUtils.JAVA_VERSION, JAVA_VERSION_TRIM_SIZE)); - } - - /** - *

- * Gets the Java version number as an int. - *

- * - *

- * Example return values: - *

- * - * - *

- * Patch releases are not reported. - *

- * - * @return the version, for example 131 for Java 1.3.1 - */ - private static int getJavaVersionAsInt() { - return toVersionInt(toJavaVersionIntArray(SystemUtils.JAVA_VERSION, JAVA_VERSION_TRIM_SIZE)); - } - /** *

* Decides if the Java version matches. @@ -1398,24 +1286,7 @@ public class SystemUtils { * @return true if matches, or false if not or can't determine */ private static boolean getJavaVersionMatches(String versionPrefix) { - return isJavaVersionMatch(JAVA_VERSION_TRIMMED, versionPrefix); - } - - /** - * Trims the text of the java version to start with numbers. - * - * @return the trimmed java version - */ - private static String getJavaVersionTrimmed() { - if (JAVA_VERSION != null) { - for (int i = 0; i < JAVA_VERSION.length(); i++) { - char ch = JAVA_VERSION.charAt(i); - if (ch >= '0' && ch <= '9') { - return JAVA_VERSION.substring(i); - } - } - } - return null; + return isJavaVersionMatch(JAVA_SPECIFICATION_VERSION, versionPrefix); } /** @@ -1530,30 +1401,8 @@ public class SystemUtils { * the required version, for example 1.31f * @return true if the actual version is equal or greater than the required version */ - public static boolean isJavaVersionAtLeast(float requiredVersion) { - return JAVA_VERSION_FLOAT >= requiredVersion; - } - - /** - *

- * Is the Java version at least the requested version. - *

- * - *

- * Example input: - *

- * - * - * @param requiredVersion - * the required version, for example 131 - * @return true if the actual version is equal or greater than the required version - * @since 2.0 - */ - public static boolean isJavaVersionAtLeast(int requiredVersion) { - return JAVA_VERSION_INT >= requiredVersion; + public static boolean isJavaVersionAtLeast(JavaVersion requiredVersion) { + return JAVA_SPECIFICATION_VERSION_AS_ENUM.atLeast(requiredVersion); } /** @@ -1619,193 +1468,6 @@ public class SystemUtils { return osName.startsWith(osNamePrefix); } - /** - *

- * Converts the given Java version string to a float. - *

- * - *

- * Example return values: - *

- * - * - *

- * Patch releases are not reported. - *

- *

- * This method is package private instead of private to support unit test invocation. - *

- * - * @return the version, for example 1.31f for Java 1.3.1 - */ - static float toJavaVersionFloat(String version) { - return toVersionFloat(toJavaVersionIntArray(version, JAVA_VERSION_TRIM_SIZE)); - } - - /** - *

- * Converts the given Java version string to an int. - *

- * - *

- * Example return values: - *

- * - * - *

- * Patch releases are not reported. - *

- *

- * This method is package private instead of private to support unit test invocation. - *

- * - * @return the version, for example 131 for Java 1.3.1 - */ - static int toJavaVersionInt(String version) { - return toVersionInt(toJavaVersionIntArray(version, JAVA_VERSION_TRIM_SIZE)); - } - - /** - *

- * Converts the given Java version string to an int[] of maximum size 3. - *

- * - *

- * Example return values: - *

- * - *

- * This method is package private instead of private to support unit test invocation. - *

- * - * @return the version, for example [1, 5, 0] for Java 1.5.0_21 - */ - static int[] toJavaVersionIntArray(String version) { - return toJavaVersionIntArray(version, Integer.MAX_VALUE); - } - - /** - *

- * Converts the given Java version string to an int[] of maximum size limit. - *

- * - *

- * Example return values: - *

- * - * - * @return the version, for example [1, 5, 0, 21] for Java 1.5.0_21 - */ - private static int[] toJavaVersionIntArray(String version, int limit) { - if (version == null) { - return ArrayUtils.EMPTY_INT_ARRAY; - } - String[] strings = Pattern.compile("[^\\d]").split(version); - int[] ints = new int[Math.min(limit, strings.length)]; - int j = 0; - for (int i = 0; i < strings.length && j < limit; i++) { - String s = strings[i]; - if (s.length() > 0) { - ints[j++] = Integer.parseInt(s); - } - } - return ints; - } - - /** - *

- * Converts given the Java version array to a float. - *

- * - *

- * Example return values: - *

- * - * - *

- * Patch releases are not reported. - *

- * - * @return the version, for example 1.31f for Java 1.3.1 - */ - private static float toVersionFloat(int[] javaVersions) { - if (javaVersions == null || javaVersions.length == 0) { - return 0f; - } - if (javaVersions.length == 1) { - return javaVersions[0]; - } - StringBuilder builder = new StringBuilder(); - builder.append(javaVersions[0]); - builder.append('.'); - for (int i = 1; i < javaVersions.length; i++) { - builder.append(javaVersions[i]); - } - try { - return Float.parseFloat(builder.toString()); - } catch (Exception ex) { - return 0f; - } - } - - /** - *

- * Converts given the Java version array to an int. - *

- * - *

- * Example return values: - *

- * - * - *

- * Patch releases are not reported. - *

- * - * @return the version, for example 1.31f for Java 1.3.1 - */ - private static int toVersionInt(int[] javaVersions) { - if (javaVersions == null) { - return 0; - } - int intVersion = 0; - int len = javaVersions.length; - if (len >= 1) { - intVersion = javaVersions[0] * 100; - } - if (len >= 2) { - intVersion += javaVersions[1] * 10; - } - if (len >= 3) { - intVersion += javaVersions[2]; - } - return intVersion; - } - // ----------------------------------------------------------------------- /** *

diff --git a/src/test/java/org/apache/commons/lang3/CharEncodingTest.java b/src/test/java/org/apache/commons/lang3/CharEncodingTest.java index b0ca6ca3f..1eee1b3b7 100644 --- a/src/test/java/org/apache/commons/lang3/CharEncodingTest.java +++ b/src/test/java/org/apache/commons/lang3/CharEncodingTest.java @@ -19,6 +19,8 @@ package org.apache.commons.lang3; import junit.framework.TestCase; +import static org.apache.commons.lang3.JavaVersion.*; + /** * Tests CharEncoding. * @@ -40,7 +42,7 @@ public class CharEncodingTest extends TestCase { } public void testMustBeSupportedJava1_3_1() { - if (SystemUtils.isJavaVersionAtLeast(1.3f)) { + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_3)) { this.assertSupportedEncoding(CharEncoding.ISO_8859_1); this.assertSupportedEncoding(CharEncoding.US_ASCII); this.assertSupportedEncoding(CharEncoding.UTF_16); @@ -48,7 +50,7 @@ public class CharEncodingTest extends TestCase { this.assertSupportedEncoding(CharEncoding.UTF_16LE); this.assertSupportedEncoding(CharEncoding.UTF_8); } else { - this.warn("Java 1.3 tests not run since the current version is " + SystemUtils.JAVA_VERSION); + this.warn("Java 1.3 tests not run since the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); } } @@ -66,12 +68,12 @@ public class CharEncodingTest extends TestCase { // In this test, I simply deleted the encodings from the 1.3.1 list. // The Javadoc do not specify which encodings are required. // - if (SystemUtils.isJavaVersionAtLeast(1.1f)) { + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_1)) { this.assertSupportedEncoding(CharEncoding.ISO_8859_1); this.assertSupportedEncoding(CharEncoding.US_ASCII); this.assertSupportedEncoding(CharEncoding.UTF_8); } else { - this.warn("Java 1.1 tests not run since the current version is " + SystemUtils.JAVA_VERSION); + this.warn("Java 1.1 tests not run since the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); } } @@ -80,12 +82,12 @@ public class CharEncodingTest extends TestCase { // In this test, I simply deleted the encodings from the 1.3.1 list. // The Javadoc do not specify which encodings are required. // - if (SystemUtils.isJavaVersionAtLeast(1.2f)) { + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_2)) { this.assertSupportedEncoding(CharEncoding.ISO_8859_1); this.assertSupportedEncoding(CharEncoding.US_ASCII); this.assertSupportedEncoding(CharEncoding.UTF_8); } else { - this.warn("Java 1.2 tests not run since the current version is " + SystemUtils.JAVA_VERSION); + this.warn("Java 1.2 tests not run since the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); } } diff --git a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java index 3ec16f085..f66c0a5aa 100644 --- a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java @@ -27,6 +27,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static org.apache.commons.lang3.JavaVersion.*; + import junit.framework.TestCase; /** @@ -265,7 +267,7 @@ public class ClassUtilsTest extends TestCase { assertTrue(ClassUtils.isAssignable(array1s, array1s)); assertTrue(ClassUtils.isAssignable(array1s, array1)); - boolean autoboxing = SystemUtils.isJavaVersionAtLeast(1.5f); + boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5); assertEquals(autoboxing, ClassUtils.isAssignable(arrayPrimitives, arrayWrappers)); assertEquals(autoboxing, ClassUtils.isAssignable(arrayWrappers, arrayPrimitives)); @@ -340,7 +342,7 @@ public class ClassUtilsTest extends TestCase { assertTrue(ClassUtils.isAssignable(String.class, String.class)); assertFalse(ClassUtils.isAssignable(Object.class, String.class)); - boolean autoboxing = SystemUtils.isJavaVersionAtLeast(1.5f); + boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5); assertEquals(autoboxing, ClassUtils.isAssignable(Integer.TYPE, Integer.class)); assertEquals(autoboxing, ClassUtils.isAssignable(Integer.TYPE, Object.class)); @@ -485,7 +487,7 @@ public class ClassUtilsTest extends TestCase { } public void test_isAssignable_DefaultUnboxing_Widening() throws Exception { - boolean autoboxing = SystemUtils.isJavaVersionAtLeast(1.5f); + boolean autoboxing = SystemUtils.isJavaVersionAtLeast(JAVA_1_5); // test byte conversions assertFalse("byte -> char", ClassUtils.isAssignable(Byte.class, Character.TYPE)); diff --git a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java index 28ab263cf..2f054ae94 100644 --- a/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/LocaleUtilsTest.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Locale; import java.util.Set; +import static org.apache.commons.lang3.JavaVersion.*; + import junit.framework.TestCase; /** @@ -212,7 +214,7 @@ public class LocaleUtilsTest extends TestCase { assertValidToLocale("us_EN_A", "us", "EN", "A"); // this isn't pretty, but was caused by a jdk bug it seems // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4210525 - if (SystemUtils.isJavaVersionAtLeast(1.4f)) { + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { assertValidToLocale("us_EN_a", "us", "EN", "a"); assertValidToLocale("us_EN_SFsafdFDsdfF", "us", "EN", "SFsafdFDsdfF"); } else { diff --git a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java index b6bbf8ffb..4d7089162 100644 --- a/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/SystemUtilsTest.java @@ -27,6 +27,8 @@ import java.util.Locale; import junit.framework.Assert; import junit.framework.TestCase; +import static org.apache.commons.lang3.JavaVersion.*; + /** * Unit tests {@link org.apache.commons.lang3.SystemUtils}. * @@ -187,62 +189,6 @@ public class SystemUtilsTest extends TestCase { } } - public void testJavaVersionAsFloat() { - assertEquals(0f, SystemUtils.toJavaVersionFloat(null), 0.000001f); - assertEquals(0f, SystemUtils.toJavaVersionFloat(""), 0.000001f); - assertEquals(0f, SystemUtils.toJavaVersionFloat("0"), 0.000001f); - assertEquals(1.1f, SystemUtils.toJavaVersionFloat("1.1"), 0.000001f); - assertEquals(1.2f, SystemUtils.toJavaVersionFloat("1.2"), 0.000001f); - assertEquals(1.3f, SystemUtils.toJavaVersionFloat("1.3.0"), 0.000001f); - assertEquals(1.31f, SystemUtils.toJavaVersionFloat("1.3.1"), 0.000001f); - assertEquals(1.4f, SystemUtils.toJavaVersionFloat("1.4.0"), 0.000001f); - assertEquals(1.41f, SystemUtils.toJavaVersionFloat("1.4.1"), 0.000001f); - assertEquals(1.42f, SystemUtils.toJavaVersionFloat("1.4.2"), 0.000001f); - assertEquals(1.5f, SystemUtils.toJavaVersionFloat("1.5.0"), 0.000001f); - assertEquals(1.6f, SystemUtils.toJavaVersionFloat("1.6.0"), 0.000001f); - assertEquals(1.31f, SystemUtils.toJavaVersionFloat("JavaVM-1.3.1"), 0.000001f); - assertEquals(1.3f, SystemUtils.toJavaVersionFloat("1.3.0 subset"), 0.000001f); - // This used to return 0f in [lang] version 2.5: - assertEquals(1.3f, SystemUtils.toJavaVersionFloat("XXX-1.3.x"), 0.000001f); - } - - public void testJavaVersionAsInt() { - assertEquals(0, SystemUtils.toJavaVersionInt(null)); - assertEquals(0, SystemUtils.toJavaVersionInt("")); - assertEquals(0, SystemUtils.toJavaVersionInt("0")); - assertEquals(110, SystemUtils.toJavaVersionInt("1.1")); - assertEquals(120, SystemUtils.toJavaVersionInt("1.2")); - assertEquals(130, SystemUtils.toJavaVersionInt("1.3.0")); - assertEquals(131, SystemUtils.toJavaVersionInt("1.3.1")); - assertEquals(140, SystemUtils.toJavaVersionInt("1.4.0")); - assertEquals(141, SystemUtils.toJavaVersionInt("1.4.1")); - assertEquals(142, SystemUtils.toJavaVersionInt("1.4.2")); - assertEquals(150, SystemUtils.toJavaVersionInt("1.5.0")); - assertEquals(160, SystemUtils.toJavaVersionInt("1.6.0")); - assertEquals(131, SystemUtils.toJavaVersionInt("JavaVM-1.3.1")); - assertEquals(131, SystemUtils.toJavaVersionInt("1.3.1 subset")); - // This used to return 0f in [lang] version 2.5: - assertEquals(130, SystemUtils.toJavaVersionInt("XXX-1.3.x")); - } - - public void testJavaVersionAtLeastFloat() { - float version = SystemUtils.JAVA_VERSION_FLOAT; - assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); - version -= 0.1f; - assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); - version += 0.2f; - assertEquals(false, SystemUtils.isJavaVersionAtLeast(version)); - } - - public void testJavaVersionAtLeastInt() { - int version = SystemUtils.JAVA_VERSION_INT; - assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); - version -= 10; - assertEquals(true, SystemUtils.isJavaVersionAtLeast(version)); - version += 20; - assertEquals(false, SystemUtils.isJavaVersionAtLeast(version)); - } - public void testJavaVersionMatches() { String javaVersion = null; assertEquals(false, SystemUtils.isJavaVersionMatch(javaVersion, "1.0")); @@ -401,7 +347,7 @@ public class SystemUtilsTest extends TestCase { } public void testJavaAwtHeadless() { - boolean atLeastJava14 = SystemUtils.isJavaVersionAtLeast(140); + boolean atLeastJava14 = SystemUtils.isJavaVersionAtLeast(JAVA_1_4); String expectedStringValue = System.getProperty("java.awt.headless"); String expectedStringValueWithDefault = System.getProperty("java.awt.headless", "false"); assertNotNull(expectedStringValueWithDefault); diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java index bb94ab31c..a0d99a42e 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java @@ -23,6 +23,7 @@ import java.math.BigInteger; import junit.framework.TestCase; +import static org.apache.commons.lang3.JavaVersion.*; import org.apache.commons.lang3.SystemUtils; /** @@ -198,7 +199,7 @@ public class NumberUtilsTest extends TestCase { .createNumber("12345678901234567890L")); // jdk 1.2 doesn't support this. unsure about jdk 1.2.2 - if (SystemUtils.isJavaVersionAtLeast(1.3f)) { + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_3)) { assertEquals("createNumber(String) 15 failed", new BigDecimal("1.1E-700"), NumberUtils .createNumber("1.1E-700F")); } diff --git a/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java b/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java index e2bde90b4..36b89e8e0 100644 --- a/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java +++ b/src/test/java/org/apache/commons/lang3/text/ExtendedMessageFormatTest.java @@ -34,6 +34,7 @@ import java.util.Map; import junit.framework.TestCase; +import static org.apache.commons.lang3.JavaVersion.*; import org.apache.commons.lang3.SystemUtils; /** @@ -359,7 +360,7 @@ public class ExtendedMessageFormatTest extends TestCase { //can't trust what MessageFormat does with toPattern() pre 1.4: private void assertPatternsEqual(String message, String expected, String actual) { - if (SystemUtils.isJavaVersionAtLeast(1.4f)) { + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { assertEquals(message, expected, actual); } } diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java index 68094f9e9..4fb8ec287 100644 --- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java @@ -32,6 +32,7 @@ import java.util.TimeZone; import junit.framework.AssertionFailedError; import junit.framework.TestCase; +import static org.apache.commons.lang3.JavaVersion.*; import org.apache.commons.lang3.SystemUtils; /** @@ -805,7 +806,7 @@ public class DateUtilsTest extends TestCase { assertEquals("round MET date across DST change-over", dateTimeParser.parse("March 30, 2003 01:00:00.000"), DateUtils.round((Object) cal4, Calendar.HOUR_OF_DAY)); - if (SystemUtils.isJavaVersionAtLeast(1.4f)) { + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { assertEquals("round MET date across DST change-over", dateTimeParser.parse("March 30, 2003 03:00:00.000"), DateUtils.round(date5, Calendar.HOUR_OF_DAY)); @@ -825,7 +826,7 @@ public class DateUtilsTest extends TestCase { dateTimeParser.parse("March 30, 2003 04:00:00.000"), DateUtils.round((Object) cal7, Calendar.HOUR_OF_DAY)); } else { - this.warn("WARNING: Some date rounding tests not run since the current version is " + SystemUtils.JAVA_VERSION); + this.warn("WARNING: Some date rounding tests not run since the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); } TimeZone.setDefault(defaultZone); dateTimeParser.setTimeZone(defaultZone); @@ -1091,8 +1092,8 @@ public class DateUtilsTest extends TestCase { * see http://issues.apache.org/jira/browse/LANG-59 */ public void testTruncateLang59() throws Exception { - if (!SystemUtils.isJavaVersionAtLeast(1.4f)) { - this.warn("WARNING: Test for LANG-59 not run since the current version is " + SystemUtils.JAVA_VERSION); + if (!SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { + this.warn("WARNING: Test for LANG-59 not run since the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); return; } @@ -1379,7 +1380,7 @@ public class DateUtilsTest extends TestCase { assertEquals("ceiling MET date across DST change-over", dateTimeParser.parse("March 30, 2003 03:00:00.000"), DateUtils.ceiling((Object) cal4, Calendar.HOUR_OF_DAY)); - if (SystemUtils.isJavaVersionAtLeast(1.4f)) { + if (SystemUtils.isJavaVersionAtLeast(JAVA_1_4)) { assertEquals("ceiling MET date across DST change-over", dateTimeParser.parse("March 30, 2003 03:00:00.000"), DateUtils.ceiling(date5, Calendar.HOUR_OF_DAY)); @@ -1399,7 +1400,7 @@ public class DateUtilsTest extends TestCase { dateTimeParser.parse("March 30, 2003 04:00:00.000"), DateUtils.ceiling((Object) cal7, Calendar.HOUR_OF_DAY)); } else { - this.warn("WARNING: Some date ceiling tests not run since the current version is " + SystemUtils.JAVA_VERSION); + this.warn("WARNING: Some date ceiling tests not run since the current version is " + SystemUtils.JAVA_SPECIFICATION_VERSION); } TimeZone.setDefault(defaultZone); dateTimeParser.setTimeZone(defaultZone);