Replace Character constructor (deprecated on Java 9+) calls in tests with Character#valueOf.

This commit is contained in:
pascalschumacher 2019-12-20 13:08:50 +01:00
parent 325d9a97d6
commit cb2ec37bd3
4 changed files with 23 additions and 23 deletions

View File

@ -4340,11 +4340,11 @@ public class ArrayUtilsTest {
assertSame(ArrayUtils.EMPTY_CHAR_ARRAY, ArrayUtils.toPrimitive(new Character[0])); 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), assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE),
new Character(Character.MAX_VALUE), new Character('0')})); Character.valueOf(Character.MAX_VALUE), Character.valueOf('0')}));
assertThrows(NullPointerException.class, assertThrows(NullPointerException.class,
() -> ArrayUtils.toPrimitive(new Character[]{new Character(Character.MIN_VALUE), null})); () -> ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE), null}));
} }
@Test @Test
@ -4355,12 +4355,12 @@ public class ArrayUtilsTest {
assertSame(ArrayUtils.EMPTY_CHAR_ARRAY, assertSame(ArrayUtils.EMPTY_CHAR_ARRAY,
ArrayUtils.toPrimitive(new Character[0], (char) 0)); 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), assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE),
new Character(Character.MAX_VALUE), new Character('0')}, Character.valueOf(Character.MAX_VALUE), Character.valueOf('0')},
Character.MIN_VALUE)); Character.MIN_VALUE));
assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{new Character(Character.MIN_VALUE), null, assertArrayEquals(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, '0'}, ArrayUtils.toPrimitive(new Character[]{Character.valueOf(Character.MIN_VALUE), null,
new Character('0')}, Character.MAX_VALUE)); Character.valueOf('0')}, Character.MAX_VALUE));
} }
@Test @Test
@ -4371,8 +4371,8 @@ public class ArrayUtilsTest {
assertSame(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY, assertSame(ArrayUtils.EMPTY_CHARACTER_OBJECT_ARRAY,
ArrayUtils.toObject(new char[0])); ArrayUtils.toObject(new char[0]));
assertArrayEquals(new Character[]{new Character(Character.MIN_VALUE), assertArrayEquals(new Character[]{Character.valueOf(Character.MIN_VALUE),
new Character(Character.MAX_VALUE), new Character('0')}, ArrayUtils.toObject(new char[]{Character.MIN_VALUE, Character.MAX_VALUE, Character.valueOf(Character.MAX_VALUE), Character.valueOf('0')}, ArrayUtils.toObject(new char[]{Character.MIN_VALUE, Character.MAX_VALUE,
'0'})); '0'}));
} }

View File

