diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringExtensionTestCase.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringExtensionTestCase.java index 01ce094d3ed..7a4c5a94ee4 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringExtensionTestCase.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringExtensionTestCase.java @@ -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"); * 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"); 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 @@ -163,7 +163,7 @@ class SpringExtensionTestCase { @Test void valueParameterFromPropertyPlaceholder(@Value("${enigma}") Integer enigmaParam) { assertNotNull(enigmaParam, "Enigma should have been injected via @Value by Spring"); - assertEquals(new Integer(42), enigmaParam, "enigma"); + assertEquals(Integer.valueOf(42), enigmaParam, "enigma"); } @Test diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterAutowiredConstructorInjectionTestCase.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterAutowiredConstructorInjectionTestCase.java index 68913689ab4..79cc2c34ae3 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterAutowiredConstructorInjectionTestCase.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterAutowiredConstructorInjectionTestCase.java @@ -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"); * you may not use this file except in compliance with the License. @@ -77,7 +77,7 @@ class SpringJUnitJupiterAutowiredConstructorInjectionTestCase { @Test void propertyPlaceholderInjected() { 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"); } } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterConstructorInjectionTestCase.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterConstructorInjectionTestCase.java index 1dd233fe4c1..da1e6974360 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterConstructorInjectionTestCase.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/SpringJUnitJupiterConstructorInjectionTestCase.java @@ -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"); * you may not use this file except in compliance with the License. @@ -80,7 +80,7 @@ class SpringJUnitJupiterConstructorInjectionTestCase { @Test void propertyPlaceholderInjected() { 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 diff --git a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java b/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java index 493b558b03f..f6d688f01fc 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit4/orm/HibernateSessionFlushingTests.java @@ -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"); * 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); DriversLicense driversLicense = sam.getDriversLicense(); 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 diff --git a/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java b/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java index bc408ef73de..8a67cec45e8 100644 --- a/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/transaction/TransactionalTestExecutionListenerTests.java @@ -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"); * 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.mockito.BDDMockito; - +import org.springframework.beans.BeanUtils; import org.springframework.core.annotation.AliasFor; import org.springframework.test.annotation.Commit; import org.springframework.test.annotation.Rollback; @@ -76,7 +76,7 @@ public class TransactionalTestExecutionListenerTests { private void assertBeforeTestMethodWithTransactionalTestMethod(Class clazz, boolean invokedInTx) throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); - Invocable instance = clazz.newInstance(); + Invocable instance = BeanUtils.instantiateClass(clazz); given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest")); @@ -89,7 +89,7 @@ public class TransactionalTestExecutionListenerTests { private void assertBeforeTestMethodWithNonTransactionalTestMethod(Class clazz) throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); - Invocable instance = clazz.newInstance(); + Invocable instance = BeanUtils.instantiateClass(clazz); given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest")); @@ -106,7 +106,7 @@ public class TransactionalTestExecutionListenerTests { private void assertAfterTestMethodWithTransactionalTestMethod(Class clazz) throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); - Invocable instance = clazz.newInstance(); + Invocable instance = BeanUtils.instantiateClass(clazz); given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest")); @@ -122,7 +122,7 @@ public class TransactionalTestExecutionListenerTests { private void assertAfterTestMethodWithNonTransactionalTestMethod(Class clazz) throws Exception { BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); - Invocable instance = clazz.newInstance(); + Invocable instance = BeanUtils.instantiateClass(clazz); given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("nonTransactionalTest")); @@ -159,7 +159,7 @@ public class TransactionalTestExecutionListenerTests { Class clazz = TransactionalDeclaredOnClassLocallyTestCase.class; BDDMockito.> given(testContext.getTestClass()).willReturn(clazz); - Invocable instance = clazz.newInstance(); + Invocable instance = BeanUtils.instantiateClass(clazz); given(testContext.getTestInstance()).willReturn(instance); given(testContext.getTestMethod()).willReturn(clazz.getDeclaredMethod("transactionalTest")); diff --git a/spring-test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java b/spring-test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java index 3ea39f9b8b4..ae168ae94ba 100644 --- a/spring-test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/ReflectionTestUtilsTests.java @@ -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"); * 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 { - 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(); @@ -63,7 +63,7 @@ public class ReflectionTestUtilsTests { public void setFieldWithNullTargetObject() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Either targetObject or targetClass")); - setField((Object) null, "id", new Long(99)); + setField((Object) null, "id", Long.valueOf(99)); } @Test @@ -77,7 +77,7 @@ public class ReflectionTestUtilsTests { public void setFieldWithNullTargetClass() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Either targetObject or targetClass")); - setField((Class) null, "id", new Long(99)); + setField((Class) null, "id", Long.valueOf(99)); } @Test @@ -91,21 +91,21 @@ public class ReflectionTestUtilsTests { public void setFieldWithNullNameAndNullType() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Either name or type")); - setField(person, null, new Long(99), null); + setField(person, null, Long.valueOf(99), null); } @Test public void setFieldWithBogusName() throws Exception { exception.expect(IllegalArgumentException.class); 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 public void setFieldWithWrongType() throws Exception { exception.expect(IllegalArgumentException.class); exception.expectMessage(startsWith("Could not find field")); - setField(person, "id", new Long(99), String.class); + setField(person, "id", Long.valueOf(99), String.class); } @Test @@ -133,17 +133,17 @@ public class ReflectionTestUtilsTests { private static void assertSetFieldAndGetFieldBehavior(Person person) { // Set reflectively - setField(person, "id", new Long(99), long.class); + setField(person, "id", Long.valueOf(99), long.class); setField(person, "name", "Tom"); - setField(person, "age", new Integer(42)); + setField(person, "age", Integer.valueOf(42)); setField(person, "eyeColor", "blue", String.class); setField(person, "likesPets", Boolean.TRUE); setField(person, "favoriteNumber", PI, Number.class); // Get reflectively - assertEquals(new Long(99), getField(person, "id")); + assertEquals(Long.valueOf(99), getField(person, "id")); 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(Boolean.TRUE, getField(person, "likesPets")); assertEquals(PI, getField(person, "favoriteNumber")); @@ -247,33 +247,33 @@ public class ReflectionTestUtilsTests { @Test 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, "setAge", new Integer(33), int.class); + invokeSetterMethod(person, "setAge", Integer.valueOf(33), int.class); invokeSetterMethod(person, "setEyeColor", "green", String.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("name (private method)", "Jerry", person.getName()); assertEquals("age (protected method)", 33, person.getAge()); assertEquals("eye color (package private method)", "green", person.getEyeColor()); 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(new Integer(33), invokeGetterMethod(person, "getAge")); + assertEquals(Integer.valueOf(33), invokeGetterMethod(person, "getAge")); assertEquals("green", invokeGetterMethod(person, "getEyeColor")); assertEquals(Boolean.FALSE, invokeGetterMethod(person, "likesPets")); - assertEquals(new Integer(42), invokeGetterMethod(person, "getFavoriteNumber")); + assertEquals(Integer.valueOf(42), invokeGetterMethod(person, "getFavoriteNumber")); } @Test 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, "age", new Integer(42)); + invokeSetterMethod(person, "age", Integer.valueOf(42)); invokeSetterMethod(person, "eyeColor", "blue", String.class); invokeSetterMethod(person, "likesPets", Boolean.TRUE); 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("'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(new Integer(42), invokeGetterMethod(person, "age")); + assertEquals(Integer.valueOf(42), invokeGetterMethod(person, "age")); assertEquals("blue", invokeGetterMethod(person, "eyeColor")); assertEquals(Boolean.TRUE, invokeGetterMethod(person, "likesPets")); assertEquals(PI, invokeGetterMethod(person, "favoriteNumber")); @@ -347,8 +347,8 @@ public class ReflectionTestUtilsTests { assertNull("text", component.getText()); // Simulate autowiring a configuration method - invokeMethod(component, "configure", new Integer(42), "enigma"); - assertEquals("number should have been configured", new Integer(42), component.getNumber()); + invokeMethod(component, "configure", Integer.valueOf(42), "enigma"); + assertEquals("number should have been configured", Integer.valueOf(42), component.getNumber()); assertEquals("text should have been configured", "enigma", component.getText()); // Simulate @PostConstruct life-cycle event @@ -379,14 +379,14 @@ public class ReflectionTestUtilsTests { public void invokeMethodWithTooFewArguments() { exception.expect(IllegalStateException.class); exception.expectMessage(startsWith("Method not found")); - invokeMethod(component, "configure", new Integer(42)); + invokeMethod(component, "configure", Integer.valueOf(42)); } @Test public void invokeMethodWithTooManyArguments() { exception.expect(IllegalStateException.class); 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 @@ -404,8 +404,8 @@ public class ReflectionTestUtilsTests { @Test // SPR-14363 public void invokeMethodOnLegacyEntityWithSideEffectsInToString() { - invokeMethod(entity, "configure", new Integer(42), "enigma"); - assertEquals("number should have been configured", new Integer(42), entity.getNumber()); + invokeMethod(entity, "configure", Integer.valueOf(42), "enigma"); + assertEquals("number should have been configured", Integer.valueOf(42), entity.getNumber()); assertEquals("text should have been configured", "enigma", entity.getText()); }