Browse Source

Avoid use of deprecated Character/Double constructors in tests

pull/29935/head
Sam Brannen 3 years ago
parent
commit
109b00d24d
  1. 12
      spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java
  2. 16
      spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java
  3. 4
      spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java

12
spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -502,7 +502,7 @@ class CustomEditorTests { @@ -502,7 +502,7 @@ class CustomEditorTests {
CharBean cb = new CharBean();
BeanWrapper bw = new BeanWrapperImpl(cb);
bw.setPropertyValue("myChar", new Character('c'));
bw.setPropertyValue("myChar", 'c');
assertThat(cb.getMyChar()).isEqualTo('c');
bw.setPropertyValue("myChar", "c");
@ -526,16 +526,16 @@ class CustomEditorTests { @@ -526,16 +526,16 @@ class CustomEditorTests {
bw.registerCustomEditor(Character.class, new CharacterEditor(true));
bw.setPropertyValue("myCharacter", 'c');
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c'));
assertThat(cb.getMyCharacter()).isEqualTo('c');
bw.setPropertyValue("myCharacter", "c");
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c'));
assertThat(cb.getMyCharacter()).isEqualTo('c');
bw.setPropertyValue("myCharacter", "\u0041");
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('A'));
assertThat(cb.getMyCharacter()).isEqualTo('A');
bw.setPropertyValue("myCharacter", " ");
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf(' '));
assertThat(cb.getMyCharacter()).isEqualTo(' ');
bw.setPropertyValue("myCharacter", "");
assertThat(cb.getMyCharacter()).isNull();

16
spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -251,32 +251,28 @@ class ObjectUtilsTests { @@ -251,32 +251,28 @@ class ObjectUtilsTests {
@Deprecated
void hashCodeWithDouble() {
double dbl = 9830.43;
int expected = (new Double(dbl)).hashCode();
assertThat(ObjectUtils.hashCode(dbl)).isEqualTo(expected);
assertThat(ObjectUtils.hashCode(dbl)).isEqualTo(Double.hashCode(dbl));
}
@Test
@Deprecated
void hashCodeWithFloat() {
float flt = 34.8f;
int expected = (Float.valueOf(flt)).hashCode();
assertThat(ObjectUtils.hashCode(flt)).isEqualTo(expected);
assertThat(ObjectUtils.hashCode(flt)).isEqualTo(Float.hashCode(flt));
}
@Test
@Deprecated
void hashCodeWithLong() {
long lng = 883L;
int expected = (Long.valueOf(lng)).hashCode();
assertThat(ObjectUtils.hashCode(lng)).isEqualTo(expected);
assertThat(ObjectUtils.hashCode(lng)).isEqualTo(Long.hashCode(lng));
}
@Test
void identityToString() {
Object obj = new Object();
String expected = obj.getClass().getName() + "@" + ObjectUtils.getIdentityHexString(obj);
String actual = ObjectUtils.identityToString(obj);
assertThat(actual).isEqualTo(expected);
assertThat(ObjectUtils.identityToString(obj)).isEqualTo(expected);
}
@Test
@ -732,7 +728,7 @@ class ObjectUtilsTests { @@ -732,7 +728,7 @@ class ObjectUtilsTests {
@Test
void nullSafeToStringWithObjectArray() {
Object[] array = {"Han", Long.valueOf(43)};
Object[] array = {"Han", 43};
assertThat(ObjectUtils.nullSafeToString(array)).isEqualTo("{Han, 43}");
}

4
spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -153,7 +153,7 @@ public class ServletRequestAttributesTests { @@ -153,7 +153,7 @@ public class ServletRequestAttributesTests {
@Test
public void skipImmutableCharacter() {
doSkipImmutableValue(new Character('x'));
doSkipImmutableValue('x');
}
@Test

Loading…
Cancel
Save