Skip to content

Commit c88f11f

Browse files
committed
Avoid deprecation warnings on JDK 9 in spring-test
1 parent 1dbcd66 commit c88f11f

6 files changed

+44
-44
lines changed

spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringExtensionTestCase.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,7 +99,7 @@ void autowiredFields() {
9999
assertEquals(2, this.cats.size(), "Number of cats in context");
100100

101101
assertNotNull(this.enigma, "Enigma should have been injected via @Value by Spring");
102-
assertEquals(new Integer(42), this.enigma, "enigma");
102+
assertEquals(Integer.valueOf(42), this.enigma, "enigma");
103103
}
104104

105105
@Test
@@ -163,7 +163,7 @@ void valueParameterWithPrimitiveType(@Value("99") int num) {
163163
@Test
164164
void valueParameterFromPropertyPlaceholder(@Value("${enigma}") Integer enigmaParam) {
165165
assertNotNull(enigmaParam, "Enigma should have been injected via @Value by Spring");
166-
assertEquals(new Integer(42), enigmaParam, "enigma");
166+
assertEquals(Integer.valueOf(42), enigmaParam, "enigma");
167167
}
168168

169169
@Test

spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterAutowiredConstructorInjectionTestCase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -77,7 +77,7 @@ void beansInjected() {
7777
@Test
7878
void propertyPlaceholderInjected() {
7979
assertNotNull(this.enigma, "Enigma should have been injected via @Value by Spring");
80-
assertEquals(new Integer(42), this.enigma, "enigma");
80+
assertEquals(Integer.valueOf(42), this.enigma, "enigma");
8181
}
8282

8383
}

spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterConstructorInjectionTestCase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -80,7 +80,7 @@ void beansInjected() {
8080
@Test
8181
void propertyPlaceholderInjected() {
8282
assertNotNull(this.enigma, "Enigma should have been injected via @Value by Spring");
83-
assertEquals(new Integer(42), this.enigma, "enigma");
83+
assertEquals(Integer.valueOf(42), this.enigma, "enigma");
8484
}
8585

8686
@Test

spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,7 +74,7 @@ public void findSam() {
7474
assertNotNull("Should be able to find Sam", sam);
7575
DriversLicense driversLicense = sam.getDriversLicense();
7676
assertNotNull("Sam's driver's license should not be null", driversLicense);
77-
assertEquals("Verifying Sam's driver's license number", new Long(1234), driversLicense.getNumber());
77+
assertEquals("Verifying Sam's driver's license number", Long.valueOf(1234), driversLicense.getNumber());
7878
}
7979

8080
@Test

spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@
2525
import org.junit.rules.ExpectedException;
2626

2727
import org.mockito.BDDMockito;
28-
28+
import org.springframework.beans.BeanUtils;
2929
import org.springframework.core.annotation.AliasFor;
3030
import org.springframework.test.annotation.Commit;
3131
import org.springframework.test.annotation.Rollback;
@@ -76,7 +76,7 @@ private void assertBeforeTestMethodWithTransactionalTestMethod(Class<? extends I
7676
private void assertBeforeTestMethodWithTransactionalTestMethod(Class<? extends Invocable> clazz, boolean invokedInTx)
7777
throws Exception {
7878
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
79-
Invocable instance = clazz.newInstance();
79+
Invocable instance = BeanUtils.instantiateClass(clazz);
8080
given(testContext.getTestInstance()).willReturn(instance);
8181
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest"));
8282

@@ -89,7 +89,7 @@ private void assertBeforeTestMethodWithTransactionalTestMethod(Class<? extends I
8989
private void assertBeforeTestMethodWithNonTransactionalTestMethod(Class<? extends Invocable> clazz)
9090
throws Exception {
9191
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
92-
Invocable instance = clazz.newInstance();
92+
Invocable instance = BeanUtils.instantiateClass(clazz);
9393
given(testContext.getTestInstance()).willReturn(instance);
9494
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest"));
9595

@@ -106,7 +106,7 @@ private void assertAfterTestMethod(Class<? extends Invocable> clazz) throws Exce
106106

107107
private void assertAfterTestMethodWithTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception {
108108
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
109-
Invocable instance = clazz.newInstance();
109+
Invocable instance = BeanUtils.instantiateClass(clazz);
110110
given(testContext.getTestInstance()).willReturn(instance);
111111
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest"));
112112

@@ -122,7 +122,7 @@ private void assertAfterTestMethodWithTransactionalTestMethod(Class<? extends In
122122

123123
private void assertAfterTestMethodWithNonTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception {
124124
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
125-
Invocable instance = clazz.newInstance();
125+
Invocable instance = BeanUtils.instantiateClass(clazz);
126126
given(testContext.getTestInstance()).willReturn(instance);
127127
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest"));
128128

@@ -159,7 +159,7 @@ protected PlatformTransactionManager getTransactionManager(TestContext testConte
159159
Class<? extends Invocable> clazz = TransactionalDeclaredOnClassLocallyTestCase.class;
160160

161161
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
162-
Invocable instance = clazz.newInstance();
162+
Invocable instance = BeanUtils.instantiateClass(clazz);
163163
given(testContext.getTestInstance()).willReturn(instance);
164164
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest"));
165165

spring-test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@
4242
*/
4343
public class ReflectionTestUtilsTests {
4444

45-
private static final Float PI = new Float((float) 22 / 7);
45+
private static final Float PI = Float.valueOf((float) 22 / 7);
4646

4747
private final Person person = new PersonEntity();
4848

@@ -63,7 +63,7 @@ public void resetStaticFields() {
6363
public void setFieldWithNullTargetObject() throws Exception {
6464
exception.expect(IllegalArgumentException.class);
6565
exception.expectMessage(startsWith("Either targetObject or targetClass"));
66-
setField((Object) null, "id", new Long(99));
66+
setField((Object) null, "id", Long.valueOf(99));
6767
}
6868

6969
@Test
@@ -77,7 +77,7 @@ public void getFieldWithNullTargetObject() throws Exception {
7777
public void setFieldWithNullTargetClass() throws Exception {
7878
exception.expect(IllegalArgumentException.class);
7979
exception.expectMessage(startsWith("Either targetObject or targetClass"));
80-
setField((Class<?>) null, "id", new Long(99));
80+
setField((Class<?>) null, "id", Long.valueOf(99));
8181
}
8282

8383
@Test
@@ -91,21 +91,21 @@ public void getFieldWithNullTargetClass() throws Exception {
9191
public void setFieldWithNullNameAndNullType() throws Exception {
9292
exception.expect(IllegalArgumentException.class);
9393
exception.expectMessage(startsWith("Either name or type"));
94-
setField(person, null, new Long(99), null);
94+
setField(person, null, Long.valueOf(99), null);
9595
}
9696

9797
@Test
9898
public void setFieldWithBogusName() throws Exception {
9999
exception.expect(IllegalArgumentException.class);
100100
exception.expectMessage(startsWith("Could not find field 'bogus'"));
101-
setField(person, "bogus", new Long(99), long.class);
101+
setField(person, "bogus", Long.valueOf(99), long.class);
102102
}
103103

104104
@Test
105105
public void setFieldWithWrongType() throws Exception {
106106
exception.expect(IllegalArgumentException.class);
107107
exception.expectMessage(startsWith("Could not find field"));
108-
setField(person, "id", new Long(99), String.class);
108+
setField(person, "id", Long.valueOf(99), String.class);
109109
}
110110

111111
@Test
@@ -133,17 +133,17 @@ public void setFieldAndGetFieldViaCglibProxy() throws Exception {
133133

134134
private static void assertSetFieldAndGetFieldBehavior(Person person) {
135135
// Set reflectively
136-
setField(person, "id", new Long(99), long.class);
136+
setField(person, "id", Long.valueOf(99), long.class);
137137
setField(person, "name", "Tom");
138-
setField(person, "age", new Integer(42));
138+
setField(person, "age", Integer.valueOf(42));
139139
setField(person, "eyeColor", "blue", String.class);
140140
setField(person, "likesPets", Boolean.TRUE);
141141
setField(person, "favoriteNumber", PI, Number.class);
142142

143143
// Get reflectively
144-
assertEquals(new Long(99), getField(person, "id"));
144+
assertEquals(Long.valueOf(99), getField(person, "id"));
145145
assertEquals("Tom", getField(person, "name"));
146-
assertEquals(new Integer(42), getField(person, "age"));
146+
assertEquals(Integer.valueOf(42), getField(person, "age"));
147147
assertEquals("blue", getField(person, "eyeColor"));
148148
assertEquals(Boolean.TRUE, getField(person, "likesPets"));
149149
assertEquals(PI, getField(person, "favoriteNumber"));
@@ -247,33 +247,33 @@ public void getStaticFieldViaInstance() throws Exception {
247247

248248
@Test
249249
public void invokeSetterMethodAndInvokeGetterMethodWithExplicitMethodNames() throws Exception {
250-
invokeSetterMethod(person, "setId", new Long(1), long.class);
250+
invokeSetterMethod(person, "setId", Long.valueOf(1), long.class);
251251
invokeSetterMethod(person, "setName", "Jerry", String.class);
252-
invokeSetterMethod(person, "setAge", new Integer(33), int.class);
252+
invokeSetterMethod(person, "setAge", Integer.valueOf(33), int.class);
253253
invokeSetterMethod(person, "setEyeColor", "green", String.class);
254254
invokeSetterMethod(person, "setLikesPets", Boolean.FALSE, boolean.class);
255-
invokeSetterMethod(person, "setFavoriteNumber", new Integer(42), Number.class);
255+
invokeSetterMethod(person, "setFavoriteNumber", Integer.valueOf(42), Number.class);
256256

257257
assertEquals("ID (protected method in a superclass)", 1, person.getId());
258258
assertEquals("name (private method)", "Jerry", person.getName());
259259
assertEquals("age (protected method)", 33, person.getAge());
260260
assertEquals("eye color (package private method)", "green", person.getEyeColor());
261261
assertEquals("'likes pets' flag (protected method for a boolean)", false, person.likesPets());
262-
assertEquals("'favorite number' (protected method for a Number)", new Integer(42), person.getFavoriteNumber());
262+
assertEquals("'favorite number' (protected method for a Number)", Integer.valueOf(42), person.getFavoriteNumber());
263263

264-
assertEquals(new Long(1), invokeGetterMethod(person, "getId"));
264+
assertEquals(Long.valueOf(1), invokeGetterMethod(person, "getId"));
265265
assertEquals("Jerry", invokeGetterMethod(person, "getName"));
266-
assertEquals(new Integer(33), invokeGetterMethod(person, "getAge"));
266+
assertEquals(Integer.valueOf(33), invokeGetterMethod(person, "getAge"));
267267
assertEquals("green", invokeGetterMethod(person, "getEyeColor"));
268268
assertEquals(Boolean.FALSE, invokeGetterMethod(person, "likesPets"));
269-
assertEquals(new Integer(42), invokeGetterMethod(person, "getFavoriteNumber"));
269+
assertEquals(Integer.valueOf(42), invokeGetterMethod(person, "getFavoriteNumber"));
270270
}
271271

272272
@Test
273273
public void invokeSetterMethodAndInvokeGetterMethodWithJavaBeanPropertyNames() throws Exception {
274-
invokeSetterMethod(person, "id", new Long(99), long.class);
274+
invokeSetterMethod(person, "id", Long.valueOf(99), long.class);
275275
invokeSetterMethod(person, "name", "Tom");
276-
invokeSetterMethod(person, "age", new Integer(42));
276+
invokeSetterMethod(person, "age", Integer.valueOf(42));
277277
invokeSetterMethod(person, "eyeColor", "blue", String.class);
278278
invokeSetterMethod(person, "likesPets", Boolean.TRUE);
279279
invokeSetterMethod(person, "favoriteNumber", PI, Number.class);
@@ -285,9 +285,9 @@ public void invokeSetterMethodAndInvokeGetterMethodWithJavaBeanPropertyNames() t
285285
assertEquals("'likes pets' flag (protected method for a boolean)", true, person.likesPets());
286286
assertEquals("'favorite number' (protected method for a Number)", PI, person.getFavoriteNumber());
287287

288-
assertEquals(new Long(99), invokeGetterMethod(person, "id"));
288+
assertEquals(Long.valueOf(99), invokeGetterMethod(person, "id"));
289289
assertEquals("Tom", invokeGetterMethod(person, "name"));
290-
assertEquals(new Integer(42), invokeGetterMethod(person, "age"));
290+
assertEquals(Integer.valueOf(42), invokeGetterMethod(person, "age"));
291291
assertEquals("blue", invokeGetterMethod(person, "eyeColor"));
292292
assertEquals(Boolean.TRUE, invokeGetterMethod(person, "likesPets"));
293293
assertEquals(PI, invokeGetterMethod(person, "favoriteNumber"));
@@ -347,8 +347,8 @@ public void invokeMethodSimulatingLifecycleEvents() {
347347
assertNull("text", component.getText());
348348

349349
// Simulate autowiring a configuration method
350-
invokeMethod(component, "configure", new Integer(42), "enigma");
351-
assertEquals("number should have been configured", new Integer(42), component.getNumber());
350+
invokeMethod(component, "configure", Integer.valueOf(42), "enigma");
351+
assertEquals("number should have been configured", Integer.valueOf(42), component.getNumber());
352352
assertEquals("text should have been configured", "enigma", component.getText());
353353

354354
// Simulate @PostConstruct life-cycle event
@@ -379,14 +379,14 @@ public void invokeMethodWithIncompatibleArgumentTypes() {
379379
public void invokeMethodWithTooFewArguments() {
380380
exception.expect(IllegalStateException.class);
381381
exception.expectMessage(startsWith("Method not found"));
382-
invokeMethod(component, "configure", new Integer(42));
382+
invokeMethod(component, "configure", Integer.valueOf(42));
383383
}
384384

385385
@Test
386386
public void invokeMethodWithTooManyArguments() {
387387
exception.expect(IllegalStateException.class);
388388
exception.expectMessage(startsWith("Method not found"));
389-
invokeMethod(component, "configure", new Integer(42), "enigma", "baz", "quux");
389+
invokeMethod(component, "configure", Integer.valueOf(42), "enigma", "baz", "quux");
390390
}
391391

392392
@Test // SPR-14363
@@ -404,8 +404,8 @@ public void setFieldOnLegacyEntityWithSideEffectsInToString() {
404404

405405
@Test // SPR-14363
406406
public void invokeMethodOnLegacyEntityWithSideEffectsInToString() {
407-
invokeMethod(entity, "configure", new Integer(42), "enigma");
408-
assertEquals("number should have been configured", new Integer(42), entity.getNumber());
407+
invokeMethod(entity, "configure", Integer.valueOf(42), "enigma");
408+
assertEquals("number should have been configured", Integer.valueOf(42), entity.getNumber());
409409
assertEquals("text should have been configured", "enigma", entity.getText());
410410
}
411411

0 commit comments

Comments
 (0)