From cb2ec37bd393030b58b3aaf3129dcf83c5a0a6c6 Mon Sep 17 00:00:00 2001 From: pascalschumacher Date: Fri, 20 Dec 2019 13:08:50 +0100 Subject: [PATCH] Replace Character constructor (deprecated on Java 9+) calls in tests with Character#valueOf. --- .../apache/commons/lang3/ArrayUtilsTest.java | 18 ++++++++--------- .../apache/commons/lang3/CharUtilsTest.java | 20 +++++++++---------- .../commons/lang3/RandomStringUtilsTest.java | 4 ++-- .../commons/lang3/StringEscapeUtilsTest.java | 4 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java index 3eb76c583..8dfcbcb5a 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java @@ -4340,11 +4340,11 @@ public class ArrayUtilsTest { assertSame(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.toPrimitive(new Character[0])); - assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{new Character(Character.MIN_VALUE), - new Character(Character.MAX_VALUE), new Character('0')})); + assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE), + Character.valueOf(Character.MAX_VALUE), Character.valueOf('0')})); assertThrows(NullPointerException.class, - () -> ArrayUtils.toPrimitive(new Character[]{new Character(Character.MIN_VALUE), null})); + () -> ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE), null})); } @Test @@ -4355,12 +4355,12 @@ public class ArrayUtilsTest { assertSame(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.toPrimitive(new Character[0], (char) 0)); - assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{new Character(Character.MIN_VALUE), - new Character(Character.MAX_VALUE), new Character('0')}, + assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE), + Character.valueOf(Character.MAX_VALUE), Character.valueOf('0')}, Character.MIN_VALUE)); - assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{new Character(Character.MIN_VALUE), null, - new Character('0')}, Character.MAX_VALUE)); + assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE), null, + Character.valueOf('0')}, Character.MAX_VALUE)); } @Test @@ -4371,8 +4371,8 @@ public class ArrayUtilsTest { assertSame(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, ArrayUtils.toObject(new char[0])); - assertArrayEquals(new Character[]{new Character(Character.MIN_VALUE), - new Character(Character.MAX_VALUE), new Character('0')}, ArrayUtils.toObject(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, + assertArrayEquals(new Character[]{Character.valueOf(Character.MIN_VALUE), + Character.valueOf(Character.MAX_VALUE), Character.valueOf('0')}, ArrayUtils.toObject(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'})); } diff --git a/src/test/java/org/apache/commons/lang3/CharUtilsTest.java b/src/test/java/org/apache/commons/lang3/CharUtilsTest.java index d4ba3e62d..ae6be1c97 100644 --- a/src/test/java/org/apache/commons/lang3/CharUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/CharUtilsTest.java @@ -36,8 +36,8 @@ import org.junit.jupiter.api.Test; public class CharUtilsTest { private static final char CHAR_COPY = '\u00a9'; - private static final Character CHARACTER_A = new Character('A'); - private static final Character CHARACTER_B = new Character('B'); + private static final Character CHARACTER_A = Character.valueOf('A'); + private static final Character CHARACTER_B = Character.valueOf('B'); @Test public void testCompare() { @@ -229,7 +229,7 @@ public class CharUtilsTest { @SuppressWarnings("deprecation") // intentional test of deprecated method @Test public void testToCharacterObject_char() { - assertEquals(new Character('a'), CharUtils.toCharacterObject('a')); + assertEquals(Character.valueOf('a'), CharUtils.toCharacterObject('a')); assertSame(CharUtils.toCharacterObject('a'), CharUtils.toCharacterObject('a')); for (int i = 0; i < 128; i++) { @@ -253,8 +253,8 @@ public class CharUtilsTest { public void testToCharacterObject_String() { assertNull(CharUtils.toCharacterObject(null)); assertNull(CharUtils.toCharacterObject("")); - assertEquals(new Character('a'), CharUtils.toCharacterObject("a")); - assertEquals(new Character('a'), CharUtils.toCharacterObject("abc")); + assertEquals(Character.valueOf('a'), CharUtils.toCharacterObject("a")); + assertEquals(Character.valueOf('a'), CharUtils.toCharacterObject("abc")); assertSame(CharUtils.toCharacterObject("a"), CharUtils.toCharacterObject("a")); } @@ -282,17 +282,17 @@ public class CharUtilsTest { @Test public void testToIntValue_Character() { - assertEquals(0, CharUtils.toIntValue(new Character('0'))); - assertEquals(3, CharUtils.toIntValue(new Character('3'))); + assertEquals(0, CharUtils.toIntValue(Character.valueOf('0'))); + assertEquals(3, CharUtils.toIntValue(Character.valueOf('3'))); assertThrows(IllegalArgumentException.class, () -> CharUtils.toIntValue(null)); assertThrows(IllegalArgumentException.class, () -> CharUtils.toIntValue(CHARACTER_A)); } @Test public void testToIntValue_Character_int() { - assertEquals(0, CharUtils.toIntValue(new Character('0'), -1)); - assertEquals(3, CharUtils.toIntValue(new Character('3'), -1)); - assertEquals(-1, CharUtils.toIntValue(new Character('A'), -1)); + assertEquals(0, CharUtils.toIntValue(Character.valueOf('0'), -1)); + assertEquals(3, CharUtils.toIntValue(Character.valueOf('3'), -1)); + assertEquals(-1, CharUtils.toIntValue(Character.valueOf('A'), -1)); assertEquals(-1, CharUtils.toIntValue(null, -1)); } diff --git a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java index 35eddf64d..d18e3c887 100644 --- a/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java @@ -498,8 +498,8 @@ public class RandomStringUtilsTest { final char o = orig.charAt(i); final char c = copy.charAt(i); assertEquals(o, c, - "differs at " + i + "(" + Integer.toHexString(new Character(o).hashCode()) + "," + - Integer.toHexString(new Character(c).hashCode()) + ")"); + "differs at " + i + "(" + Integer.toHexString(Character.valueOf(o).hashCode()) + "," + + Integer.toHexString(Character.valueOf(c).hashCode()) + ")"); } // compare length also assertEquals(orig.length(), copy.length()); diff --git a/src/test/java/org/apache/commons/lang3/StringEscapeUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringEscapeUtilsTest.java index f0160634c..e04c20e5e 100644 --- a/src/test/java/org/apache/commons/lang3/StringEscapeUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringEscapeUtilsTest.java @@ -235,8 +235,8 @@ public class StringEscapeUtilsTest { assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("€Ÿ"), "hex number unescape"); // Test all Character values: for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) { - final Character c1 = new Character(i); - final Character c2 = new Character((char) (i+1)); + final Character c1 = Character.valueOf(i); + final Character c2 = Character.valueOf((char) (i+1)); final String expected = c1.toString() + c2.toString(); final String escapedC1 = "&#x" + Integer.toHexString((c1.charValue())) + ";"; final String escapedC2 = "&#x" + Integer.toHexString((c2.charValue())) + ";";