Avoid deprecation warnings on JDK 9 in spring-test

This commit is contained in:
Sam Brannen 2018-01-13 16:45:04 +01:00
parent 1dbcd66091
commit c88f11f958
6 changed files with 44 additions and 44 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -99,7 +99,7 @@ class SpringExtensionTestCase {
assertEquals(2, this.cats.size(), "Number of cats in context"); assertEquals(2, this.cats.size(), "Number of cats in context");
assertNotNull(this.enigma, "Enigma should have been injected via @Value by Spring"); assertNotNull(this.enigma, "Enigma should have been injected via @Value by Spring");
assertEquals(new Integer(42), this.enigma, "enigma"); assertEquals(Integer.valueOf(42), this.enigma, "enigma");
} }
@Test @Test
@ -163,7 +163,7 @@ class SpringExtensionTestCase {
@Test @Test
void valueParameterFromPropertyPlaceholder(@Value("${enigma}") Integer enigmaParam) { void valueParameterFromPropertyPlaceholder(@Value("${enigma}") Integer enigmaParam) {
assertNotNull(enigmaParam, "Enigma should have been injected via @Value by Spring"); assertNotNull(enigmaParam, "Enigma should have been injected via @Value by Spring");
assertEquals(new Integer(42), enigmaParam, "enigma"); assertEquals(Integer.valueOf(42), enigmaParam, "enigma");
} }
@Test @Test

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -77,7 +77,7 @@ class SpringJUnitJupiterAutowiredConstructorInjectionTestCase {
@Test @Test
void propertyPlaceholderInjected() { void propertyPlaceholderInjected() {
assertNotNull(this.enigma, "Enigma should have been injected via @Value by Spring"); assertNotNull(this.enigma, "Enigma should have been injected via @Value by Spring");
assertEquals(new Integer(42), this.enigma, "enigma"); assertEquals(Integer.valueOf(42), this.enigma, "enigma");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 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.
@ -80,7 +80,7 @@ class SpringJUnitJupiterConstructorInjectionTestCase {
@Test @Test
void propertyPlaceholderInjected() { void propertyPlaceholderInjected() {
assertNotNull(this.enigma, "Enigma should have been injected via @Value by Spring"); assertNotNull(this.enigma, "Enigma should have been injected via @Value by Spring");
assertEquals(new Integer(42), this.enigma, "enigma"); assertEquals(Integer.valueOf(42), this.enigma, "enigma");
} }
@Test @Test

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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.
@ -74,7 +74,7 @@ public class HibernateSessionFlushingTests extends AbstractTransactionalJUnit4Sp
assertNotNull("Should be able to find Sam", sam); assertNotNull("Should be able to find Sam", sam);
DriversLicense driversLicense = sam.getDriversLicense(); DriversLicense driversLicense = sam.getDriversLicense();
assertNotNull("Sam's driver's license should not be null", driversLicense); assertNotNull("Sam's driver's license should not be null", driversLicense);
assertEquals("Verifying Sam's driver's license number", new Long(1234), driversLicense.getNumber()); assertEquals("Verifying Sam's driver's license number", Long.valueOf(1234), driversLicense.getNumber());
} }
@Test @Test

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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.
@ -25,7 +25,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.mockito.BDDMockito; import org.mockito.BDDMockito;
import org.springframework.beans.BeanUtils;
import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.AliasFor;
import org.springframework.test.annotation.Commit; import org.springframework.test.annotation.Commit;
import org.springframework.test.annotation.Rollback; import org.springframework.test.annotation.Rollback;
@ -76,7 +76,7 @@ public class TransactionalTestExecutionListenerTests {
private void assertBeforeTestMethodWithTransactionalTestMethod(Class<? extends Invocable> clazz, boolean invokedInTx) private void assertBeforeTestMethodWithTransactionalTestMethod(Class<? extends Invocable> clazz, boolean invokedInTx)
throws Exception { throws Exception {
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
Invocable instance = clazz.newInstance(); Invocable instance = BeanUtils.instantiateClass(clazz);
given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestInstance()).willReturn(instance);
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest")); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest"));
@ -89,7 +89,7 @@ public class TransactionalTestExecutionListenerTests {
private void assertBeforeTestMethodWithNonTransactionalTestMethod(Class<? extends Invocable> clazz) private void assertBeforeTestMethodWithNonTransactionalTestMethod(Class<? extends Invocable> clazz)
throws Exception { throws Exception {
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
Invocable instance = clazz.newInstance(); Invocable instance = BeanUtils.instantiateClass(clazz);
given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestInstance()).willReturn(instance);
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest")); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest"));
@ -106,7 +106,7 @@ public class TransactionalTestExecutionListenerTests {
private void assertAfterTestMethodWithTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception { private void assertAfterTestMethodWithTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception {
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
Invocable instance = clazz.newInstance(); Invocable instance = BeanUtils.instantiateClass(clazz);
given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestInstance()).willReturn(instance);
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest")); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest"));
@ -122,7 +122,7 @@ public class TransactionalTestExecutionListenerTests {
private void assertAfterTestMethodWithNonTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception { private void assertAfterTestMethodWithNonTransactionalTestMethod(Class<? extends Invocable> clazz) throws Exception {
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
Invocable instance = clazz.newInstance(); Invocable instance = BeanUtils.instantiateClass(clazz);
given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestInstance()).willReturn(instance);
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest")); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest"));
@ -159,7 +159,7 @@ public class TransactionalTestExecutionListenerTests {
Class<? extends Invocable> clazz = TransactionalDeclaredOnClassLocallyTestCase.class; Class<? extends Invocable> clazz = TransactionalDeclaredOnClassLocallyTestCase.class;
BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz); BDDMockito.<Class<?>> given(testContext.getTestClass()).willReturn(clazz);
Invocable instance = clazz.newInstance(); Invocable instance = BeanUtils.instantiateClass(clazz);
given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestInstance()).willReturn(instance);
given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest")); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest"));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 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.
@ -42,7 +42,7 @@ import static org.springframework.test.util.ReflectionTestUtils.*;
*/ */
public class ReflectionTestUtilsTests { public class ReflectionTestUtilsTests {
private static final Float PI = new Float((float) 22 / 7); private static final Float PI = Float.valueOf((float) 22 / 7);
private final Person person = new PersonEntity(); private final Person person = new PersonEntity();
@ -63,7 +63,7 @@ public class ReflectionTestUtilsTests {
public void setFieldWithNullTargetObject() throws Exception { public void setFieldWithNullTargetObject() throws Exception {
exception.expect(IllegalArgumentException.class); exception.expect(IllegalArgumentException.class);
exception.expectMessage(startsWith("Either targetObject or targetClass")); exception.expectMessage(startsWith("Either targetObject or targetClass"));
setField((Object) null, "id", new Long(99)); setField((Object) null, "id", Long.valueOf(99));
} }
@Test @Test
@ -77,7 +77,7 @@ public class ReflectionTestUtilsTests {
public void setFieldWithNullTargetClass() throws Exception { public void setFieldWithNullTargetClass() throws Exception {
exception.expect(IllegalArgumentException.class); exception.expect(IllegalArgumentException.class);
exception.expectMessage(startsWith("Either targetObject or targetClass")); exception.expectMessage(startsWith("Either targetObject or targetClass"));
setField((Class<?>) null, "id", new Long(99)); setField((Class<?>) null, "id", Long.valueOf(99));
} }
@Test @Test
@ -91,21 +91,21 @@ public class ReflectionTestUtilsTests {
public void setFieldWithNullNameAndNullType() throws Exception { public void setFieldWithNullNameAndNullType() throws Exception {
exception.expect(IllegalArgumentException.class); exception.expect(IllegalArgumentException.class);
exception.expectMessage(startsWith("Either name or type")); exception.expectMessage(startsWith("Either name or type"));
setField(person, null, new Long(99), null); setField(person, null, Long.valueOf(99), null);
} }
@Test @Test
public void setFieldWithBogusName() throws Exception { public void setFieldWithBogusName() throws Exception {
exception.expect(IllegalArgumentException.class); exception.expect(IllegalArgumentException.class);
exception.expectMessage(startsWith("Could not find field 'bogus'")); exception.expectMessage(startsWith("Could not find field 'bogus'"));
setField(person, "bogus", new Long(99), long.class); setField(person, "bogus", Long.valueOf(99), long.class);
} }
@Test @Test
public void setFieldWithWrongType() throws Exception { public void setFieldWithWrongType() throws Exception {
exception.expect(IllegalArgumentException.class); exception.expect(IllegalArgumentException.class);
exception.expectMessage(startsWith("Could not find field")); exception.expectMessage(startsWith("Could not find field"));
setField(person, "id", new Long(99), String.class); setField(person, "id", Long.valueOf(99), String.class);
} }
@Test @Test
@ -133,17 +133,17 @@ public class ReflectionTestUtilsTests {
private static void assertSetFieldAndGetFieldBehavior(Person person) { private static void assertSetFieldAndGetFieldBehavior(Person person) {
// Set reflectively // Set reflectively
setField(person, "id", new Long(99), long.class); setField(person, "id", Long.valueOf(99), long.class);
setField(person, "name", "Tom"); setField(person, "name", "Tom");
setField(person, "age", new Integer(42)); setField(person, "age", Integer.valueOf(42));
setField(person, "eyeColor", "blue", String.class); setField(person, "eyeColor", "blue", String.class);
setField(person, "likesPets", Boolean.TRUE); setField(person, "likesPets", Boolean.TRUE);
setField(person, "favoriteNumber", PI, Number.class); setField(person, "favoriteNumber", PI, Number.class);
// Get reflectively // Get reflectively
assertEquals(new Long(99), getField(person, "id")); assertEquals(Long.valueOf(99), getField(person, "id"));
assertEquals("Tom", getField(person, "name")); assertEquals("Tom", getField(person, "name"));
assertEquals(new Integer(42), getField(person, "age")); assertEquals(Integer.valueOf(42), getField(person, "age"));
assertEquals("blue", getField(person, "eyeColor")); assertEquals("blue", getField(person, "eyeColor"));
assertEquals(Boolean.TRUE, getField(person, "likesPets")); assertEquals(Boolean.TRUE, getField(person, "likesPets"));
assertEquals(PI, getField(person, "favoriteNumber")); assertEquals(PI, getField(person, "favoriteNumber"));
@ -247,33 +247,33 @@ public class ReflectionTestUtilsTests {
@Test @Test
public void invokeSetterMethodAndInvokeGetterMethodWithExplicitMethodNames() throws Exception { public void invokeSetterMethodAndInvokeGetterMethodWithExplicitMethodNames() throws Exception {
invokeSetterMethod(person, "setId", new Long(1), long.class); invokeSetterMethod(person, "setId", Long.valueOf(1), long.class);
invokeSetterMethod(person, "setName", "Jerry", String.class); invokeSetterMethod(person, "setName", "Jerry", String.class);
invokeSetterMethod(person, "setAge", new Integer(33), int.class); invokeSetterMethod(person, "setAge", Integer.valueOf(33), int.class);
invokeSetterMethod(person, "setEyeColor", "green", String.class); invokeSetterMethod(person, "setEyeColor", "green", String.class);
invokeSetterMethod(person, "setLikesPets", Boolean.FALSE, boolean.class); invokeSetterMethod(person, "setLikesPets", Boolean.FALSE, boolean.class);
invokeSetterMethod(person, "setFavoriteNumber", new Integer(42), Number.class); invokeSetterMethod(person, "setFavoriteNumber", Integer.valueOf(42), Number.class);
assertEquals("ID (protected method in a superclass)", 1, person.getId()); assertEquals("ID (protected method in a superclass)", 1, person.getId());
assertEquals("name (private method)", "Jerry", person.getName()); assertEquals("name (private method)", "Jerry", person.getName());
assertEquals("age (protected method)", 33, person.getAge()); assertEquals("age (protected method)", 33, person.getAge());
assertEquals("eye color (package private method)", "green", person.getEyeColor()); assertEquals("eye color (package private method)", "green", person.getEyeColor());
assertEquals("'likes pets' flag (protected method for a boolean)", false, person.likesPets()); assertEquals("'likes pets' flag (protected method for a boolean)", false, person.likesPets());
assertEquals("'favorite number' (protected method for a Number)", new Integer(42), person.getFavoriteNumber()); assertEquals("'favorite number' (protected method for a Number)", Integer.valueOf(42), person.getFavoriteNumber());
assertEquals(new Long(1), invokeGetterMethod(person, "getId")); assertEquals(Long.valueOf(1), invokeGetterMethod(person, "getId"));
assertEquals("Jerry", invokeGetterMethod(person, "getName")); assertEquals("Jerry", invokeGetterMethod(person, "getName"));
assertEquals(new Integer(33), invokeGetterMethod(person, "getAge")); assertEquals(Integer.valueOf(33), invokeGetterMethod(person, "getAge"));
assertEquals("green", invokeGetterMethod(person, "getEyeColor")); assertEquals("green", invokeGetterMethod(person, "getEyeColor"));
assertEquals(Boolean.FALSE, invokeGetterMethod(person, "likesPets")); assertEquals(Boolean.FALSE, invokeGetterMethod(person, "likesPets"));
assertEquals(new Integer(42), invokeGetterMethod(person, "getFavoriteNumber")); assertEquals(Integer.valueOf(42), invokeGetterMethod(person, "getFavoriteNumber"));
} }
@Test @Test
public void invokeSetterMethodAndInvokeGetterMethodWithJavaBeanPropertyNames() throws Exception { public void invokeSetterMethodAndInvokeGetterMethodWithJavaBeanPropertyNames() throws Exception {
invokeSetterMethod(person, "id", new Long(99), long.class); invokeSetterMethod(person, "id", Long.valueOf(99), long.class);
invokeSetterMethod(person, "name", "Tom"); invokeSetterMethod(person, "name", "Tom");
invokeSetterMethod(person, "age", new Integer(42)); invokeSetterMethod(person, "age", Integer.valueOf(42));
invokeSetterMethod(person, "eyeColor", "blue", String.class); invokeSetterMethod(person, "eyeColor", "blue", String.class);
invokeSetterMethod(person, "likesPets", Boolean.TRUE); invokeSetterMethod(person, "likesPets", Boolean.TRUE);
invokeSetterMethod(person, "favoriteNumber", PI, Number.class); invokeSetterMethod(person, "favoriteNumber", PI, Number.class);
@ -285,9 +285,9 @@ public class ReflectionTestUtilsTests {
assertEquals("'likes pets' flag (protected method for a boolean)", true, person.likesPets()); assertEquals("'likes pets' flag (protected method for a boolean)", true, person.likesPets());
assertEquals("'favorite number' (protected method for a Number)", PI, person.getFavoriteNumber()); assertEquals("'favorite number' (protected method for a Number)", PI, person.getFavoriteNumber());
assertEquals(new Long(99), invokeGetterMethod(person, "id")); assertEquals(Long.valueOf(99), invokeGetterMethod(person, "id"));
assertEquals("Tom", invokeGetterMethod(person, "name")); assertEquals("Tom", invokeGetterMethod(person, "name"));
assertEquals(new Integer(42), invokeGetterMethod(person, "age")); assertEquals(Integer.valueOf(42), invokeGetterMethod(person, "age"));
assertEquals("blue", invokeGetterMethod(person, "eyeColor")); assertEquals("blue", invokeGetterMethod(person, "eyeColor"));
assertEquals(Boolean.TRUE, invokeGetterMethod(person, "likesPets")); assertEquals(Boolean.TRUE, invokeGetterMethod(person, "likesPets"));
assertEquals(PI, invokeGetterMethod(person, "favoriteNumber")); assertEquals(PI, invokeGetterMethod(person, "favoriteNumber"));
@ -347,8 +347,8 @@ public class ReflectionTestUtilsTests {
assertNull("text", component.getText()); assertNull("text", component.getText());
// Simulate autowiring a configuration method // Simulate autowiring a configuration method
invokeMethod(component, "configure", new Integer(42), "enigma"); invokeMethod(component, "configure", Integer.valueOf(42), "enigma");
assertEquals("number should have been configured", new Integer(42), component.getNumber()); assertEquals("number should have been configured", Integer.valueOf(42), component.getNumber());
assertEquals("text should have been configured", "enigma", component.getText()); assertEquals("text should have been configured", "enigma", component.getText());
// Simulate @PostConstruct life-cycle event // Simulate @PostConstruct life-cycle event
@ -379,14 +379,14 @@ public class ReflectionTestUtilsTests {
public void invokeMethodWithTooFewArguments() { public void invokeMethodWithTooFewArguments() {
exception.expect(IllegalStateException.class); exception.expect(IllegalStateException.class);
exception.expectMessage(startsWith("Method not found")); exception.expectMessage(startsWith("Method not found"));
invokeMethod(component, "configure", new Integer(42)); invokeMethod(component, "configure", Integer.valueOf(42));
} }
@Test @Test
public void invokeMethodWithTooManyArguments() { public void invokeMethodWithTooManyArguments() {
exception.expect(IllegalStateException.class); exception.expect(IllegalStateException.class);
exception.expectMessage(startsWith("Method not found")); exception.expectMessage(startsWith("Method not found"));
invokeMethod(component, "configure", new Integer(42), "enigma", "baz", "quux"); invokeMethod(component, "configure", Integer.valueOf(42), "enigma", "baz", "quux");
} }
@Test // SPR-14363 @Test // SPR-14363
@ -404,8 +404,8 @@ public class ReflectionTestUtilsTests {
@Test // SPR-14363 @Test // SPR-14363
public void invokeMethodOnLegacyEntityWithSideEffectsInToString() { public void invokeMethodOnLegacyEntityWithSideEffectsInToString() {
invokeMethod(entity, "configure", new Integer(42), "enigma"); invokeMethod(entity, "configure", Integer.valueOf(42), "enigma");
assertEquals("number should have been configured", new Integer(42), entity.getNumber()); assertEquals("number should have been configured", Integer.valueOf(42), entity.getNumber());
assertEquals("text should have been configured", "enigma", entity.getText()); assertEquals("text should have been configured", "enigma", entity.getText());
} }