@ -36,8 +36,8 @@ import org.junit.jupiter.api.Test;
public class CharUtilsTest { public class CharUtilsTest {
private static final char CHAR_COPY = '\u00a9'; private static final char CHAR_COPY = '\u00a9';
private static final Character CHARACTER_A = new Character('A'); private static final Character CHARACTER_A = Character.valueOf('A');
private static final Character CHARACTER_B = new Character('B'); private static final Character CHARACTER_B = Character.valueOf('B');
@Test @Test
public void testCompare() { public void testCompare() {
@ -229,7 +229,7 @@ public class CharUtilsTest {
@SuppressWarnings("deprecation") // intentional test of deprecated method @SuppressWarnings("deprecation") // intentional test of deprecated method
@Test @Test
public void testToCharacterObject_char() { 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')); assertSame(CharUtils.toCharacterObject('a'), CharUtils.toCharacterObject('a'));
for (int i = 0; i < 128; i++) { for (int i = 0; i < 128; i++) {
@ -253,8 +253,8 @@ public class CharUtilsTest {
public void testToCharacterObject_String() { public void testToCharacterObject_String() {
assertNull(CharUtils.toCharacterObject(null)); assertNull(CharUtils.toCharacterObject(null));
assertNull(CharUtils.toCharacterObject("")); assertNull(CharUtils.toCharacterObject(""));
assertEquals(new Character('a'), CharUtils.toCharacterObject("a")); assertEquals(Character.valueOf('a'), CharUtils.toCharacterObject("a"));
assertEquals(new Character('a'), CharUtils.toCharacterObject("abc")); assertEquals(Character.valueOf('a'), CharUtils.toCharacterObject("abc"));
assertSame(CharUtils.toCharacterObject("a"), CharUtils.toCharacterObject("a")); assertSame(CharUtils.toCharacterObject("a"), CharUtils.toCharacterObject("a"));
} }
@ -282,17 +282,17 @@ public class CharUtilsTest {
@Test @Test
public void testToIntValue_Character() { public void testToIntValue_Character() {
assertEquals(0, CharUtils.toIntValue(new Character('0'))); assertEquals(0, CharUtils.toIntValue(Character.valueOf('0')));
assertEquals(3, CharUtils.toIntValue(new Character('3'))); assertEquals(3, CharUtils.toIntValue(Character.valueOf('3')));
assertThrows(IllegalArgumentException.class, () -> CharUtils.toIntValue(null)); assertThrows(IllegalArgumentException.class, () -> CharUtils.toIntValue(null));
assertThrows(IllegalArgumentException.class, () -> CharUtils.toIntValue(CHARACTER_A)); assertThrows(IllegalArgumentException.class, () -> CharUtils.toIntValue(CHARACTER_A));
} }
@Test @Test
public void testToIntValue_Character_int() { public void testToIntValue_Character_int() {
assertEquals(0, CharUtils.toIntValue(new Character('0'), -1)); assertEquals(0, CharUtils.toIntValue(Character.valueOf('0'), -1));
assertEquals(3, CharUtils.toIntValue(new Character('3'), -1)); assertEquals(3, CharUtils.toIntValue(Character.valueOf('3'), -1));
assertEquals(-1, CharUtils.toIntValue(new Character('A'), -1)); assertEquals(-1, CharUtils.toIntValue(Character.valueOf('A'), -1));
assertEquals(-1, CharUtils.toIntValue(null, -1)); assertEquals(-1, CharUtils.toIntValue(null, -1));
} }

View File

@ -498,8 +498,8 @@ public class RandomStringUtilsTest {
final char o = orig.charAt(i); final char o = orig.charAt(i);
final char c = copy.charAt(i); final char c = copy.charAt(i);
assertEquals(o, c, assertEquals(o, c,
"differs at " + i + "(" + Integer.toHexString(new Character(o).hashCode()) + "," + "differs at " + i + "(" + Integer.toHexString(Character.valueOf(o).hashCode()) + "," +
Integer.toHexString(new Character(c).hashCode()) + ")"); Integer.toHexString(Character.valueOf(c).hashCode()) + ")");
} }
// compare length also // compare length also
assertEquals(orig.length(), copy.length()); assertEquals(orig.length(), copy.length());

View File

@ -235,8 +235,8 @@ public class StringEscapeUtilsTest {
assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("&#X80;&#X9F;"), "hex number unescape"); assertEquals("\u0080\u009F", StringEscapeUtils.unescapeHtml4("&#X80;&#X9F;"), "hex number unescape");
// Test all Character values: // Test all Character values:
for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) { for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
final Character c1 = new Character(i); final Character c1 = Character.valueOf(i);
final Character c2 = new Character((char) (i+1)); final Character c2 = Character.valueOf((char) (i+1));
final String expected = c1.toString() + c2.toString(); final String expected = c1.toString() + c2.toString();
final String escapedC1 = "&#x" + Integer.toHexString((c1.charValue())) + ";"; final String escapedC1 = "&#x" + Integer.toHexString((c1.charValue())) + ";";
final String escapedC2 = "&#x" + Integer.toHexString((c2.charValue())) + ";"; final String escapedC2 = "&#x" + Integer.toHexString((c2.charValue())) + ";";