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 @@
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -502,7 +502,7 @@ class CustomEditorTests {
CharBean cb = new CharBean(); CharBean cb = new CharBean();
BeanWrapper bw = new BeanWrapperImpl(cb); BeanWrapper bw = new BeanWrapperImpl(cb);
bw.setPropertyValue("myChar", new Character('c')); bw.setPropertyValue("myChar", 'c');
assertThat(cb.getMyChar()).isEqualTo('c'); assertThat(cb.getMyChar()).isEqualTo('c');
bw.setPropertyValue("myChar", "c"); bw.setPropertyValue("myChar", "c");
@ -526,16 +526,16 @@ class CustomEditorTests {
bw.registerCustomEditor(Character.class, new CharacterEditor(true)); bw.registerCustomEditor(Character.class, new CharacterEditor(true));
bw.setPropertyValue("myCharacter", 'c'); bw.setPropertyValue("myCharacter", 'c');
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c')); assertThat(cb.getMyCharacter()).isEqualTo('c');
bw.setPropertyValue("myCharacter", "c"); bw.setPropertyValue("myCharacter", "c");
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c')); assertThat(cb.getMyCharacter()).isEqualTo('c');
bw.setPropertyValue("myCharacter", "\u0041"); bw.setPropertyValue("myCharacter", "\u0041");
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('A')); assertThat(cb.getMyCharacter()).isEqualTo('A');
bw.setPropertyValue("myCharacter", " "); bw.setPropertyValue("myCharacter", " ");
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf(' ')); assertThat(cb.getMyCharacter()).isEqualTo(' ');
bw.setPropertyValue("myCharacter", ""); bw.setPropertyValue("myCharacter", "");
assertThat(cb.getMyCharacter()).isNull(); assertThat(cb.getMyCharacter()).isNull();

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

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -251,32 +251,28 @@ class ObjectUtilsTests {
@Deprecated @Deprecated
void hashCodeWithDouble() { void hashCodeWithDouble() {
double dbl = 9830.43; double dbl = 9830.43;
int expected = (new Double(dbl)).hashCode(); assertThat(ObjectUtils.hashCode(dbl)).isEqualTo(Double.hashCode(dbl));
assertThat(ObjectUtils.hashCode(dbl)).isEqualTo(expected);
} }
@Test @Test
@Deprecated @Deprecated
void hashCodeWithFloat() { void hashCodeWithFloat() {
float flt = 34.8f; float flt = 34.8f;
int expected = (Float.valueOf(flt)).hashCode(); assertThat(ObjectUtils.hashCode(flt)).isEqualTo(Float.hashCode(flt));
assertThat(ObjectUtils.hashCode(flt)).isEqualTo(expected);
} }
@Test @Test
@Deprecated @Deprecated
void hashCodeWithLong() { void hashCodeWithLong() {
long lng = 883L; long lng = 883L;
int expected = (Long.valueOf(lng)).hashCode(); assertThat(ObjectUtils.hashCode(lng)).isEqualTo(Long.hashCode(lng));
assertThat(ObjectUtils.hashCode(lng)).isEqualTo(expected);
} }
@Test @Test
void identityToString() { void identityToString() {
Object obj = new Object(); Object obj = new Object();
String expected = obj.getClass().getName() + "@" + ObjectUtils.getIdentityHexString(obj); String expected = obj.getClass().getName() + "@" + ObjectUtils.getIdentityHexString(obj);
String actual = ObjectUtils.identityToString(obj); assertThat(ObjectUtils.identityToString(obj)).isEqualTo(expected);
assertThat(actual).isEqualTo(expected);
} }
@Test @Test
@ -732,7 +728,7 @@ class ObjectUtilsTests {
@Test @Test
void nullSafeToStringWithObjectArray() { void nullSafeToStringWithObjectArray() {
Object[] array = {"Han", Long.valueOf(43)}; Object[] array = {"Han", 43};
assertThat(ObjectUtils.nullSafeToString(array)).isEqualTo("{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 @@
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -153,7 +153,7 @@ public class ServletRequestAttributesTests {
@Test @Test
public void skipImmutableCharacter() { public void skipImmutableCharacter() {
doSkipImmutableValue(new Character('x')); doSkipImmutableValue('x');
} }
@Test @Test

Loading…
Cancel
Save