diff --git a/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java b/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java index d15556e4663..dd50e8c117c 100644 --- a/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -294,7 +294,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setNestedPropertyPolymorphic() throws Exception { + void setNestedPropertyPolymorphic() { ITestBean target = new TestBean("rod", 31); ITestBean kerry = new Employee(); @@ -316,7 +316,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setAnotherNestedProperty() throws Exception { + void setAnotherNestedProperty() { ITestBean target = new TestBean("rod", 31); ITestBean kerry = new TestBean("kerry", 0); @@ -386,7 +386,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setAnotherPropertyIntermediatePropertyIsNull() throws Exception { + void setAnotherPropertyIntermediatePropertyIsNull() { ITestBean target = new TestBean("rod", 31); AbstractPropertyAccessor accessor = createAccessor(target); assertThatExceptionOfType(NullValueInNestedPathException.class).isThrownBy(() -> @@ -406,7 +406,6 @@ abstract class AbstractPropertyAccessorTests { } @Test - @SuppressWarnings("unchecked") void setPropertyIntermediateListIsNullWithAutoGrow() { Foo target = new Foo(); AbstractPropertyAccessor accessor = createAccessor(target); @@ -553,7 +552,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setStringPropertyWithCustomEditor() throws Exception { + void setStringPropertyWithCustomEditor() { TestBean target = new TestBean(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.registerCustomEditor(String.class, "name", new PropertyEditorSupport() { @@ -724,7 +723,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setPropertiesProperty() throws Exception { + void setPropertiesProperty() { PropsTester target = new PropsTester(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.setPropertyValue("name", "ptest"); @@ -742,7 +741,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setStringArrayProperty() throws Exception { + void setStringArrayProperty() { PropsTester target = new PropsTester(); AbstractPropertyAccessor accessor = createAccessor(target); @@ -767,7 +766,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setStringArrayPropertyWithCustomStringEditor() throws Exception { + void setStringArrayPropertyWithCustomStringEditor() { PropsTester target = new PropsTester(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.registerCustomEditor(String.class, "stringArray", new PropertyEditorSupport() { @@ -796,7 +795,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setStringArrayPropertyWithStringSplitting() throws Exception { + void setStringArrayPropertyWithStringSplitting() { PropsTester target = new PropsTester(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.useConfigValueEditors(); @@ -805,7 +804,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setStringArrayPropertyWithCustomStringDelimiter() throws Exception { + void setStringArrayPropertyWithCustomStringDelimiter() { PropsTester target = new PropsTester(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.registerCustomEditor(String[].class, "stringArray", new StringArrayPropertyEditor("-")); @@ -814,7 +813,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setStringArrayWithAutoGrow() throws Exception { + void setStringArrayWithAutoGrow() { StringArrayBean target = new StringArrayBean(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.setAutoGrowNestedPaths(true); @@ -888,7 +887,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setIntArrayPropertyWithStringSplitting() throws Exception { + void setIntArrayPropertyWithStringSplitting() { PropsTester target = new PropsTester(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.useConfigValueEditors(); @@ -943,7 +942,7 @@ abstract class AbstractPropertyAccessorTests { } @Test - void setPrimitiveArrayPropertyWithAutoGrow() throws Exception { + void setPrimitiveArrayPropertyWithAutoGrow() { PrimitiveArrayBean target = new PrimitiveArrayBean(); AbstractPropertyAccessor accessor = createAccessor(target); accessor.setAutoGrowNestedPaths(true); diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperAutoGrowingTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperAutoGrowingTests.java index 8d702dbb7be..f7e41b262f6 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperAutoGrowingTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperAutoGrowingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Juergen Hoeller * @author Sam Brannen */ -public class BeanWrapperAutoGrowingTests { +class BeanWrapperAutoGrowingTests { private final Bean bean = new Bean(); @@ -38,43 +38,43 @@ public class BeanWrapperAutoGrowingTests { @BeforeEach - public void setup() { + void setup() { wrapper.setAutoGrowNestedPaths(true); } @Test - public void getPropertyValueNullValueInNestedPath() { + void getPropertyValueNullValueInNestedPath() { assertThat(wrapper.getPropertyValue("nested.prop")).isNull(); } @Test - public void setPropertyValueNullValueInNestedPath() { + void setPropertyValueNullValueInNestedPath() { wrapper.setPropertyValue("nested.prop", "test"); assertThat(bean.getNested().getProp()).isEqualTo("test"); } @Test - public void getPropertyValueNullValueInNestedPathNoDefaultConstructor() { + void getPropertyValueNullValueInNestedPathNoDefaultConstructor() { assertThatExceptionOfType(NullValueInNestedPathException.class).isThrownBy(() -> wrapper.getPropertyValue("nestedNoConstructor.prop")); } @Test - public void getPropertyValueAutoGrowArray() { + void getPropertyValueAutoGrowArray() { assertNotNull(wrapper.getPropertyValue("array[0]")); assertThat(bean.getArray()).hasSize(1); assertThat(bean.getArray()[0]).isInstanceOf(Bean.class); } @Test - public void setPropertyValueAutoGrowArray() { + void setPropertyValueAutoGrowArray() { wrapper.setPropertyValue("array[0].prop", "test"); assertThat(bean.getArray()[0].getProp()).isEqualTo("test"); } @Test - public void getPropertyValueAutoGrowArrayBySeveralElements() { + void getPropertyValueAutoGrowArrayBySeveralElements() { assertNotNull(wrapper.getPropertyValue("array[4]")); assertThat(bean.getArray()).hasSize(5); assertThat(bean.getArray()[0]).isInstanceOf(Bean.class); @@ -89,21 +89,21 @@ public class BeanWrapperAutoGrowingTests { } @Test - public void getPropertyValueAutoGrow2dArray() { + void getPropertyValueAutoGrow2dArray() { assertThat(wrapper.getPropertyValue("multiArray[0][0]")).isNotNull(); assertThat(bean.getMultiArray()[0]).hasSize(1); assertThat(bean.getMultiArray()[0][0]).isInstanceOf(Bean.class); } @Test - public void getPropertyValueAutoGrow3dArray() { + void getPropertyValueAutoGrow3dArray() { assertThat(wrapper.getPropertyValue("threeDimensionalArray[1][2][3]")).isNotNull(); assertThat(bean.getThreeDimensionalArray()[1]).hasNumberOfRows(3); assertThat(bean.getThreeDimensionalArray()[1][2][3]).isInstanceOf(Bean.class); } @Test - public void setPropertyValueAutoGrow2dArray() { + void setPropertyValueAutoGrow2dArray() { Bean newBean = new Bean(); newBean.setProp("enigma"); wrapper.setPropertyValue("multiArray[2][3]", newBean); @@ -113,7 +113,7 @@ public class BeanWrapperAutoGrowingTests { } @Test - public void setPropertyValueAutoGrow3dArray() { + void setPropertyValueAutoGrow3dArray() { Bean newBean = new Bean(); newBean.setProp("enigma"); wrapper.setPropertyValue("threeDimensionalArray[2][3][4]", newBean); @@ -123,20 +123,20 @@ public class BeanWrapperAutoGrowingTests { } @Test - public void getPropertyValueAutoGrowList() { + void getPropertyValueAutoGrowList() { assertNotNull(wrapper.getPropertyValue("list[0]")); assertThat(bean.getList()).hasSize(1); assertThat(bean.getList()).element(0).isInstanceOf(Bean.class); } @Test - public void setPropertyValueAutoGrowList() { + void setPropertyValueAutoGrowList() { wrapper.setPropertyValue("list[0].prop", "test"); assertThat(bean.getList().get(0).getProp()).isEqualTo("test"); } @Test - public void getPropertyValueAutoGrowListBySeveralElements() { + void getPropertyValueAutoGrowListBySeveralElements() { assertNotNull(wrapper.getPropertyValue("list[4]")); assertThat(bean.getList()).hasSize(5); assertThat(bean.getList()).element(0).isInstanceOf(Bean.class); @@ -151,7 +151,7 @@ public class BeanWrapperAutoGrowingTests { } @Test - public void getPropertyValueAutoGrowListFailsAgainstLimit() { + void getPropertyValueAutoGrowListFailsAgainstLimit() { wrapper.setAutoGrowCollectionLimit(2); assertThatExceptionOfType(InvalidPropertyException.class).isThrownBy(() -> wrapper.getPropertyValue("list[4]")) @@ -159,26 +159,26 @@ public class BeanWrapperAutoGrowingTests { } @Test - public void getPropertyValueAutoGrowMultiDimensionalList() { + void getPropertyValueAutoGrowMultiDimensionalList() { assertNotNull(wrapper.getPropertyValue("multiList[0][0]")); assertThat(bean.getMultiList()).element(0).asList().hasSize(1); assertThat(bean.getMultiList().get(0)).element(0).isInstanceOf(Bean.class); } @Test - public void getPropertyValueAutoGrowListNotParameterized() { + void getPropertyValueAutoGrowListNotParameterized() { assertThatExceptionOfType(InvalidPropertyException.class).isThrownBy(() -> wrapper.getPropertyValue("listNotParameterized[0]")); } @Test - public void setPropertyValueAutoGrowMap() { + void setPropertyValueAutoGrowMap() { wrapper.setPropertyValue("map[A]", new Bean()); assertThat(bean.getMap().get("A")).isInstanceOf(Bean.class); } @Test - public void setNestedPropertyValueAutoGrowMap() { + void setNestedPropertyValueAutoGrowMap() { wrapper.setPropertyValue("map[A].nested", new Bean()); assertThat(bean.getMap().get("A").getNested()).isInstanceOf(Bean.class); } diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperEnumTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperEnumTests.java index 76233364224..21c07a6d768 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperEnumTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperEnumTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @author Chris Beams */ -public class BeanWrapperEnumTests { +class BeanWrapperEnumTests { @Test - public void testCustomEnum() { + void testCustomEnum() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnum", "VALUE_1"); @@ -42,7 +42,7 @@ public class BeanWrapperEnumTests { } @Test - public void testCustomEnumWithNull() { + void testCustomEnumWithNull() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnum", null); @@ -50,7 +50,7 @@ public class BeanWrapperEnumTests { } @Test - public void testCustomEnumWithEmptyString() { + void testCustomEnumWithEmptyString() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnum", ""); @@ -58,7 +58,7 @@ public class BeanWrapperEnumTests { } @Test - public void testCustomEnumArrayWithSingleValue() { + void testCustomEnumArrayWithSingleValue() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnumArray", "VALUE_1"); @@ -67,7 +67,7 @@ public class BeanWrapperEnumTests { } @Test - public void testCustomEnumArrayWithMultipleValues() { + void testCustomEnumArrayWithMultipleValues() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnumArray", new String[] {"VALUE_1", "VALUE_2"}); @@ -77,7 +77,7 @@ public class BeanWrapperEnumTests { } @Test - public void testCustomEnumArrayWithMultipleValuesAsCsv() { + void testCustomEnumArrayWithMultipleValuesAsCsv() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnumArray", "VALUE_1,VALUE_2"); @@ -87,7 +87,7 @@ public class BeanWrapperEnumTests { } @Test - public void testCustomEnumSetWithSingleValue() { + void testCustomEnumSetWithSingleValue() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnumSet", "VALUE_1"); @@ -96,7 +96,7 @@ public class BeanWrapperEnumTests { } @Test - public void testCustomEnumSetWithMultipleValues() { + void testCustomEnumSetWithMultipleValues() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnumSet", new String[] {"VALUE_1", "VALUE_2"}); @@ -106,7 +106,7 @@ public class BeanWrapperEnumTests { } @Test - public void testCustomEnumSetWithMultipleValuesAsCsv() { + void testCustomEnumSetWithMultipleValuesAsCsv() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnumSet", "VALUE_1,VALUE_2"); @@ -116,7 +116,7 @@ public class BeanWrapperEnumTests { } @Test - public void testCustomEnumSetWithGetterSetterMismatch() { + void testCustomEnumSetWithGetterSetterMismatch() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("customEnumSetMismatch", new String[] {"VALUE_1", "VALUE_2"}); @@ -126,7 +126,7 @@ public class BeanWrapperEnumTests { } @Test - public void testStandardEnumSetWithMultipleValues() { + void testStandardEnumSetWithMultipleValues() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setConversionService(new DefaultConversionService()); @@ -138,7 +138,7 @@ public class BeanWrapperEnumTests { } @Test - public void testStandardEnumSetWithAutoGrowing() { + void testStandardEnumSetWithAutoGrowing() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setAutoGrowNestedPaths(true); @@ -148,7 +148,7 @@ public class BeanWrapperEnumTests { } @Test - public void testStandardEnumMapWithMultipleValues() { + void testStandardEnumMapWithMultipleValues() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setConversionService(new DefaultConversionService()); @@ -163,7 +163,7 @@ public class BeanWrapperEnumTests { } @Test - public void testStandardEnumMapWithAutoGrowing() { + void testStandardEnumMapWithAutoGrowing() { GenericBean gb = new GenericBean<>(); BeanWrapper bw = new BeanWrapperImpl(gb); bw.setAutoGrowNestedPaths(true); @@ -174,7 +174,7 @@ public class BeanWrapperEnumTests { } @Test - public void testNonPublicEnum() { + void testNonPublicEnum() { NonPublicEnumHolder holder = new NonPublicEnumHolder(); BeanWrapper bw = new BeanWrapperImpl(holder); bw.setPropertyValue("nonPublicEnum", "VALUE_1"); @@ -184,7 +184,7 @@ public class BeanWrapperEnumTests { enum NonPublicEnum { - VALUE_1, VALUE_2; + VALUE_1, VALUE_2 } diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java index d61a3295f54..3033edad909 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperGenericsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -201,7 +201,7 @@ class BeanWrapperGenericsTests { BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("listOfLists[0][0]", 5); assertThat(bw.getPropertyValue("listOfLists[0][0]")).isEqualTo(5); - assertThat(gb.getListOfLists().get(0)).element(0).isEqualTo(5); + assertThat(gb.getListOfLists()).singleElement().asList().containsExactly(5); } @Test @@ -213,7 +213,7 @@ class BeanWrapperGenericsTests { BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("listOfLists[0][0]", "5"); assertThat(bw.getPropertyValue("listOfLists[0][0]")).isEqualTo(5); - assertThat(gb.getListOfLists().get(0)).element(0).isEqualTo(5); + assertThat(gb.getListOfLists()).singleElement().asList().containsExactly(5); } @Test @@ -298,7 +298,7 @@ class BeanWrapperGenericsTests { BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("mapOfLists[1][0]", 5); assertThat(bw.getPropertyValue("mapOfLists[1][0]")).isEqualTo(5); - assertThat(gb.getMapOfLists().get(1)).element(0).isEqualTo(5); + assertThat(gb.getMapOfLists().get(1)).containsExactly(5); } @Test @@ -310,7 +310,7 @@ class BeanWrapperGenericsTests { BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("mapOfLists[1][0]", "5"); assertThat(bw.getPropertyValue("mapOfLists[1][0]")).isEqualTo(5); - assertThat(gb.getMapOfLists().get(1)).element(0).isEqualTo(5); + assertThat(gb.getMapOfLists().get(1)).containsExactly(5); } @Test @@ -516,8 +516,7 @@ class BeanWrapperGenericsTests { bw.setPropertyValue("genericProperty", "10"); bw.setPropertyValue("genericListProperty", new String[] {"20", "30"}); assertThat(gb.getGenericProperty()).isEqualTo(10); - assertThat(gb.getGenericListProperty()).element(0).isEqualTo(20); - assertThat(gb.getGenericListProperty()).element(1).isEqualTo(30); + assertThat(gb.getGenericListProperty()).containsExactly(20, 30); } @Test @@ -526,9 +525,9 @@ class BeanWrapperGenericsTests { BeanWrapper bw = new BeanWrapperImpl(gb); bw.setPropertyValue("genericProperty", "10"); bw.setPropertyValue("genericListProperty", new String[] {"20", "30"}); - assertThat(gb.getGenericProperty()).element(0).isEqualTo(10); - assertThat(gb.getGenericListProperty().get(0)).element(0).isEqualTo(20); - assertThat(gb.getGenericListProperty().get(1)).element(0).isEqualTo(30); + assertThat(gb.getGenericProperty()).containsExactly(10); + assertThat(gb.getGenericListProperty().get(0)).containsExactly(20); + assertThat(gb.getGenericListProperty().get(1)).containsExactly(30); } @Test diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java index e884a778def..c62a9b01d90 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -428,7 +428,7 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests { } @Override - public void close() throws Exception { + public void close() { } } diff --git a/spring-beans/src/test/java/org/springframework/beans/CachedIntrospectionResultsTests.java b/spring-beans/src/test/java/org/springframework/beans/CachedIntrospectionResultsTests.java index cba7e4964a9..3e312f888bb 100644 --- a/spring-beans/src/test/java/org/springframework/beans/CachedIntrospectionResultsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/CachedIntrospectionResultsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Chris Beams * @author Arjen Poutsma */ -public class CachedIntrospectionResultsTests { +class CachedIntrospectionResultsTests { @Test - public void acceptAndClearClassLoader() throws Exception { + void acceptAndClearClassLoader() throws Exception { BeanWrapper bw = new BeanWrapperImpl(TestBean.class); assertThat(bw.isWritableProperty("name")).isTrue(); assertThat(bw.isWritableProperty("age")).isTrue(); @@ -56,7 +56,7 @@ public class CachedIntrospectionResultsTests { } @Test - public void clearClassLoaderForSystemClassLoader() throws Exception { + void clearClassLoaderForSystemClassLoader() { BeanUtils.getPropertyDescriptors(ArrayList.class); assertThat(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class)).isTrue(); CachedIntrospectionResults.clearClassLoader(ArrayList.class.getClassLoader()); @@ -64,7 +64,7 @@ public class CachedIntrospectionResultsTests { } @Test - public void shouldUseExtendedBeanInfoWhenApplicable() throws NoSuchMethodException, SecurityException { + void shouldUseExtendedBeanInfoWhenApplicable() throws NoSuchMethodException, SecurityException { // given a class with a non-void returning setter method @SuppressWarnings("unused") class C { diff --git a/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java b/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java index d0d3e233270..e7bd9109b71 100644 --- a/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -97,7 +97,7 @@ class ConcurrentBeanWrapperTests { // ByteArrayOutputStream does not throw // any IOException } - String value = new String(buffer.toByteArray()); + String value = buffer.toString(); BeanWrapperImpl wrapper = new BeanWrapperImpl(bean); wrapper.setPropertyValue("properties", value); diff --git a/spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java b/spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java index 72b585bcafd..6bd565c4dfc 100644 --- a/spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/ExtendedBeanInfoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -558,7 +558,7 @@ class ExtendedBeanInfoTests { * @see #cornerSpr9702() */ @Test - void cornerSpr10111() throws Exception { + void cornerSpr10111() { assertThatNoException().isThrownBy(() -> new ExtendedBeanInfo(Introspector.getBeanInfo(BigDecimal.class))); } diff --git a/spring-beans/src/test/java/org/springframework/beans/PropertyAccessorUtilsTests.java b/spring-beans/src/test/java/org/springframework/beans/PropertyAccessorUtilsTests.java index 2afa65d99d0..28a9047f760 100644 --- a/spring-beans/src/test/java/org/springframework/beans/PropertyAccessorUtilsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/PropertyAccessorUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -26,17 +26,17 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @author Chris Beams */ -public class PropertyAccessorUtilsTests { +class PropertyAccessorUtilsTests { @Test - public void getPropertyName() { + void getPropertyName() { assertThat(PropertyAccessorUtils.getPropertyName("")).isEmpty(); assertThat(PropertyAccessorUtils.getPropertyName("[user]")).isEmpty(); assertThat(PropertyAccessorUtils.getPropertyName("user")).isEqualTo("user"); } @Test - public void isNestedOrIndexedProperty() { + void isNestedOrIndexedProperty() { assertThat(PropertyAccessorUtils.isNestedOrIndexedProperty(null)).isFalse(); assertThat(PropertyAccessorUtils.isNestedOrIndexedProperty("")).isFalse(); assertThat(PropertyAccessorUtils.isNestedOrIndexedProperty("user")).isFalse(); @@ -46,19 +46,19 @@ public class PropertyAccessorUtilsTests { } @Test - public void getFirstNestedPropertySeparatorIndex() { + void getFirstNestedPropertySeparatorIndex() { assertThat(PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex("[user]")).isEqualTo(-1); assertThat(PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex("user.name")).isEqualTo(4); } @Test - public void getLastNestedPropertySeparatorIndex() { + void getLastNestedPropertySeparatorIndex() { assertThat(PropertyAccessorUtils.getLastNestedPropertySeparatorIndex("[user]")).isEqualTo(-1); assertThat(PropertyAccessorUtils.getLastNestedPropertySeparatorIndex("user.address.street")).isEqualTo(12); } @Test - public void matchesProperty() { + void matchesProperty() { assertThat(PropertyAccessorUtils.matchesProperty("user", "email")).isFalse(); assertThat(PropertyAccessorUtils.matchesProperty("username", "user")).isFalse(); assertThat(PropertyAccessorUtils.matchesProperty("admin[user]", "user")).isFalse(); @@ -68,7 +68,7 @@ public class PropertyAccessorUtilsTests { } @Test - public void canonicalPropertyName() { + void canonicalPropertyName() { assertThat(PropertyAccessorUtils.canonicalPropertyName(null)).isEmpty(); assertThat(PropertyAccessorUtils.canonicalPropertyName("map")).isEqualTo("map"); assertThat(PropertyAccessorUtils.canonicalPropertyName("map[key1]")).isEqualTo("map[key1]"); @@ -82,7 +82,7 @@ public class PropertyAccessorUtilsTests { } @Test - public void canonicalPropertyNames() { + void canonicalPropertyNames() { assertThat(PropertyAccessorUtils.canonicalPropertyNames(null)).isNull(); String[] original = diff --git a/spring-beans/src/test/java/org/springframework/beans/PropertyMatchesTests.java b/spring-beans/src/test/java/org/springframework/beans/PropertyMatchesTests.java index 09e72571e00..5dc2b0f42af 100644 --- a/spring-beans/src/test/java/org/springframework/beans/PropertyMatchesTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/PropertyMatchesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -30,28 +30,28 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Stephane Nicoll */ -public class PropertyMatchesTests { +class PropertyMatchesTests { @Test - public void simpleBeanPropertyTypo() { + void simpleBeanPropertyTypo() { PropertyMatches matches = PropertyMatches.forProperty("naem", SampleBeanProperties.class); assertThat(matches.getPossibleMatches()).contains("name"); } @Test - public void complexBeanPropertyTypo() { + void complexBeanPropertyTypo() { PropertyMatches matches = PropertyMatches.forProperty("desriptn", SampleBeanProperties.class); assertThat(matches.getPossibleMatches()).isEmpty(); } @Test - public void unknownBeanProperty() { + void unknownBeanProperty() { PropertyMatches matches = PropertyMatches.forProperty("unknown", SampleBeanProperties.class); assertThat(matches.getPossibleMatches()).isEmpty(); } @Test - public void severalMatchesBeanProperty() { + void severalMatchesBeanProperty() { PropertyMatches matches = PropertyMatches.forProperty("counter", SampleBeanProperties.class); assertThat(matches.getPossibleMatches()).contains("counter1"); assertThat(matches.getPossibleMatches()).contains("counter2"); @@ -59,7 +59,7 @@ public class PropertyMatchesTests { } @Test - public void simpleBeanPropertyErrorMessage() { + void simpleBeanPropertyErrorMessage() { PropertyMatches matches = PropertyMatches.forProperty("naem", SampleBeanProperties.class); String msg = matches.buildErrorMessage(); assertThat(msg).contains("naem"); @@ -69,7 +69,7 @@ public class PropertyMatchesTests { } @Test - public void complexBeanPropertyErrorMessage() { + void complexBeanPropertyErrorMessage() { PropertyMatches matches = PropertyMatches.forProperty("counter", SampleBeanProperties.class); String msg = matches.buildErrorMessage(); assertThat(msg).contains("counter"); @@ -79,25 +79,25 @@ public class PropertyMatchesTests { } @Test - public void simpleFieldPropertyTypo() { + void simpleFieldPropertyTypo() { PropertyMatches matches = PropertyMatches.forField("naem", SampleFieldProperties.class); assertThat(matches.getPossibleMatches()).contains("name"); } @Test - public void complexFieldPropertyTypo() { + void complexFieldPropertyTypo() { PropertyMatches matches = PropertyMatches.forField("desriptn", SampleFieldProperties.class); assertThat(matches.getPossibleMatches()).isEmpty(); } @Test - public void unknownFieldProperty() { + void unknownFieldProperty() { PropertyMatches matches = PropertyMatches.forField("unknown", SampleFieldProperties.class); assertThat(matches.getPossibleMatches()).isEmpty(); } @Test - public void severalMatchesFieldProperty() { + void severalMatchesFieldProperty() { PropertyMatches matches = PropertyMatches.forField("counter", SampleFieldProperties.class); assertThat(matches.getPossibleMatches()).contains("counter1"); assertThat(matches.getPossibleMatches()).contains("counter2"); @@ -105,7 +105,7 @@ public class PropertyMatchesTests { } @Test - public void simpleFieldPropertyErrorMessage() { + void simpleFieldPropertyErrorMessage() { PropertyMatches matches = PropertyMatches.forField("naem", SampleFieldProperties.class); String msg = matches.buildErrorMessage(); assertThat(msg).contains("naem"); @@ -115,7 +115,7 @@ public class PropertyMatchesTests { } @Test - public void complexFieldPropertyErrorMessage() { + void complexFieldPropertyErrorMessage() { PropertyMatches matches = PropertyMatches.forField("counter", SampleFieldProperties.class); String msg = matches.buildErrorMessage(); assertThat(msg).contains("counter"); diff --git a/spring-beans/src/test/java/org/springframework/beans/SimplePropertyDescriptorTests.java b/spring-beans/src/test/java/org/springframework/beans/SimplePropertyDescriptorTests.java index 4a154ef10a4..d4243094b59 100644 --- a/spring-beans/src/test/java/org/springframework/beans/SimplePropertyDescriptorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/SimplePropertyDescriptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Chris Beams * @see ExtendedBeanInfoTests */ -public class SimplePropertyDescriptorTests { +class SimplePropertyDescriptorTests { @Test - public void toStringOutput() throws IntrospectionException, SecurityException, NoSuchMethodException { + void toStringOutput() throws IntrospectionException, SecurityException, NoSuchMethodException { { Object pd = new ExtendedBeanInfo.SimplePropertyDescriptor("foo", null, null); assertThat(pd.toString()).contains( @@ -71,7 +71,7 @@ public class SimplePropertyDescriptorTests { } @Test - public void nonIndexedEquality() throws IntrospectionException, SecurityException, NoSuchMethodException { + void nonIndexedEquality() throws IntrospectionException, SecurityException, NoSuchMethodException { Object pd1 = new ExtendedBeanInfo.SimplePropertyDescriptor("foo", null, null); assertThat(pd1).isEqualTo(pd1); @@ -108,7 +108,7 @@ public class SimplePropertyDescriptorTests { } @Test - public void indexedEquality() throws IntrospectionException, SecurityException, NoSuchMethodException { + void indexedEquality() throws IntrospectionException, SecurityException, NoSuchMethodException { Object pd1 = new ExtendedBeanInfo.SimpleIndexedPropertyDescriptor("foo", null, null, null, null); assertThat(pd1).isEqualTo(pd1); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java index 43a9544168b..e60d9d6d65a 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/BeanFactoryUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -49,7 +49,7 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @author Sam Brannen * @since 04.07.2003 */ -public class BeanFactoryUtilsTests { +class BeanFactoryUtilsTests { private static final Class CLASS = BeanFactoryUtilsTests.class; private static final Resource ROOT_CONTEXT = qualifiedResource(CLASS, "root.xml"); @@ -63,7 +63,7 @@ public class BeanFactoryUtilsTests { @BeforeEach - public void setup() { + void setup() { // Interesting hierarchical factory to test counts. DefaultListableBeanFactory grandParent = new DefaultListableBeanFactory(); @@ -81,7 +81,7 @@ public class BeanFactoryUtilsTests { @Test - public void testHierarchicalCountBeansWithNonHierarchicalFactory() { + void testHierarchicalCountBeansWithNonHierarchicalFactory() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); lbf.addBean("t1", new TestBean()); lbf.addBean("t2", new TestBean()); @@ -92,7 +92,7 @@ public class BeanFactoryUtilsTests { * Check that override doesn't count as two separate beans. */ @Test - public void testHierarchicalCountBeansWithOverride() { + void testHierarchicalCountBeansWithOverride() { // Leaf count assertThat(this.listableBeanFactory.getBeanDefinitionCount()).isEqualTo(1); // Count minus duplicate @@ -101,14 +101,14 @@ public class BeanFactoryUtilsTests { } @Test - public void testHierarchicalNamesWithNoMatch() { + void testHierarchicalNamesWithNoMatch() { List names = Arrays.asList( BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, NoOp.class)); assertThat(names).isEmpty(); } @Test - public void testHierarchicalNamesWithMatchOnlyInRoot() { + void testHierarchicalNamesWithMatchOnlyInRoot() { List names = Arrays.asList( BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, IndexedTestBean.class)); assertThat(names).hasSize(1); @@ -118,7 +118,7 @@ public class BeanFactoryUtilsTests { } @Test - public void testGetBeanNamesForTypeWithOverride() { + void testGetBeanNamesForTypeWithOverride() { List names = Arrays.asList( BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class)); // includes 2 TestBeans from FactoryBeans (DummyFactory definitions) @@ -130,7 +130,7 @@ public class BeanFactoryUtilsTests { } @Test - public void testNoBeansOfType() { + void testNoBeansOfType() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); lbf.addBean("foo", new Object()); Map beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false); @@ -138,7 +138,7 @@ public class BeanFactoryUtilsTests { } @Test - public void testFindsBeansOfTypeWithStaticFactory() { + void testFindsBeansOfTypeWithStaticFactory() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); TestBean t1 = new TestBean(); TestBean t2 = new TestBean(); @@ -169,7 +169,7 @@ public class BeanFactoryUtilsTests { } @Test - public void testFindsBeansOfTypeWithDefaultFactory() { + void testFindsBeansOfTypeWithDefaultFactory() { Object test3 = this.listableBeanFactory.getBean("test3"); Object test = this.listableBeanFactory.getBean("test"); @@ -232,7 +232,7 @@ public class BeanFactoryUtilsTests { } @Test - public void testHierarchicalResolutionWithOverride() { + void testHierarchicalResolutionWithOverride() { Object test3 = this.listableBeanFactory.getBean("test3"); Object test = this.listableBeanFactory.getBean("test"); @@ -271,14 +271,14 @@ public class BeanFactoryUtilsTests { } @Test - public void testHierarchicalNamesForAnnotationWithNoMatch() { + void testHierarchicalNamesForAnnotationWithNoMatch() { List names = Arrays.asList( BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(this.listableBeanFactory, Override.class)); assertThat(names).isEmpty(); } @Test - public void testHierarchicalNamesForAnnotationWithMatchOnlyInRoot() { + void testHierarchicalNamesForAnnotationWithMatchOnlyInRoot() { List names = Arrays.asList( BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(this.listableBeanFactory, TestAnnotation.class)); assertThat(names).hasSize(1); @@ -288,7 +288,7 @@ public class BeanFactoryUtilsTests { } @Test - public void testGetBeanNamesForAnnotationWithOverride() { + void testGetBeanNamesForAnnotationWithOverride() { AnnotatedBean annotatedBean = new AnnotatedBean(); this.listableBeanFactory.registerSingleton("anotherAnnotatedBean", annotatedBean); List names = Arrays.asList( @@ -299,31 +299,31 @@ public class BeanFactoryUtilsTests { } @Test - public void testADependencies() { + void testADependencies() { String[] deps = this.dependentBeansFactory.getDependentBeans("a"); assertThat(ObjectUtils.isEmpty(deps)).isTrue(); } @Test - public void testBDependencies() { + void testBDependencies() { String[] deps = this.dependentBeansFactory.getDependentBeans("b"); assertThat(Arrays.equals(new String[] { "c" }, deps)).isTrue(); } @Test - public void testCDependencies() { + void testCDependencies() { String[] deps = this.dependentBeansFactory.getDependentBeans("c"); assertThat(Arrays.equals(new String[] { "int", "long" }, deps)).isTrue(); } @Test - public void testIntDependencies() { + void testIntDependencies() { String[] deps = this.dependentBeansFactory.getDependentBeans("int"); assertThat(Arrays.equals(new String[] { "buffer" }, deps)).isTrue(); } @Test - public void findAnnotationOnBean() { + void findAnnotationOnBean() { this.listableBeanFactory.registerSingleton("controllerAdvice", new ControllerAdviceClass()); this.listableBeanFactory.registerSingleton("restControllerAdvice", new RestControllerAdviceClass()); testFindAnnotationOnBean(this.listableBeanFactory); @@ -350,7 +350,7 @@ public class BeanFactoryUtilsTests { } @Test - public void isSingletonAndIsPrototypeWithStaticFactory() { + void isSingletonAndIsPrototypeWithStaticFactory() { StaticListableBeanFactory lbf = new StaticListableBeanFactory(); TestBean bean = new TestBean(); DummyFactory fb1 = new DummyFactory(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java index 78dd589a419..12b7f26515f 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -1240,7 +1240,7 @@ class DefaultListableBeanFactoryTests { } @Test - void arrayPropertyWithOptionalAutowiring() throws MalformedURLException { + void arrayPropertyWithOptionalAutowiring() { RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class); rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE); lbf.registerBeanDefinition("arrayBean", rbd); @@ -3211,7 +3211,7 @@ class DefaultListableBeanFactoryTests { extends RepositoryFactoryBeanSupport { @Override - public T getObject() throws Exception { + public T getObject() { throw new IllegalArgumentException("Should not be called"); } @@ -3460,7 +3460,7 @@ class DefaultListableBeanFactoryTests { enum NonPublicEnum { - VALUE_1, VALUE_2; + VALUE_1, VALUE_2 } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanLookupTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanLookupTests.java index 9075bb9b37c..a8546f37481 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanLookupTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanLookupTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -32,42 +32,42 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Chris Beams */ -public class FactoryBeanLookupTests { +class FactoryBeanLookupTests { private BeanFactory beanFactory; @BeforeEach - public void setUp() { + void setUp() { beanFactory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory).loadBeanDefinitions( new ClassPathResource("FactoryBeanLookupTests-context.xml", this.getClass())); } @Test - public void factoryBeanLookupByNameDereferencing() { + void factoryBeanLookupByNameDereferencing() { Object fooFactory = beanFactory.getBean("&fooFactory"); assertThat(fooFactory).isInstanceOf(FooFactoryBean.class); } @Test - public void factoryBeanLookupByType() { + void factoryBeanLookupByType() { FooFactoryBean fooFactory = beanFactory.getBean(FooFactoryBean.class); assertThat(fooFactory).isNotNull(); } @Test - public void factoryBeanLookupByTypeAndNameDereference() { + void factoryBeanLookupByTypeAndNameDereference() { FooFactoryBean fooFactory = beanFactory.getBean("&fooFactory", FooFactoryBean.class); assertThat(fooFactory).isNotNull(); } @Test - public void factoryBeanObjectLookupByName() { + void factoryBeanObjectLookupByName() { Object fooFactory = beanFactory.getBean("fooFactory"); assertThat(fooFactory).isInstanceOf(Foo.class); } @Test - public void factoryBeanObjectLookupByNameAndType() { + void factoryBeanObjectLookupByNameAndType() { Foo foo = beanFactory.getBean("fooFactory", Foo.class); assertThat(foo).isNotNull(); } @@ -75,7 +75,7 @@ public class FactoryBeanLookupTests { class FooFactoryBean extends AbstractFactoryBean { @Override - protected Foo createInstance() throws Exception { + protected Foo createInstance() { return new Foo(); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java index fea3de17d21..e40da2c0df7 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/FactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -38,7 +38,7 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @author Juergen Hoeller * @author Chris Beams */ -public class FactoryBeanTests { +class FactoryBeanTests { private static final Class CLASS = FactoryBeanTests.class; private static final Resource RETURNS_NULL_CONTEXT = qualifiedResource(CLASS, "returnsNull.xml"); @@ -48,7 +48,7 @@ public class FactoryBeanTests { @Test - public void testFactoryBeanReturnsNull() throws Exception { + void testFactoryBeanReturnsNull() { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(RETURNS_NULL_CONTEXT); @@ -56,7 +56,7 @@ public class FactoryBeanTests { } @Test - public void testFactoryBeansWithAutowiring() throws Exception { + void testFactoryBeansWithAutowiring() { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT); @@ -77,7 +77,7 @@ public class FactoryBeanTests { } @Test - public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception { + void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT); @@ -92,21 +92,21 @@ public class FactoryBeanTests { } @Test - public void testAbstractFactoryBeanViaAnnotation() throws Exception { + void testAbstractFactoryBeanViaAnnotation() { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(ABSTRACT_CONTEXT); factory.getBeansWithAnnotation(Component.class); } @Test - public void testAbstractFactoryBeanViaType() throws Exception { + void testAbstractFactoryBeanViaType() { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(ABSTRACT_CONTEXT); factory.getBeansOfType(AbstractFactoryBean.class); } @Test - public void testCircularReferenceWithPostProcessor() { + void testCircularReferenceWithPostProcessor() { DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CIRCULAR_CONTEXT); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/Spr5475Tests.java b/spring-beans/src/test/java/org/springframework/beans/factory/Spr5475Tests.java index 846f6f6696c..a72597d7057 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/Spr5475Tests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/Spr5475Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -33,10 +33,10 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.ro * @author Chris Beams * @author Juergen Hoeller */ -public class Spr5475Tests { +class Spr5475Tests { @Test - public void noArgFactoryMethodInvokedWithOneArg() { + void noArgFactoryMethodInvokedWithOneArg() { assertExceptionMessageForMisconfiguredFactoryMethod( rootBeanDefinition(Foo.class) .setFactoryMethod("noArgFactory") @@ -47,7 +47,7 @@ public class Spr5475Tests { } @Test - public void noArgFactoryMethodInvokedWithTwoArgs() { + void noArgFactoryMethodInvokedWithTwoArgs() { assertExceptionMessageForMisconfiguredFactoryMethod( rootBeanDefinition(Foo.class) .setFactoryMethod("noArgFactory") @@ -59,7 +59,7 @@ public class Spr5475Tests { } @Test - public void noArgFactoryMethodInvokedWithTwoArgsAndTypesSpecified() { + void noArgFactoryMethodInvokedWithTwoArgsAndTypesSpecified() { RootBeanDefinition def = new RootBeanDefinition(Foo.class); def.setFactoryMethodName("noArgFactory"); ConstructorArgumentValues cav = new ConstructorArgumentValues(); @@ -82,7 +82,7 @@ public class Spr5475Tests { } @Test - public void singleArgFactoryMethodInvokedWithNoArgs() { + void singleArgFactoryMethodInvokedWithNoArgs() { // calling a factory method that accepts arguments without any arguments emits an exception unlike cases // where a no-arg factory method is called with arguments. Adding this test just to document the difference assertExceptionMessageForMisconfiguredFactoryMethod( diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolverTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolverTests.java index 4851c1387fd..27d071459c8 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolverTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -27,30 +27,30 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rick Evans * @author Chris Beams */ -public class AnnotationBeanWiringInfoResolverTests { +class AnnotationBeanWiringInfoResolverTests { @Test - public void testResolveWiringInfo() throws Exception { + void testResolveWiringInfo() { assertThatIllegalArgumentException().isThrownBy(() -> new AnnotationBeanWiringInfoResolver().resolveWiringInfo(null)); } @Test - public void testResolveWiringInfoWithAnInstanceOfANonAnnotatedClass() { + void testResolveWiringInfoWithAnInstanceOfANonAnnotatedClass() { AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver(); BeanWiringInfo info = resolver.resolveWiringInfo("java.lang.String is not @Configurable"); assertThat(info).as("Must be returning null for a non-@Configurable class instance").isNull(); } @Test - public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClass() { + void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClass() { AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver(); BeanWiringInfo info = resolver.resolveWiringInfo(new Soap()); assertThat(info).as("Must *not* be returning null for a non-@Configurable class instance").isNotNull(); } @Test - public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitly() { + void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitly() { AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver(); BeanWiringInfo info = resolver.resolveWiringInfo(new WirelessSoap()); assertThat(info).as("Must *not* be returning null for an @Configurable class instance even when autowiring is NO").isNotNull(); @@ -59,7 +59,7 @@ public class AnnotationBeanWiringInfoResolverTests { } @Test - public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitlyAndCustomBeanName() { + void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitlyAndCustomBeanName() { AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver(); BeanWiringInfo info = resolver.resolveWiringInfo(new NamedWirelessSoap()); assertThat(info).as("Must *not* be returning null for an @Configurable class instance even when autowiring is NO").isNotNull(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java index e98a21a8c71..12910bbb5bf 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -21,7 +21,6 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.Arrays; @@ -89,7 +88,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Chris Beams * @author Stephane Nicoll */ -public class AutowiredAnnotationBeanPostProcessorTests { +class AutowiredAnnotationBeanPostProcessorTests { private DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); @@ -711,15 +710,9 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.getTestBean3()).isSameAs(tb); assertThat(bean.getTestBean4()).isSameAs(tb); assertThat(bean.getIndexedTestBean()).isSameAs(itb); - assertThat(bean.getNestedTestBeans()).hasSize(2); - assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb2); - assertThat(bean.getNestedTestBeans()).element(1).isSameAs(ntb1); - assertThat(bean.nestedTestBeansSetter).hasSize(2); - assertThat(bean.nestedTestBeansSetter).element(0).isSameAs(ntb2); - assertThat(bean.nestedTestBeansSetter).element(1).isSameAs(ntb1); - assertThat(bean.nestedTestBeansField).hasSize(2); - assertThat(bean.nestedTestBeansField).element(0).isSameAs(ntb2); - assertThat(bean.nestedTestBeansField).element(1).isSameAs(ntb1); + assertThat(bean.getNestedTestBeans()).containsExactly(ntb2, ntb1); + assertThat(bean.nestedTestBeansSetter).containsExactly(ntb2, ntb1); + assertThat(bean.nestedTestBeansField).containsExactly(ntb2, ntb1); } @Test @@ -744,15 +737,9 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.getTestBean3()).isSameAs(tb); assertThat(bean.getTestBean4()).isSameAs(tb); assertThat(bean.getIndexedTestBean()).isSameAs(itb); - assertThat(bean.getNestedTestBeans()).hasSize(2); - assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb2); - assertThat(bean.getNestedTestBeans()).element(1).isSameAs(ntb1); - assertThat(bean.nestedTestBeansSetter).hasSize(2); - assertThat(bean.nestedTestBeansSetter).element(0).isSameAs(ntb2); - assertThat(bean.nestedTestBeansSetter).element(1).isSameAs(ntb1); - assertThat(bean.nestedTestBeansField).hasSize(2); - assertThat(bean.nestedTestBeansField).element(0).isSameAs(ntb2); - assertThat(bean.nestedTestBeansField).element(1).isSameAs(ntb1); + assertThat(bean.getNestedTestBeans()).containsExactly(ntb2, ntb1); + assertThat(bean.nestedTestBeansSetter).containsExactly(ntb2, ntb1); + assertThat(bean.nestedTestBeansField).containsExactly(ntb2, ntb1); } @Test @@ -1112,9 +1099,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { ConstructorsCollectionResourceInjectionBean bean = bf.getBean("annotatedBean", ConstructorsCollectionResourceInjectionBean.class); assertThat(bean.getTestBean3()).isNull(); assertThat(bean.getTestBean4()).isSameAs(tb); - assertThat(bean.getNestedTestBeans()).hasSize(2); - assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb2); - assertThat(bean.getNestedTestBeans()).element(1).isSameAs(ntb1); + assertThat(bean.getNestedTestBeans()).containsExactly(ntb2, ntb1); } @Test @@ -1129,9 +1114,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { SingleConstructorVarargBean bean = bf.getBean("annotatedBean", SingleConstructorVarargBean.class); assertThat(bean.getTestBean()).isSameAs(tb); - assertThat(bean.getNestedTestBeans()).hasSize(2); - assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb2); - assertThat(bean.getNestedTestBeans()).element(1).isSameAs(ntb1); + assertThat(bean.getNestedTestBeans()).containsExactly(ntb2, ntb1); } @Test @@ -1158,9 +1141,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { SingleConstructorRequiredCollectionBean bean = bf.getBean("annotatedBean", SingleConstructorRequiredCollectionBean.class); assertThat(bean.getTestBean()).isSameAs(tb); - assertThat(bean.getNestedTestBeans()).hasSize(2); - assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb2); - assertThat(bean.getNestedTestBeans()).element(1).isSameAs(ntb1); + assertThat(bean.getNestedTestBeans()).containsExactly(ntb2, ntb1); } @Test @@ -1187,9 +1168,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { SingleConstructorOptionalCollectionBean bean = bf.getBean("annotatedBean", SingleConstructorOptionalCollectionBean.class); assertThat(bean.getTestBean()).isSameAs(tb); - assertThat(bean.getNestedTestBeans()).hasSize(2); - assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb2); - assertThat(bean.getNestedTestBeans()).element(1).isSameAs(ntb1); + assertThat(bean.getNestedTestBeans()).containsExactly(ntb2, ntb1); } @Test @@ -1500,8 +1479,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { SelfInjectionBean bean = bf.getBean("annotatedBean", SelfInjectionBean.class); SelfInjectionBean bean2 = bf.getBean("annotatedBean2", SelfInjectionBean.class); assertThat(bean.reference).isSameAs(bean2); - assertThat(bean.referenceCollection).hasSize(1); - assertThat(bean.referenceCollection).element(0).isSameAs(bean2); + assertThat(bean.referenceCollection).containsExactly(bean2); } @Test @@ -1986,10 +1964,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerArray).hasSize(1); assertThat(bean.stringArray[0]).isSameAs(sv); assertThat(bean.integerArray[0]).isSameAs(iv); - assertThat(bean.stringList).hasSize(1); - assertThat(bean.integerList).hasSize(1); - assertThat(bean.stringList).element(0).isSameAs(sv); - assertThat(bean.integerList).element(0).isSameAs(iv); + assertThat(bean.stringList).containsExactly(sv); + assertThat(bean.integerList).containsExactly(iv); assertThat(bean.stringMap).hasSize(1); assertThat(bean.integerMap).hasSize(1); assertThat(bean.stringMap.get("stringValue")).isSameAs(sv); @@ -2000,10 +1976,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(sr); assertThat(bean.integerRepositoryArray[0]).isSameAs(ir); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(sr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(ir); + assertThat(bean.stringRepositoryList).containsExactly(sr); + assertThat(bean.integerRepositoryList).containsExactly(ir); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("stringRepo")).isSameAs(sr); @@ -2032,10 +2006,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerArray).hasSize(1); assertThat(bean.stringArray[0]).isSameAs(sv); assertThat(bean.integerArray[0]).isSameAs(iv); - assertThat(bean.stringList).hasSize(1); - assertThat(bean.integerList).hasSize(1); - assertThat(bean.stringList).element(0).isSameAs(sv); - assertThat(bean.integerList).element(0).isSameAs(iv); + assertThat(bean.stringList).containsExactly(sv); + assertThat(bean.integerList).containsExactly(iv); assertThat(bean.stringMap).hasSize(1); assertThat(bean.integerMap).hasSize(1); assertThat(bean.stringMap.get("stringValue")).isSameAs(sv); @@ -2046,10 +2018,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(sr); assertThat(bean.integerRepositoryArray[0]).isSameAs(ir); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(sr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(ir); + assertThat(bean.stringRepositoryList).containsExactly(sr); + assertThat(bean.integerRepositoryList).containsExactly(ir); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("stringRepo")).isSameAs(sr); @@ -2074,10 +2044,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(sr); assertThat(bean.integerRepositoryArray[0]).isSameAs(ir); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(sr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(ir); + assertThat(bean.stringRepositoryList).containsExactly(sr); + assertThat(bean.integerRepositoryList).containsExactly(ir); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("stringRepo")).isSameAs(sr); @@ -2141,9 +2109,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.stringRepositoryArray).hasSize(1); assertThat(bean.repositoryArray[0]).isSameAs(repo); assertThat(bean.stringRepositoryArray[0]).isSameAs(repo); - assertThat(bean.repositoryList).hasSize(1); + assertThat(bean.repositoryList).containsExactly(repo); assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.repositoryList).element(0).isSameAs(repo); assertThat(bean.stringRepositoryList).element(0).isSameAs(repo); assertThat(bean.repositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap).hasSize(1); @@ -2201,7 +2168,6 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.stringRepositoryArray[0]).isSameAs(repo); assertThat(bean.repositoryList).hasSize(1); assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.repositoryList).element(0).isSameAs(repo); assertThat(bean.stringRepositoryList).element(0).isSameAs(repo); assertThat(bean.repositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap).hasSize(1); @@ -2230,9 +2196,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.stringRepositoryArray).hasSize(1); assertThat(bean.repositoryArray[0]).isSameAs(repo); assertThat(bean.stringRepositoryArray[0]).isSameAs(repo); - assertThat(bean.repositoryList).hasSize(1); + assertThat(bean.repositoryList).containsExactly(repo); assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.repositoryList).element(0).isSameAs(repo); assertThat(bean.stringRepositoryList).element(0).isSameAs(repo); assertThat(bean.repositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap).hasSize(1); @@ -2270,10 +2235,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerArray).hasSize(1); assertThat(bean.stringArray[0]).isSameAs(sv); assertThat(bean.integerArray[0]).isSameAs(iv); - assertThat(bean.stringList).hasSize(1); - assertThat(bean.integerList).hasSize(1); - assertThat(bean.stringList).element(0).isSameAs(sv); - assertThat(bean.integerList).element(0).isSameAs(iv); + assertThat(bean.stringList).containsExactly(sv); + assertThat(bean.integerList).containsExactly(iv); assertThat(bean.stringMap).hasSize(1); assertThat(bean.integerMap).hasSize(1); assertThat(bean.stringMap.get("stringValue")).isSameAs(sv); @@ -2284,10 +2247,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(sr); assertThat(bean.integerRepositoryArray[0]).isSameAs(ir); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(sr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(ir); + assertThat(bean.stringRepositoryList).containsExactly(sr); + assertThat(bean.integerRepositoryList).containsExactly(ir); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("stringRepo")).isSameAs(sr); @@ -2316,10 +2277,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerArray).hasSize(1); assertThat(bean.stringArray[0]).isSameAs(sv); assertThat(bean.integerArray[0]).isSameAs(iv); - assertThat(bean.stringList).hasSize(1); - assertThat(bean.integerList).hasSize(1); - assertThat(bean.stringList).element(0).isSameAs(sv); - assertThat(bean.integerList).element(0).isSameAs(iv); + assertThat(bean.stringList).containsExactly(sv); + assertThat(bean.integerList).containsExactly(iv); assertThat(bean.stringMap).hasSize(1); assertThat(bean.integerMap).hasSize(1); assertThat(bean.stringMap.get("stringValue")).isSameAs(sv); @@ -2330,10 +2289,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(sr); assertThat(bean.integerRepositoryArray[0]).isSameAs(ir); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(sr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(ir); + assertThat(bean.stringRepositoryList).containsExactly(sr); + assertThat(bean.integerRepositoryList).containsExactly(ir); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("stringRepo")).isSameAs(sr); @@ -2357,10 +2314,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(sr); assertThat(bean.integerRepositoryArray[0]).isSameAs(ir); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(sr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(ir); + assertThat(bean.stringRepositoryList).containsExactly(sr); + assertThat(bean.integerRepositoryList).containsExactly(ir); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("stringRepo")).isSameAs(sr); @@ -2383,10 +2338,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(gr); assertThat(bean.integerRepositoryArray[0]).isSameAs(gr); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(gr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(gr); + assertThat(bean.stringRepositoryList).containsExactly(gr); + assertThat(bean.integerRepositoryList).containsExactly(gr); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("genericRepo")).isSameAs(gr); @@ -2408,10 +2361,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(ngr); assertThat(bean.integerRepositoryArray[0]).isSameAs(ngr); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(ngr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(ngr); + assertThat(bean.stringRepositoryList).containsExactly(ngr); + assertThat(bean.integerRepositoryList).containsExactly(ngr); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("simpleRepo")).isSameAs(ngr); @@ -2436,10 +2387,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(sr); assertThat(bean.integerRepositoryArray[0]).isSameAs(gr); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(sr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(gr); + assertThat(bean.stringRepositoryList).containsExactly(sr); + assertThat(bean.integerRepositoryList).containsExactly(gr); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("stringRepo")).isSameAs(sr); @@ -2463,10 +2412,8 @@ public class AutowiredAnnotationBeanPostProcessorTests { assertThat(bean.integerRepositoryArray).hasSize(1); assertThat(bean.stringRepositoryArray[0]).isSameAs(sr); assertThat(bean.integerRepositoryArray[0]).isSameAs(ngr); - assertThat(bean.stringRepositoryList).hasSize(1); - assertThat(bean.integerRepositoryList).hasSize(1); - assertThat(bean.stringRepositoryList).element(0).isSameAs(sr); - assertThat(bean.integerRepositoryList).element(0).isSameAs(ngr); + assertThat(bean.stringRepositoryList).containsExactly(sr); + assertThat(bean.integerRepositoryList).containsExactly(ngr); assertThat(bean.stringRepositoryMap).hasSize(1); assertThat(bean.integerRepositoryMap).hasSize(1); assertThat(bean.stringRepositoryMap.get("stringRepo")).isSameAs(sr); @@ -2602,7 +2549,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { } @Test - public void mixedNullableArgMethodInjection(){ + void mixedNullableArgMethodInjection(){ bf.registerSingleton("nonNullBean", "Test"); bf.registerBeanDefinition("mixedNullableInjectionBean", new RootBeanDefinition(MixedNullableInjectionBean.class)); @@ -2612,7 +2559,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { } @Test - public void mixedOptionalArgMethodInjection(){ + void mixedOptionalArgMethodInjection(){ bf.registerSingleton("nonNullBean", "Test"); bf.registerBeanDefinition("mixedOptionalInjectionBean", new RootBeanDefinition(MixedOptionalInjectionBean.class)); @@ -3463,7 +3410,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { public static class StringFactoryBean implements FactoryBean { @Override - public String getObject() throws Exception { + public String getObject() { return ""; } @@ -3998,7 +3945,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { @SuppressWarnings("unchecked") public T createMock(Class toMock) { return (T) Proxy.newProxyInstance(AutowiredAnnotationBeanPostProcessorTests.class.getClassLoader(), new Class[] {toMock}, - (InvocationHandler) (proxy, method, args) -> { + (proxy, method, args) -> { throw new UnsupportedOperationException("mocked!"); }); } @@ -4146,7 +4093,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { public static class MyCallable implements Callable { @Override - public Thread call() throws Exception { + public Thread call() { return null; } } @@ -4155,7 +4102,7 @@ public class AutowiredAnnotationBeanPostProcessorTests { public static class SecondCallable implements Callable{ @Override - public Thread call() throws Exception { + public Thread call() { return null; } } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java index 02a87f6c0d4..0c2e336552c 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -34,10 +34,10 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @author Juergen Hoeller * @author Chris Beams */ -public class CustomAutowireConfigurerTests { +class CustomAutowireConfigurerTests { @Test - public void testCustomResolver() { + void testCustomResolver() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( qualifiedResource(CustomAutowireConfigurerTests.class, "context.xml")); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java index d3cf63cb4dd..d73ced61990 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -33,6 +33,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorTests.StringFactoryBean; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.AutowireCandidateQualifier; @@ -55,7 +56,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Juergen Hoeller * @since 3.0 */ -public class InjectAnnotationBeanPostProcessorTests { +class InjectAnnotationBeanPostProcessorTests { private DefaultListableBeanFactory bf; @@ -63,7 +64,7 @@ public class InjectAnnotationBeanPostProcessorTests { @BeforeEach - public void setup() { + void setup() { bf = new DefaultListableBeanFactory(); bf.registerResolvableDependency(BeanFactory.class, bf); bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -73,13 +74,13 @@ public class InjectAnnotationBeanPostProcessorTests { } @AfterEach - public void close() { + void close() { bf.destroySingletons(); } @Test - public void testIncompleteBeanDefinition() { + void testIncompleteBeanDefinition() { bf.registerBeanDefinition("testBean", new GenericBeanDefinition()); try { bf.getBean("testBean"); @@ -90,7 +91,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testResourceInjection() { + void testResourceInjection() { RootBeanDefinition bd = new RootBeanDefinition(ResourceInjectionBean.class); bd.setScope(BeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); @@ -107,7 +108,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testExtendedResourceInjection() { + void testExtendedResourceInjection() { RootBeanDefinition bd = new RootBeanDefinition(TypedExtendedResourceInjectionBean.class); bd.setScope(BeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); @@ -134,7 +135,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testExtendedResourceInjectionWithOverriding() { + void testExtendedResourceInjectionWithOverriding() { RootBeanDefinition annotatedBd = new RootBeanDefinition(TypedExtendedResourceInjectionBean.class); TestBean tb2 = new TestBean(); annotatedBd.getPropertyValues().add("testBean2", tb2); @@ -154,7 +155,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testConstructorResourceInjection() { + void testConstructorResourceInjection() { RootBeanDefinition bd = new RootBeanDefinition(ConstructorResourceInjectionBean.class); bd.setScope(BeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); @@ -181,7 +182,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testConstructorResourceInjectionWithMultipleCandidatesAsCollection() { + void testConstructorResourceInjectionWithMultipleCandidatesAsCollection() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorsCollectionResourceInjectionBean.class)); TestBean tb = new TestBean(); @@ -200,7 +201,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testConstructorResourceInjectionWithMultipleCandidatesAndFallback() { + void testConstructorResourceInjectionWithMultipleCandidatesAndFallback() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorsResourceInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); @@ -211,7 +212,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testConstructorInjectionWithMap() { + void testConstructorInjectionWithMap() { RootBeanDefinition bd = new RootBeanDefinition(MapConstructorInjectionBean.class); bd.setScope(BeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); @@ -236,7 +237,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testFieldInjectionWithMap() { + void testFieldInjectionWithMap() { RootBeanDefinition bd = new RootBeanDefinition(MapFieldInjectionBean.class); bd.setScope(BeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); @@ -261,7 +262,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testMethodInjectionWithMap() { + void testMethodInjectionWithMap() { RootBeanDefinition bd = new RootBeanDefinition(MapMethodInjectionBean.class); bd.setScope(BeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", bd); @@ -282,7 +283,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testMethodInjectionWithMapAndMultipleMatches() { + void testMethodInjectionWithMapAndMultipleMatches() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(MapMethodInjectionBean.class)); bf.registerBeanDefinition("testBean1", new RootBeanDefinition(TestBean.class)); bf.registerBeanDefinition("testBean2", new RootBeanDefinition(TestBean.class)); @@ -291,7 +292,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testMethodInjectionWithMapAndMultipleMatchesButOnlyOneAutowireCandidate() { + void testMethodInjectionWithMapAndMultipleMatchesButOnlyOneAutowireCandidate() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(MapMethodInjectionBean.class)); bf.registerBeanDefinition("testBean1", new RootBeanDefinition(TestBean.class)); RootBeanDefinition rbd2 = new RootBeanDefinition(TestBean.class); @@ -307,7 +308,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryInjection() { + void testObjectFactoryInjection() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryQualifierFieldInjectionBean.class)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "testBean")); @@ -319,7 +320,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryQualifierInjection() { + void testObjectFactoryQualifierInjection() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryQualifierFieldInjectionBean.class)); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "testBean")); @@ -330,7 +331,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryFieldInjectionIntoPrototypeBean() { + void testObjectFactoryFieldInjectionIntoPrototypeBean() { RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition(ObjectFactoryQualifierFieldInjectionBean.class); annotatedBeanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", annotatedBeanDefinition); @@ -347,7 +348,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryMethodInjectionIntoPrototypeBean() { + void testObjectFactoryMethodInjectionIntoPrototypeBean() { RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition(ObjectFactoryQualifierMethodInjectionBean.class); annotatedBeanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE); bf.registerBeanDefinition("annotatedBean", annotatedBeanDefinition); @@ -364,7 +365,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryWithBeanField() throws Exception { + void testObjectFactoryWithBeanField() throws Exception { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryFieldInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); bf.setSerializationId("test"); @@ -376,7 +377,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryWithBeanMethod() throws Exception { + void testObjectFactoryWithBeanMethod() throws Exception { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryMethodInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); bf.setSerializationId("test"); @@ -388,7 +389,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryWithTypedListField() throws Exception { + void testObjectFactoryWithTypedListField() throws Exception { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryListFieldInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); bf.setSerializationId("test"); @@ -400,7 +401,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryWithTypedListMethod() throws Exception { + void testObjectFactoryWithTypedListMethod() throws Exception { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryListMethodInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); bf.setSerializationId("test"); @@ -412,7 +413,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryWithTypedMapField() throws Exception { + void testObjectFactoryWithTypedMapField() throws Exception { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryMapFieldInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); bf.setSerializationId("test"); @@ -424,7 +425,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testObjectFactoryWithTypedMapMethod() throws Exception { + void testObjectFactoryWithTypedMapMethod() throws Exception { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryMapMethodInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); bf.setSerializationId("test"); @@ -441,7 +442,7 @@ public class InjectAnnotationBeanPostProcessorTests { * specifically addressing SPR-4040. */ @Test - public void testBeanAutowiredWithFactoryBean() { + void testBeanAutowiredWithFactoryBean() { bf.registerBeanDefinition("factoryBeanDependentBean", new RootBeanDefinition(FactoryBeanDependentBean.class)); bf.registerSingleton("stringFactoryBean", new StringFactoryBean()); @@ -454,7 +455,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testNullableFieldInjectionWithBeanAvailable() { + void testNullableFieldInjectionWithBeanAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(NullableFieldInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); @@ -463,7 +464,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testNullableFieldInjectionWithBeanNotAvailable() { + void testNullableFieldInjectionWithBeanNotAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(NullableFieldInjectionBean.class)); NullableFieldInjectionBean bean = (NullableFieldInjectionBean) bf.getBean("annotatedBean"); @@ -471,7 +472,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testNullableMethodInjectionWithBeanAvailable() { + void testNullableMethodInjectionWithBeanAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(NullableMethodInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); @@ -480,7 +481,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testNullableMethodInjectionWithBeanNotAvailable() { + void testNullableMethodInjectionWithBeanNotAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(NullableMethodInjectionBean.class)); NullableMethodInjectionBean bean = (NullableMethodInjectionBean) bf.getBean("annotatedBean"); @@ -488,7 +489,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testOptionalFieldInjectionWithBeanAvailable() { + void testOptionalFieldInjectionWithBeanAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalFieldInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); @@ -498,7 +499,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testOptionalFieldInjectionWithBeanNotAvailable() { + void testOptionalFieldInjectionWithBeanNotAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalFieldInjectionBean.class)); OptionalFieldInjectionBean bean = (OptionalFieldInjectionBean) bf.getBean("annotatedBean"); @@ -506,7 +507,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testOptionalMethodInjectionWithBeanAvailable() { + void testOptionalMethodInjectionWithBeanAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalMethodInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); @@ -516,7 +517,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testOptionalMethodInjectionWithBeanNotAvailable() { + void testOptionalMethodInjectionWithBeanNotAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalMethodInjectionBean.class)); OptionalMethodInjectionBean bean = (OptionalMethodInjectionBean) bf.getBean("annotatedBean"); @@ -524,7 +525,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testOptionalListFieldInjectionWithBeanAvailable() { + void testOptionalListFieldInjectionWithBeanAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListFieldInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); @@ -534,7 +535,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testOptionalListFieldInjectionWithBeanNotAvailable() { + void testOptionalListFieldInjectionWithBeanNotAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListFieldInjectionBean.class)); OptionalListFieldInjectionBean bean = (OptionalListFieldInjectionBean) bf.getBean("annotatedBean"); @@ -542,7 +543,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testOptionalListMethodInjectionWithBeanAvailable() { + void testOptionalListMethodInjectionWithBeanAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListMethodInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); @@ -552,7 +553,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testOptionalListMethodInjectionWithBeanNotAvailable() { + void testOptionalListMethodInjectionWithBeanNotAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListMethodInjectionBean.class)); OptionalListMethodInjectionBean bean = (OptionalListMethodInjectionBean) bf.getBean("annotatedBean"); @@ -560,7 +561,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testProviderOfOptionalFieldInjectionWithBeanAvailable() { + void testProviderOfOptionalFieldInjectionWithBeanAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ProviderOfOptionalFieldInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); @@ -570,7 +571,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testProviderOfOptionalFieldInjectionWithBeanNotAvailable() { + void testProviderOfOptionalFieldInjectionWithBeanNotAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ProviderOfOptionalFieldInjectionBean.class)); ProviderOfOptionalFieldInjectionBean bean = (ProviderOfOptionalFieldInjectionBean) bf.getBean("annotatedBean"); @@ -578,7 +579,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testProviderOfOptionalMethodInjectionWithBeanAvailable() { + void testProviderOfOptionalMethodInjectionWithBeanAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ProviderOfOptionalMethodInjectionBean.class)); bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class)); @@ -588,7 +589,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testProviderOfOptionalMethodInjectionWithBeanNotAvailable() { + void testProviderOfOptionalMethodInjectionWithBeanNotAvailable() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ProviderOfOptionalMethodInjectionBean.class)); ProviderOfOptionalMethodInjectionBean bean = (ProviderOfOptionalMethodInjectionBean) bf.getBean("annotatedBean"); @@ -596,7 +597,7 @@ public class InjectAnnotationBeanPostProcessorTests { } @Test - public void testAnnotatedDefaultConstructor() { + void testAnnotatedDefaultConstructor() { bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedDefaultConstructorBean.class)); assertThat(bf.getBean("annotatedBean")).isNotNull(); @@ -644,7 +645,6 @@ public class InjectAnnotationBeanPostProcessorTests { @Override @Inject - @SuppressWarnings("deprecation") public void setTestBean2(TestBean testBean2) { super.setTestBean2(testBean2); } @@ -1108,25 +1108,6 @@ public class InjectAnnotationBeanPostProcessorTests { } - public static class StringFactoryBean implements FactoryBean { - - @Override - public String getObject() { - return ""; - } - - @Override - public Class getObjectType() { - return String.class; - } - - @Override - public boolean isSingleton() { - return true; - } - } - - @Retention(RetentionPolicy.RUNTIME) public @interface Nullable {} diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/LookupAnnotationTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/LookupAnnotationTests.java index 526e3153553..f12e9a0fac6 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/LookupAnnotationTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/LookupAnnotationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,13 +31,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Karl Pietrzak * @author Juergen Hoeller */ -public class LookupAnnotationTests { +class LookupAnnotationTests { private DefaultListableBeanFactory beanFactory; @BeforeEach - public void setup() { + void setup() { beanFactory = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor aabpp = new AutowiredAnnotationBeanPostProcessor(); aabpp.setBeanFactory(beanFactory); @@ -51,7 +51,7 @@ public class LookupAnnotationTests { @Test - public void testWithoutConstructorArg() { + void testWithoutConstructorArg() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); Object expected = bean.get(); assertThat(expected.getClass()).isEqualTo(TestBean.class); @@ -59,7 +59,7 @@ public class LookupAnnotationTests { } @Test - public void testWithOverloadedArg() { + void testWithOverloadedArg() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); TestBean expected = bean.get("haha"); assertThat(expected.getClass()).isEqualTo(TestBean.class); @@ -68,7 +68,7 @@ public class LookupAnnotationTests { } @Test - public void testWithOneConstructorArg() { + void testWithOneConstructorArg() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); TestBean expected = bean.getOneArgument("haha"); assertThat(expected.getClass()).isEqualTo(TestBean.class); @@ -77,7 +77,7 @@ public class LookupAnnotationTests { } @Test - public void testWithTwoConstructorArg() { + void testWithTwoConstructorArg() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); TestBean expected = bean.getTwoArguments("haha", 72); assertThat(expected.getClass()).isEqualTo(TestBean.class); @@ -87,7 +87,7 @@ public class LookupAnnotationTests { } @Test - public void testWithThreeArgsShouldFail() { + void testWithThreeArgsShouldFail() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); assertThatExceptionOfType(AbstractMethodError.class).as("TestBean has no three arg constructor").isThrownBy(() -> bean.getThreeArguments("name", 1, 2)); @@ -95,7 +95,7 @@ public class LookupAnnotationTests { } @Test - public void testWithEarlyInjection() { + void testWithEarlyInjection() { AbstractBean bean = beanFactory.getBean("beanConsumer", BeanConsumer.class).abstractBean; Object expected = bean.get(); assertThat(expected.getClass()).isEqualTo(TestBean.class); @@ -115,7 +115,7 @@ public class LookupAnnotationTests { } @Test - public void testWithGenericBean() { + void testWithGenericBean() { beanFactory.registerBeanDefinition("numberBean", new RootBeanDefinition(NumberBean.class)); beanFactory.registerBeanDefinition("doubleStore", new RootBeanDefinition(DoubleStore.class)); beanFactory.registerBeanDefinition("floatStore", new RootBeanDefinition(FloatStore.class)); @@ -126,7 +126,7 @@ public class LookupAnnotationTests { } @Test - public void testSingletonWithoutMetadataCaching() { + void testSingletonWithoutMetadataCaching() { beanFactory.setCacheBeanMetadata(false); beanFactory.registerBeanDefinition("numberBean", new RootBeanDefinition(NumberBean.class)); @@ -139,7 +139,7 @@ public class LookupAnnotationTests { } @Test - public void testPrototypeWithoutMetadataCaching() { + void testPrototypeWithoutMetadataCaching() { beanFactory.setCacheBeanMetadata(false); beanFactory.registerBeanDefinition("numberBean", new RootBeanDefinition(NumberBean.class, BeanDefinition.SCOPE_PROTOTYPE, null)); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/ParameterResolutionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/ParameterResolutionTests.java index de4e74fc27a..b1e17d66f68 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/ParameterResolutionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/ParameterResolutionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -41,29 +41,29 @@ import static org.mockito.Mockito.mock; * @author Juergen Hoeller * @author Loïc Ledoyen */ -public class ParameterResolutionTests { +class ParameterResolutionTests { @Test - public void isAutowirablePreconditions() { + void isAutowirablePreconditions() { assertThatIllegalArgumentException().isThrownBy(() -> ParameterResolutionDelegate.isAutowirable(null, 0)) .withMessageContaining("Parameter must not be null"); } @Test - public void annotatedParametersInMethodAreCandidatesForAutowiring() throws Exception { + void annotatedParametersInMethodAreCandidatesForAutowiring() throws Exception { Method method = getClass().getDeclaredMethod("autowirableMethod", String.class, String.class, String.class, String.class); assertAutowirableParameters(method); } @Test - public void annotatedParametersInTopLevelClassConstructorAreCandidatesForAutowiring() throws Exception { + void annotatedParametersInTopLevelClassConstructorAreCandidatesForAutowiring() throws Exception { Constructor constructor = AutowirableClass.class.getConstructor(String.class, String.class, String.class, String.class); assertAutowirableParameters(constructor); } @Test - public void annotatedParametersInInnerClassConstructorAreCandidatesForAutowiring() throws Exception { + void annotatedParametersInInnerClassConstructorAreCandidatesForAutowiring() throws Exception { Class innerClass = AutowirableClass.InnerAutowirableClass.class; assertThat(ClassUtils.isInnerClass(innerClass)).isTrue(); Constructor constructor = innerClass.getConstructor(AutowirableClass.class, String.class, String.class); @@ -81,7 +81,7 @@ public class ParameterResolutionTests { } @Test - public void nonAnnotatedParametersInTopLevelClassConstructorAreNotCandidatesForAutowiring() throws Exception { + void nonAnnotatedParametersInTopLevelClassConstructorAreNotCandidatesForAutowiring() throws Exception { Constructor notAutowirableConstructor = AutowirableClass.class.getConstructor(String.class); Parameter[] parameters = notAutowirableConstructor.getParameters(); @@ -92,21 +92,21 @@ public class ParameterResolutionTests { } @Test - public void resolveDependencyPreconditionsForParameter() { + void resolveDependencyPreconditionsForParameter() { assertThatIllegalArgumentException() .isThrownBy(() -> ParameterResolutionDelegate.resolveDependency(null, 0, null, mock())) .withMessageContaining("Parameter must not be null"); } @Test - public void resolveDependencyPreconditionsForContainingClass() throws Exception { + void resolveDependencyPreconditionsForContainingClass() { assertThatIllegalArgumentException().isThrownBy(() -> ParameterResolutionDelegate.resolveDependency(getParameter(), 0, null, null)) .withMessageContaining("Containing class must not be null"); } @Test - public void resolveDependencyPreconditionsForBeanFactory() throws Exception { + void resolveDependencyPreconditionsForBeanFactory() { assertThatIllegalArgumentException().isThrownBy(() -> ParameterResolutionDelegate.resolveDependency(getParameter(), 0, getClass(), null)) .withMessageContaining("AutowireCapableBeanFactory must not be null"); @@ -118,7 +118,7 @@ public class ParameterResolutionTests { } @Test - public void resolveDependencyForAnnotatedParametersInTopLevelClassConstructor() throws Exception { + void resolveDependencyForAnnotatedParametersInTopLevelClassConstructor() throws Exception { Constructor constructor = AutowirableClass.class.getConstructor(String.class, String.class, String.class, String.class); AutowireCapableBeanFactory beanFactory = mock(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java index 17e985f135c..507d2564805 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -692,7 +692,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests { @Nullable @Override - public String getObject() throws Exception { + public String getObject() { return getPrefix() + " " + getName(); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java index 9af47fbd133..c1ded5f4a29 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -26,11 +26,11 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.annotation.InjectAnnotationBeanPostProcessorTests.StringFactoryBean; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.testfixture.beans.factory.DummyFactory; +import org.springframework.beans.testfixture.beans.factory.StringFactoryBean; import org.springframework.beans.testfixture.beans.factory.aot.GenericFactoryBean; import org.springframework.beans.testfixture.beans.factory.aot.MockBeanRegistrationCode; import org.springframework.beans.testfixture.beans.factory.aot.MockBeanRegistrationsCode; @@ -275,7 +275,7 @@ class DefaultBeanRegistrationCodeFragmentsTests { static class PrivilegedTestBeanFactoryBean implements FactoryBean { @Override - public SimpleBean getObject() throws Exception { + public SimpleBean getObject() { return new SimpleBean(); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomEditorConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomEditorConfigurerTests.java index 48a87a9a773..0ec429a10c8 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomEditorConfigurerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomEditorConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -41,10 +41,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Chris Beams * @since 31.07.2004 */ -public class CustomEditorConfigurerTests { +class CustomEditorConfigurerTests { @Test - public void testCustomEditorConfigurerWithPropertyEditorRegistrar() throws ParseException { + void testCustomEditorConfigurerWithPropertyEditorRegistrar() throws ParseException { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CustomEditorConfigurer cec = new CustomEditorConfigurer(); final DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN); @@ -70,7 +70,7 @@ public class CustomEditorConfigurerTests { } @Test - public void testCustomEditorConfigurerWithEditorAsClass() throws ParseException { + void testCustomEditorConfigurerWithEditorAsClass() throws ParseException { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CustomEditorConfigurer cec = new CustomEditorConfigurer(); Map, Class> editors = new HashMap<>(); @@ -90,7 +90,7 @@ public class CustomEditorConfigurerTests { } @Test - public void testCustomEditorConfigurerWithRequiredTypeArray() throws ParseException { + void testCustomEditorConfigurerWithRequiredTypeArray() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); CustomEditorConfigurer cec = new CustomEditorConfigurer(); Map, Class> editors = new HashMap<>(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java index 82523c771de..ebbadd9fcd5 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/CustomScopeConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -35,7 +35,7 @@ import static org.mockito.Mockito.mock; * @author Juergen Hoeller * @author Chris Beams */ -public class CustomScopeConfigurerTests { +class CustomScopeConfigurerTests { private static final String FOO_SCOPE = "fooScope"; @@ -43,13 +43,13 @@ public class CustomScopeConfigurerTests { @Test - public void testWithNoScopes() { + void testWithNoScopes() { CustomScopeConfigurer figurer = new CustomScopeConfigurer(); figurer.postProcessBeanFactory(factory); } @Test - public void testSunnyDayWithBonaFideScopeInstance() { + void testSunnyDayWithBonaFideScopeInstance() { Scope scope = mock(); factory.registerScope(FOO_SCOPE, scope); Map scopes = new HashMap<>(); @@ -60,7 +60,7 @@ public class CustomScopeConfigurerTests { } @Test - public void testSunnyDayWithBonaFideScopeClass() { + void testSunnyDayWithBonaFideScopeClass() { Map scopes = new HashMap<>(); scopes.put(FOO_SCOPE, NoOpScope.class); CustomScopeConfigurer figurer = new CustomScopeConfigurer(); @@ -70,7 +70,7 @@ public class CustomScopeConfigurerTests { } @Test - public void testSunnyDayWithBonaFideScopeClassName() { + void testSunnyDayWithBonaFideScopeClassName() { Map scopes = new HashMap<>(); scopes.put(FOO_SCOPE, NoOpScope.class.getName()); CustomScopeConfigurer figurer = new CustomScopeConfigurer(); @@ -80,7 +80,7 @@ public class CustomScopeConfigurerTests { } @Test - public void testWhereScopeMapHasNullScopeValueInEntrySet() { + void testWhereScopeMapHasNullScopeValueInEntrySet() { Map scopes = new HashMap<>(); scopes.put(FOO_SCOPE, null); CustomScopeConfigurer figurer = new CustomScopeConfigurer(); @@ -90,7 +90,7 @@ public class CustomScopeConfigurerTests { } @Test - public void testWhereScopeMapHasNonScopeInstanceInEntrySet() { + void testWhereScopeMapHasNonScopeInstanceInEntrySet() { Map scopes = new HashMap<>(); scopes.put(FOO_SCOPE, this); // <-- not a valid value... CustomScopeConfigurer figurer = new CustomScopeConfigurer(); @@ -101,7 +101,7 @@ public class CustomScopeConfigurerTests { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test - public void testWhereScopeMapHasNonStringTypedScopeNameInKeySet() { + void testWhereScopeMapHasNonStringTypedScopeNameInKeySet() { Map scopes = new HashMap(); scopes.put(this, new NoOpScope()); // <-- not a valid value (the key)... CustomScopeConfigurer figurer = new CustomScopeConfigurer(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/DeprecatedBeanWarnerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/DeprecatedBeanWarnerTests.java index 2be93f0d400..d9a6023e3c7 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/DeprecatedBeanWarnerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/DeprecatedBeanWarnerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Arjen Poutsma */ -public class DeprecatedBeanWarnerTests { +class DeprecatedBeanWarnerTests { private String beanName; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java index b697500fb34..5129fef2432 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -34,10 +34,10 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @author Chris Beams * @since 31.07.2004 */ -public class FieldRetrievingFactoryBeanTests { +class FieldRetrievingFactoryBeanTests { @Test - public void testStaticField() throws Exception { + void testStaticField() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); fr.setStaticField("java.sql.Connection.TRANSACTION_SERIALIZABLE"); fr.afterPropertiesSet(); @@ -45,7 +45,7 @@ public class FieldRetrievingFactoryBeanTests { } @Test - public void testStaticFieldWithWhitespace() throws Exception { + void testStaticFieldWithWhitespace() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); fr.setStaticField(" java.sql.Connection.TRANSACTION_SERIALIZABLE "); fr.afterPropertiesSet(); @@ -53,7 +53,7 @@ public class FieldRetrievingFactoryBeanTests { } @Test - public void testStaticFieldViaClassAndFieldName() throws Exception { + void testStaticFieldViaClassAndFieldName() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); fr.setTargetClass(Connection.class); fr.setTargetField("TRANSACTION_SERIALIZABLE"); @@ -62,7 +62,7 @@ public class FieldRetrievingFactoryBeanTests { } @Test - public void testNonStaticField() throws Exception { + void testNonStaticField() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); PublicFieldHolder target = new PublicFieldHolder(); fr.setTargetObject(target); @@ -72,7 +72,7 @@ public class FieldRetrievingFactoryBeanTests { } @Test - public void testNothingButBeanName() throws Exception { + void testNothingButBeanName() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); fr.setBeanName("java.sql.Connection.TRANSACTION_SERIALIZABLE"); fr.afterPropertiesSet(); @@ -80,7 +80,7 @@ public class FieldRetrievingFactoryBeanTests { } @Test - public void testJustTargetField() throws Exception { + void testJustTargetField() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); fr.setTargetField("TRANSACTION_SERIALIZABLE"); try { @@ -91,7 +91,7 @@ public class FieldRetrievingFactoryBeanTests { } @Test - public void testJustTargetClass() throws Exception { + void testJustTargetClass() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); fr.setTargetClass(Connection.class); try { @@ -102,7 +102,7 @@ public class FieldRetrievingFactoryBeanTests { } @Test - public void testJustTargetObject() throws Exception { + void testJustTargetObject() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); fr.setTargetObject(new PublicFieldHolder()); try { @@ -113,7 +113,7 @@ public class FieldRetrievingFactoryBeanTests { } @Test - public void testWithConstantOnClassWithPackageLevelVisibility() throws Exception { + void testWithConstantOnClassWithPackageLevelVisibility() throws Exception { FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean(); fr.setBeanName("org.springframework.beans.testfixture.beans.PackageLevelVisibleBean.CONSTANT"); fr.afterPropertiesSet(); @@ -121,7 +121,7 @@ public class FieldRetrievingFactoryBeanTests { } @Test - public void testBeanNameSyntaxWithBeanFactory() throws Exception { + void testBeanNameSyntaxWithBeanFactory() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( qualifiedResource(FieldRetrievingFactoryBeanTests.class, "context.xml")); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/MethodInvokingFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/MethodInvokingFactoryBeanTests.java index ff1af3ed421..83d15069f72 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/MethodInvokingFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/MethodInvokingFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -38,10 +38,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Chris Beams * @since 21.11.2003 */ -public class MethodInvokingFactoryBeanTests { +class MethodInvokingFactoryBeanTests { @Test - public void testParameterValidation() throws Exception { + void testParameterValidation() throws Exception { // assert that only static OR non-static are set, but not both or none MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean(); @@ -91,7 +91,7 @@ public class MethodInvokingFactoryBeanTests { } @Test - public void testGetObjectType() throws Exception { + void testGetObjectType() throws Exception { TestClass1 tc1 = new TestClass1(); MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean(); mcfb = new MethodInvokingFactoryBean(); @@ -127,7 +127,7 @@ public class MethodInvokingFactoryBeanTests { } @Test - public void testGetObject() throws Exception { + void testGetObject() throws Exception { // singleton, non-static TestClass1 tc1 = new TestClass1(); MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean(); @@ -190,7 +190,7 @@ public class MethodInvokingFactoryBeanTests { } @Test - public void testArgumentConversion() throws Exception { + void testArgumentConversion() throws Exception { MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean(); mcfb.setTargetClass(TestClass1.class); mcfb.setTargetMethod("supertypes"); @@ -224,7 +224,7 @@ public class MethodInvokingFactoryBeanTests { } @Test - public void testInvokeWithNullArgument() throws Exception { + void testInvokeWithNullArgument() throws Exception { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetClass(TestClass1.class); methodInvoker.setTargetMethod("nullArgument"); @@ -234,7 +234,7 @@ public class MethodInvokingFactoryBeanTests { } @Test - public void testInvokeWithIntArgument() throws Exception { + void testInvokeWithIntArgument() throws Exception { ArgumentConvertingMethodInvoker methodInvoker = new ArgumentConvertingMethodInvoker(); methodInvoker.setTargetClass(TestClass1.class); methodInvoker.setTargetMethod("intArgument"); @@ -251,7 +251,7 @@ public class MethodInvokingFactoryBeanTests { } @Test - public void testInvokeWithIntArguments() throws Exception { + void testInvokeWithIntArguments() throws Exception { MethodInvokingBean methodInvoker = new MethodInvokingBean(); methodInvoker.setTargetClass(TestClass1.class); methodInvoker.setTargetMethod("intArguments"); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java index 7088a51b1a1..1dc9482f1cb 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -41,13 +41,13 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @author Rick Evans * @author Chris Beams */ -public class ObjectFactoryCreatingFactoryBeanTests { +class ObjectFactoryCreatingFactoryBeanTests { private DefaultListableBeanFactory beanFactory; @BeforeEach - public void setup() { + void setup() { this.beanFactory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml")); @@ -55,13 +55,13 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @AfterEach - public void close() { + void close() { this.beanFactory.setSerializationId(null); } @Test - public void testFactoryOperation() { + void testFactoryOperation() { FactoryTestBean testBean = beanFactory.getBean("factoryTestBean", FactoryTestBean.class); ObjectFactory objectFactory = testBean.getObjectFactory(); @@ -71,7 +71,7 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - public void testFactorySerialization() throws Exception { + void testFactorySerialization() throws Exception { FactoryTestBean testBean = beanFactory.getBean("factoryTestBean", FactoryTestBean.class); ObjectFactory objectFactory = testBean.getObjectFactory(); @@ -83,7 +83,7 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - public void testProviderOperation() { + void testProviderOperation() { ProviderTestBean testBean = beanFactory.getBean("providerTestBean", ProviderTestBean.class); Provider provider = testBean.getProvider(); @@ -93,7 +93,7 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - public void testProviderSerialization() throws Exception { + void testProviderSerialization() throws Exception { ProviderTestBean testBean = beanFactory.getBean("providerTestBean", ProviderTestBean.class); Provider provider = testBean.getProvider(); @@ -105,7 +105,7 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - public void testDoesNotComplainWhenTargetBeanNameRefersToSingleton() throws Exception { + void testDoesNotComplainWhenTargetBeanNameRefersToSingleton() throws Exception { final String targetBeanName = "singleton"; final String expectedSingleton = "Alicia Keys"; @@ -122,14 +122,14 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - public void testWhenTargetBeanNameIsNull() throws Exception { + void testWhenTargetBeanNameIsNull() { assertThatIllegalArgumentException().as( "'targetBeanName' property not set").isThrownBy( new ObjectFactoryCreatingFactoryBean()::afterPropertiesSet); } @Test - public void testWhenTargetBeanNameIsEmptyString() throws Exception { + void testWhenTargetBeanNameIsEmptyString() { ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean(); factory.setTargetBeanName(""); assertThatIllegalArgumentException().as( @@ -138,7 +138,7 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - public void testWhenTargetBeanNameIsWhitespacedString() throws Exception { + void testWhenTargetBeanNameIsWhitespacedString() { ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean(); factory.setTargetBeanName(" \t"); assertThatIllegalArgumentException().as( @@ -147,7 +147,7 @@ public class ObjectFactoryCreatingFactoryBeanTests { } @Test - public void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() { + void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() { assertThat(new ObjectFactoryCreatingFactoryBean().getObjectType()).as("Must be reporting that it creates ObjectFactory instances (as per class contract).").isEqualTo(ObjectFactory.class); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertiesFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertiesFactoryBeanTests.java index a04c2d768da..65c24698285 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertiesFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertiesFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -32,14 +32,14 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @author Chris Beams * @since 01.11.2003 */ -public class PropertiesFactoryBeanTests { +class PropertiesFactoryBeanTests { private static final Class CLASS = PropertiesFactoryBeanTests.class; private static final Resource TEST_PROPS = qualifiedResource(CLASS, "test.properties"); private static final Resource TEST_PROPS_XML = qualifiedResource(CLASS, "test.properties.xml"); @Test - public void testWithPropertiesFile() throws Exception { + void testWithPropertiesFile() throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setLocation(TEST_PROPS); pfb.afterPropertiesSet(); @@ -48,7 +48,7 @@ public class PropertiesFactoryBeanTests { } @Test - public void testWithPropertiesXmlFile() throws Exception { + void testWithPropertiesXmlFile() throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setLocation(TEST_PROPS_XML); pfb.afterPropertiesSet(); @@ -57,7 +57,7 @@ public class PropertiesFactoryBeanTests { } @Test - public void testWithLocalProperties() throws Exception { + void testWithLocalProperties() throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); Properties localProps = new Properties(); localProps.setProperty("key2", "value2"); @@ -68,7 +68,7 @@ public class PropertiesFactoryBeanTests { } @Test - public void testWithPropertiesFileAndLocalProperties() throws Exception { + void testWithPropertiesFileAndLocalProperties() throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setLocation(TEST_PROPS); Properties localProps = new Properties(); @@ -82,7 +82,7 @@ public class PropertiesFactoryBeanTests { } @Test - public void testWithPropertiesFileAndMultipleLocalProperties() throws Exception { + void testWithPropertiesFileAndMultipleLocalProperties() throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setLocation(TEST_PROPS); @@ -111,7 +111,7 @@ public class PropertiesFactoryBeanTests { } @Test - public void testWithPropertiesFileAndLocalPropertiesAndLocalOverride() throws Exception { + void testWithPropertiesFileAndLocalPropertiesAndLocalOverride() throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setLocation(TEST_PROPS); Properties localProps = new Properties(); @@ -126,7 +126,7 @@ public class PropertiesFactoryBeanTests { } @Test - public void testWithPrototype() throws Exception { + void testWithPrototype() throws Exception { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setSingleton(false); pfb.setLocation(TEST_PROPS); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPathFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPathFactoryBeanTests.java index b8c6c0c1a92..f082bd2c00f 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPathFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyPathFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -34,13 +34,13 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @author Chris Beams * @since 04.10.2004 */ -public class PropertyPathFactoryBeanTests { +class PropertyPathFactoryBeanTests { private static final Resource CONTEXT = qualifiedResource(PropertyPathFactoryBeanTests.class, "context.xml"); @Test - public void testPropertyPathFactoryBeanWithSingletonResult() { + void testPropertyPathFactoryBeanWithSingletonResult() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT); assertThat(xbf.getBean("propertyPath1")).isEqualTo(12); @@ -55,7 +55,7 @@ public class PropertyPathFactoryBeanTests { } @Test - public void testPropertyPathFactoryBeanWithPrototypeResult() { + void testPropertyPathFactoryBeanWithPrototypeResult() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT); assertThat(xbf.getType("tb.spouse")).isNull(); @@ -75,7 +75,7 @@ public class PropertyPathFactoryBeanTests { } @Test - public void testPropertyPathFactoryBeanWithNullResult() { + void testPropertyPathFactoryBeanWithNullResult() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT); assertThat(xbf.getType("tb.spouse.spouse")).isNull(); @@ -83,7 +83,7 @@ public class PropertyPathFactoryBeanTests { } @Test - public void testPropertyPathFactoryBeanAsInnerBean() { + void testPropertyPathFactoryBeanAsInnerBean() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT); TestBean spouse = (TestBean) xbf.getBean("otb.spouse"); @@ -94,14 +94,14 @@ public class PropertyPathFactoryBeanTests { } @Test - public void testPropertyPathFactoryBeanAsNullReference() { + void testPropertyPathFactoryBeanAsNullReference() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT); assertThat(xbf.getBean("tbWithNullReference", TestBean.class).getSpouse()).isNull(); } @Test - public void testPropertyPathFactoryBeanAsInnerNull() { + void testPropertyPathFactoryBeanAsInnerNull() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT); assertThat(xbf.getBean("tbWithInnerNull", TestBean.class).getSpouse()).isNull(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java index 41db2bd3058..6b473065a2f 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -23,7 +23,6 @@ import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.prefs.AbstractPreferences; -import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; import java.util.prefs.PreferencesFactory; @@ -61,7 +60,7 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @see PropertyPlaceholderConfigurerTests */ @SuppressWarnings("deprecation") -public class PropertyResourceConfigurerTests { +class PropertyResourceConfigurerTests { static { System.setProperty("java.util.prefs.PreferencesFactory", MockPreferencesFactory.class.getName()); @@ -76,7 +75,7 @@ public class PropertyResourceConfigurerTests { @Test - public void testPropertyOverrideConfigurer() { + void testPropertyOverrideConfigurer() { BeanDefinition def1 = BeanDefinitionBuilder.genericBeanDefinition(TestBean.class).getBeanDefinition(); factory.registerBeanDefinition("tb1", def1); @@ -116,7 +115,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithNestedProperty() { + void testPropertyOverrideConfigurerWithNestedProperty() { BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition(); factory.registerBeanDefinition("tb", def); @@ -134,7 +133,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithNestedPropertyAndDotInBeanName() { + void testPropertyOverrideConfigurerWithNestedPropertyAndDotInBeanName() { BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition(); factory.registerBeanDefinition("my.tb", def); @@ -153,7 +152,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithNestedMapPropertyAndDotInMapKey() { + void testPropertyOverrideConfigurerWithNestedMapPropertyAndDotInMapKey() { BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition(); factory.registerBeanDefinition("tb", def); @@ -171,7 +170,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithHeldProperties() { + void testPropertyOverrideConfigurerWithHeldProperties() { BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(PropertiesHolder.class).getBeanDefinition(); factory.registerBeanDefinition("tb", def); @@ -187,7 +186,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithPropertiesFile() { + void testPropertyOverrideConfigurerWithPropertiesFile() { BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition(); factory.registerBeanDefinition("tb", def); @@ -201,7 +200,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithInvalidPropertiesFile() { + void testPropertyOverrideConfigurerWithInvalidPropertiesFile() { BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition(); factory.registerBeanDefinition("tb", def); @@ -216,7 +215,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithPropertiesXmlFile() { + void testPropertyOverrideConfigurerWithPropertiesXmlFile() { BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition(); factory.registerBeanDefinition("tb", def); @@ -230,7 +229,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithConvertProperties() { + void testPropertyOverrideConfigurerWithConvertProperties() { BeanDefinition def = BeanDefinitionBuilder.genericBeanDefinition(IndexedTestBean.class).getBeanDefinition(); factory.registerBeanDefinition("tb", def); @@ -247,7 +246,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithInvalidKey() { + void testPropertyOverrideConfigurerWithInvalidKey() { factory.registerBeanDefinition("tb1", genericBeanDefinition(TestBean.class).getBeanDefinition()); factory.registerBeanDefinition("tb2", genericBeanDefinition(TestBean.class).getBeanDefinition()); @@ -282,7 +281,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyOverrideConfigurerWithIgnoreInvalidKeys() { + void testPropertyOverrideConfigurerWithIgnoreInvalidKeys() { factory.registerBeanDefinition("tb1", genericBeanDefinition(TestBean.class).getBeanDefinition()); factory.registerBeanDefinition("tb2", genericBeanDefinition(TestBean.class).getBeanDefinition()); @@ -315,12 +314,12 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurer() { + void testPropertyPlaceholderConfigurer() { doTestPropertyPlaceholderConfigurer(false); } @Test - public void testPropertyPlaceholderConfigurerWithParentChildSeparation() { + void testPropertyPlaceholderConfigurerWithParentChildSeparation() { doTestPropertyPlaceholderConfigurer(true); } @@ -427,7 +426,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithSystemPropertyFallback() { + void testPropertyPlaceholderConfigurerWithSystemPropertyFallback() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("country", "${os.name}").getBeanDefinition()); @@ -439,7 +438,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithSystemPropertyNotUsed() { + void testPropertyPlaceholderConfigurerWithSystemPropertyNotUsed() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("country", "${os.name}").getBeanDefinition()); @@ -454,7 +453,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithOverridingSystemProperty() { + void testPropertyPlaceholderConfigurerWithOverridingSystemProperty() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("country", "${os.name}").getBeanDefinition()); @@ -470,7 +469,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithUnresolvableSystemProperty() { + void testPropertyPlaceholderConfigurerWithUnresolvableSystemProperty() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("touchy", "${user.dir}").getBeanDefinition()); PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); @@ -481,7 +480,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithUnresolvablePlaceholder() { + void testPropertyPlaceholderConfigurerWithUnresolvablePlaceholder() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${ref}").getBeanDefinition()); PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); @@ -491,7 +490,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithIgnoreUnresolvablePlaceholder() { + void testPropertyPlaceholderConfigurerWithIgnoreUnresolvablePlaceholder() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${ref}").getBeanDefinition()); @@ -504,7 +503,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithEmptyStringAsNull() { + void testPropertyPlaceholderConfigurerWithEmptyStringAsNull() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "").getBeanDefinition()); @@ -517,7 +516,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithEmptyStringInPlaceholderAsNull() { + void testPropertyPlaceholderConfigurerWithEmptyStringInPlaceholderAsNull() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${ref}").getBeanDefinition()); @@ -533,7 +532,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithNestedPlaceholderInKey() { + void testPropertyPlaceholderConfigurerWithNestedPlaceholderInKey() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${my${key}key}").getBeanDefinition()); @@ -549,7 +548,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithPlaceholderInAlias() { + void testPropertyPlaceholderConfigurerWithPlaceholderInAlias() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class).getBeanDefinition()); factory.registerAlias("tb", "${alias}"); @@ -565,7 +564,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithSelfReferencingPlaceholderInAlias() { + void testPropertyPlaceholderConfigurerWithSelfReferencingPlaceholderInAlias() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class).getBeanDefinition()); factory.registerAlias("tb", "${alias}"); @@ -581,7 +580,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithCircularReference() { + void testPropertyPlaceholderConfigurerWithCircularReference() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("age", "${age}") .addPropertyValue("name", "name${var}") @@ -598,7 +597,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithDefaultProperties() { + void testPropertyPlaceholderConfigurerWithDefaultProperties() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("touchy", "${test}").getBeanDefinition()); @@ -613,7 +612,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithInlineDefault() { + void testPropertyPlaceholderConfigurerWithInlineDefault() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("touchy", "${test:mytest}").getBeanDefinition()); @@ -625,7 +624,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPropertyPlaceholderConfigurerWithAliases() { + void testPropertyPlaceholderConfigurerWithAliases() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("touchy", "${test}").getBeanDefinition()); @@ -649,7 +648,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPreferencesPlaceholderConfigurer() { + void testPreferencesPlaceholderConfigurer() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${myName}") .addPropertyValue("age", "${myAge}") @@ -676,7 +675,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPreferencesPlaceholderConfigurerWithCustomTreePaths() { + void testPreferencesPlaceholderConfigurerWithCustomTreePaths() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${myName}") .addPropertyValue("age", "${myAge}") @@ -705,7 +704,7 @@ public class PropertyResourceConfigurerTests { } @Test - public void testPreferencesPlaceholderConfigurerWithPathInPlaceholder() { + void testPreferencesPlaceholderConfigurerWithPathInPlaceholder() { factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class) .addPropertyValue("name", "${mypath/myName}") .addPropertyValue("age", "${myAge}") @@ -812,16 +811,16 @@ public class PropertyResourceConfigurerTests { } @Override - protected void removeNodeSpi() throws BackingStoreException { + protected void removeNodeSpi() { } @Override - protected String[] keysSpi() throws BackingStoreException { + protected String[] keysSpi() { return StringUtils.toStringArray(values.keySet()); } @Override - protected String[] childrenNamesSpi() throws BackingStoreException { + protected String[] childrenNamesSpi() { return StringUtils.toStringArray(children.keySet()); } @@ -836,11 +835,11 @@ public class PropertyResourceConfigurerTests { } @Override - protected void syncSpi() throws BackingStoreException { + protected void syncSpi() { } @Override - protected void flushSpi() throws BackingStoreException { + protected void flushSpi() { } } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java index 0a4d8fe409d..72909c265eb 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -40,17 +40,17 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.ge * @author Rick Evans * @author Chris Beams */ -public class ServiceLocatorFactoryBeanTests { +class ServiceLocatorFactoryBeanTests { private DefaultListableBeanFactory bf; @BeforeEach - public void setUp() { + void setUp() { bf = new DefaultListableBeanFactory(); } @Test - public void testNoArgGetter() { + void testNoArgGetter() { bf.registerBeanDefinition("testService", genericBeanDefinition(TestService.class).getBeanDefinition()); bf.registerBeanDefinition("factory", genericBeanDefinition(ServiceLocatorFactoryBean.class) @@ -63,7 +63,7 @@ public class ServiceLocatorFactoryBeanTests { } @Test - public void testErrorOnTooManyOrTooFew() throws Exception { + void testErrorOnTooManyOrTooFew() { bf.registerBeanDefinition("testService", genericBeanDefinition(TestService.class).getBeanDefinition()); bf.registerBeanDefinition("testServiceInstance2", genericBeanDefinition(TestService.class).getBeanDefinition()); bf.registerBeanDefinition("factory", @@ -87,7 +87,7 @@ public class ServiceLocatorFactoryBeanTests { } @Test - public void testErrorOnTooManyOrTooFewWithCustomServiceLocatorException() { + void testErrorOnTooManyOrTooFewWithCustomServiceLocatorException() { bf.registerBeanDefinition("testService", genericBeanDefinition(TestService.class).getBeanDefinition()); bf.registerBeanDefinition("testServiceInstance2", genericBeanDefinition(TestService.class).getBeanDefinition()); bf.registerBeanDefinition("factory", @@ -116,7 +116,7 @@ public class ServiceLocatorFactoryBeanTests { } @Test - public void testStringArgGetter() throws Exception { + void testStringArgGetter() throws Exception { bf.registerBeanDefinition("testService", genericBeanDefinition(TestService.class).getBeanDefinition()); bf.registerBeanDefinition("factory", genericBeanDefinition(ServiceLocatorFactoryBean.class) @@ -205,13 +205,13 @@ public class ServiceLocatorFactoryBeanTests { } @Test - public void testNoServiceLocatorInterfaceSupplied() throws Exception { + void testNoServiceLocatorInterfaceSupplied() { assertThatIllegalArgumentException().isThrownBy( new ServiceLocatorFactoryBean()::afterPropertiesSet); } @Test - public void testWhenServiceLocatorInterfaceIsNotAnInterfaceType() throws Exception { + void testWhenServiceLocatorInterfaceIsNotAnInterfaceType() { ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean(); factory.setServiceLocatorInterface(getClass()); assertThatIllegalArgumentException().isThrownBy( @@ -220,7 +220,7 @@ public class ServiceLocatorFactoryBeanTests { } @Test - public void testWhenServiceLocatorExceptionClassToExceptionTypeWithOnlyNoArgCtor() throws Exception { + void testWhenServiceLocatorExceptionClassToExceptionTypeWithOnlyNoArgCtor() { ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean(); assertThatIllegalArgumentException().isThrownBy(() -> factory.setServiceLocatorExceptionClass(ExceptionClassWithOnlyZeroArgCtor.class)); @@ -229,7 +229,7 @@ public class ServiceLocatorFactoryBeanTests { @Test @SuppressWarnings({ "unchecked", "rawtypes" }) - public void testWhenServiceLocatorExceptionClassIsNotAnExceptionSubclass() throws Exception { + public void testWhenServiceLocatorExceptionClassIsNotAnExceptionSubclass() { ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean(); assertThatIllegalArgumentException().isThrownBy(() -> factory.setServiceLocatorExceptionClass((Class) getClass())); @@ -237,7 +237,7 @@ public class ServiceLocatorFactoryBeanTests { } @Test - public void testWhenServiceLocatorMethodCalledWithTooManyParameters() throws Exception { + void testWhenServiceLocatorMethodCalledWithTooManyParameters() { ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean(); factory.setServiceLocatorInterface(ServiceLocatorInterfaceWithExtraNonCompliantMethod.class); factory.afterPropertiesSet(); @@ -247,7 +247,7 @@ public class ServiceLocatorFactoryBeanTests { } @Test - public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception { + void testRequiresListableBeanFactoryAndChokesOnAnythingElse() { BeanFactory beanFactory = mock(); try { ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java index 21d20725745..48889787608 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/SimpleScopeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -37,13 +37,13 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @author Juergen Hoeller * @author Chris Beams */ -public class SimpleScopeTests { +class SimpleScopeTests { private DefaultListableBeanFactory beanFactory; @BeforeEach - public void setup() { + void setup() { beanFactory = new DefaultListableBeanFactory(); Scope scope = new NoOpScope() { private int index; @@ -73,7 +73,7 @@ public class SimpleScopeTests { @Test - public void testCanGetScopedObject() { + void testCanGetScopedObject() { TestBean tb1 = (TestBean) beanFactory.getBean("usesScope"); TestBean tb2 = (TestBean) beanFactory.getBean("usesScope"); assertThat(tb2).isNotSameAs(tb1); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlMapFactoryBeanTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlMapFactoryBeanTests.java index e0c9b89f7cd..1f9dcc7709d 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlMapFactoryBeanTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlMapFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -38,20 +38,20 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Dave Syer * @author Juergen Hoeller */ -public class YamlMapFactoryBeanTests { +class YamlMapFactoryBeanTests { private final YamlMapFactoryBean factory = new YamlMapFactoryBean(); @Test - public void testSetIgnoreResourceNotFound() { + void testSetIgnoreResourceNotFound() { this.factory.setResolutionMethod(YamlMapFactoryBean.ResolutionMethod.OVERRIDE_AND_IGNORE); this.factory.setResources(new FileSystemResource("non-exsitent-file.yml")); assertThat(this.factory.getObject()).isEmpty(); } @Test - public void testSetBarfOnResourceNotFound() { + void testSetBarfOnResourceNotFound() { assertThatIllegalStateException().isThrownBy(() -> { this.factory.setResources(new FileSystemResource("non-exsitent-file.yml")); this.factory.getObject().size(); @@ -59,14 +59,14 @@ public class YamlMapFactoryBeanTests { } @Test - public void testGetObject() { + void testGetObject() { this.factory.setResources(new ByteArrayResource("foo: bar".getBytes())); assertThat(this.factory.getObject()).hasSize(1); } @SuppressWarnings("unchecked") @Test - public void testOverrideAndRemoveDefaults() { + void testOverrideAndRemoveDefaults() { this.factory.setResources(new ByteArrayResource("foo:\n bar: spam".getBytes()), new ByteArrayResource("foo:\n spam: bar".getBytes())); @@ -75,7 +75,7 @@ public class YamlMapFactoryBeanTests { } @Test - public void testFirstFound() { + void testFirstFound() { this.factory.setResolutionMethod(YamlProcessor.ResolutionMethod.FIRST_FOUND); this.factory.setResources(new AbstractResource() { @Override @@ -92,7 +92,7 @@ public class YamlMapFactoryBeanTests { } @Test - public void testMapWithPeriodsInKey() { + void testMapWithPeriodsInKey() { this.factory.setResources(new ByteArrayResource("foo:\n ? key1.key2\n : value".getBytes())); Map map = this.factory.getObject(); @@ -107,7 +107,7 @@ public class YamlMapFactoryBeanTests { } @Test - public void testMapWithIntegerValue() { + void testMapWithIntegerValue() { this.factory.setResources(new ByteArrayResource("foo:\n ? key1.key2\n : 3".getBytes())); Map map = this.factory.getObject(); @@ -122,7 +122,7 @@ public class YamlMapFactoryBeanTests { } @Test - public void testDuplicateKey() { + void testDuplicateKey() { this.factory.setResources(new ByteArrayResource("mymap:\n foo: bar\nmymap:\n bar: foo".getBytes())); assertThatExceptionOfType(DuplicateKeyException.class).isThrownBy(() -> this.factory.getObject().get("mymap")); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java index 1bbc928b0fa..d90186150dd 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/config/YamlProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -142,7 +142,7 @@ class YamlProcessorTests { @Test @SuppressWarnings("unchecked") - void standardTypesSupportedByDefault() throws Exception { + void standardTypesSupportedByDefault() { setYaml("value: !!set\n ? first\n ? second"); this.processor.process((properties, map) -> { assertThat(properties).containsExactly(entry("value[0]", "first"), entry("value[1]", "second")); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/ConstructorArgumentEntryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/ConstructorArgumentEntryTests.java index 9e3155dc459..14070f8c5ce 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/ConstructorArgumentEntryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/ConstructorArgumentEntryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -26,10 +26,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rick Evans * @author Chris Beams */ -public class ConstructorArgumentEntryTests { +class ConstructorArgumentEntryTests { @Test - public void testCtorBailsOnNegativeCtorIndexArgument() { + void testCtorBailsOnNegativeCtorIndexArgument() { assertThatIllegalArgumentException().isThrownBy(() -> new ConstructorArgumentEntry(-1)); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java index 82c8dd704ee..e5a9a9162be 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/CustomProblemReporterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -34,7 +34,7 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie * @author Chris Beams * @since 2.0 */ -public class CustomProblemReporterTests { +class CustomProblemReporterTests { private CollatingProblemReporter problemReporter; @@ -44,7 +44,7 @@ public class CustomProblemReporterTests { @BeforeEach - public void setup() { + void setup() { this.problemReporter = new CollatingProblemReporter(); this.beanFactory = new DefaultListableBeanFactory(); this.reader = new XmlBeanDefinitionReader(this.beanFactory); @@ -53,7 +53,7 @@ public class CustomProblemReporterTests { @Test - public void testErrorsAreCollated() { + void testErrorsAreCollated() { this.reader.loadBeanDefinitions(qualifiedResource(CustomProblemReporterTests.class, "context.xml")); assertThat(this.problemReporter.getErrors()).as("Incorrect number of errors collated").hasSize(4); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java index 65527eb9b27..0f12880dc97 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/FailFastProblemReporterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -32,10 +32,10 @@ import static org.mockito.Mockito.verify; * @author Juergen Hoeller * @author Chris Beams */ -public class FailFastProblemReporterTests { +class FailFastProblemReporterTests { @Test - public void testError() throws Exception { + void testError() { FailFastProblemReporter reporter = new FailFastProblemReporter(); assertThatExceptionOfType(BeanDefinitionParsingException.class).isThrownBy(() -> reporter.error(new Problem("VGER", new Location(new DescriptiveResource("here")), @@ -43,7 +43,7 @@ public class FailFastProblemReporterTests { } @Test - public void testWarn() throws Exception { + void testWarn() { Problem problem = new Problem("VGER", new Location(new DescriptiveResource("here")), null, new IllegalArgumentException()); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/NullSourceExtractorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/NullSourceExtractorTests.java index 844c667335c..4f6972e38f6 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/NullSourceExtractorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/NullSourceExtractorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -24,17 +24,17 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rick Evans * @author Chris Beams */ -public class NullSourceExtractorTests { +class NullSourceExtractorTests { @Test - public void testPassThroughContract() throws Exception { + void testPassThroughContract() { Object source = new Object(); Object extractedSource = new NullSourceExtractor().extractSource(source, null); assertThat(extractedSource).as("The contract of NullSourceExtractor states that the extraction *always* return null").isNull(); } @Test - public void testPassThroughContractEvenWithNull() throws Exception { + void testPassThroughContractEvenWithNull() { Object extractedSource = new NullSourceExtractor().extractSource(null, null); assertThat(extractedSource).as("The contract of NullSourceExtractor states that the extraction *always* return null").isNull(); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/ParseStateTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/ParseStateTests.java index ce6a3aaa7df..2a61a95fc56 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/ParseStateTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/ParseStateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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,10 +25,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Chris Beams * @since 2.0 */ -public class ParseStateTests { +class ParseStateTests { @Test - public void testSimple() throws Exception { + void testSimple() { MockEntry entry = new MockEntry(); ParseState parseState = new ParseState(); @@ -39,7 +39,7 @@ public class ParseStateTests { } @Test - public void testNesting() throws Exception { + void testNesting() { MockEntry one = new MockEntry(); MockEntry two = new MockEntry(); MockEntry three = new MockEntry(); @@ -59,7 +59,7 @@ public class ParseStateTests { } @Test - public void testSnapshot() throws Exception { + void testSnapshot() { MockEntry entry = new MockEntry(); ParseState original = new ParseState(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractorTests.java index 21dbc8b5746..89fad7b2c48 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -26,10 +26,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rick Evans * @author Chris Beams */ -public class PassThroughSourceExtractorTests { +class PassThroughSourceExtractorTests { @Test - public void testPassThroughContract() throws Exception { + void testPassThroughContract() { Object source = new Object(); Object extractedSource = new PassThroughSourceExtractor().extractSource(source, null); assertThat(extractedSource).as("The contract of PassThroughSourceExtractor states that the supplied " + @@ -37,7 +37,7 @@ public class PassThroughSourceExtractorTests { } @Test - public void testPassThroughContractEvenWithNull() throws Exception { + void testPassThroughContractEvenWithNull() { Object extractedSource = new PassThroughSourceExtractor().extractSource(null, null); assertThat(extractedSource).as("The contract of PassThroughSourceExtractor states that the supplied " + "source object *must* be returned as-is (even if null)").isNull(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/PropertyEntryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/PropertyEntryTests.java index 084fb1f5a74..44e111c553e 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/parsing/PropertyEntryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/parsing/PropertyEntryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -26,22 +26,22 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rick Evans * @author Chris Beams */ -public class PropertyEntryTests { +class PropertyEntryTests { @Test - public void testCtorBailsOnNullPropertyNameArgument() throws Exception { + void testCtorBailsOnNullPropertyNameArgument() { assertThatIllegalArgumentException().isThrownBy(() -> new PropertyEntry(null)); } @Test - public void testCtorBailsOnEmptyPropertyNameArgument() throws Exception { + void testCtorBailsOnEmptyPropertyNameArgument() { assertThatIllegalArgumentException().isThrownBy(() -> new PropertyEntry("")); } @Test - public void testCtorBailsOnWhitespacedPropertyNameArgument() throws Exception { + void testCtorBailsOnWhitespacedPropertyNameArgument() { assertThatIllegalArgumentException().isThrownBy(() -> new PropertyEntry("\t ")); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java index e7e04d7390d..c711c1cdd46 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/AutowireUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen * @author Loïc Ledoyen */ -public class AutowireUtilsTests { +class AutowireUtilsTests { @Test - public void genericMethodReturnTypes() { + void genericMethodReturnTypes() { Method notParameterized = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterized"); Object actual = AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterized, new Object[0], getClass().getClassLoader()); assertThat(actual).isEqualTo(String.class); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionTests.java index 9f8e3a45a8f..63ebcc9caf9 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -26,10 +26,10 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Juergen Hoeller */ -public class BeanDefinitionTests { +class BeanDefinitionTests { @Test - public void beanDefinitionEquality() { + void beanDefinitionEquality() { RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setAbstract(true); bd.setLazyInit(true); @@ -46,7 +46,7 @@ public class BeanDefinitionTests { } @Test - public void beanDefinitionEqualityWithPropertyValues() { + void beanDefinitionEqualityWithPropertyValues() { RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.getPropertyValues().add("name", "myName"); bd.getPropertyValues().add("age", "99"); @@ -64,7 +64,7 @@ public class BeanDefinitionTests { } @Test - public void beanDefinitionEqualityWithConstructorArguments() { + void beanDefinitionEqualityWithConstructorArguments() { RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.getConstructorArgumentValues().addGenericArgumentValue("test"); bd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5); @@ -82,7 +82,7 @@ public class BeanDefinitionTests { } @Test - public void beanDefinitionEqualityWithTypedConstructorArguments() { + void beanDefinitionEqualityWithTypedConstructorArguments() { RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.getConstructorArgumentValues().addGenericArgumentValue("test", "int"); bd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5, "long"); @@ -101,7 +101,7 @@ public class BeanDefinitionTests { } @Test - public void genericBeanDefinitionEquality() { + void genericBeanDefinitionEquality() { GenericBeanDefinition bd = new GenericBeanDefinition(); bd.setParentName("parent"); bd.setScope("request"); @@ -130,7 +130,7 @@ public class BeanDefinitionTests { } @Test - public void beanDefinitionHolderEquality() { + void beanDefinitionHolderEquality() { RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setAbstract(true); bd.setLazyInit(true); @@ -149,7 +149,7 @@ public class BeanDefinitionTests { } @Test - public void beanDefinitionMerging() { + void beanDefinitionMerging() { RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.getConstructorArgumentValues().addGenericArgumentValue("test"); bd.getConstructorArgumentValues().addIndexedArgumentValue(1, 5); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java index 2e404d886c3..986f7dd450e 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactoryGenericsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -564,8 +564,7 @@ class BeanFactoryGenericsTests { new ClassPathResource("genericBeanTests.xml", getClass())); GenericIntegerBean gb = (GenericIntegerBean) bf.getBean("integerBean"); assertThat(gb.getGenericProperty()).isEqualTo(10); - assertThat(gb.getGenericListProperty()).element(0).isEqualTo(20); - assertThat(gb.getGenericListProperty()).element(1).isEqualTo(30); + assertThat(gb.getGenericListProperty()).containsExactly(20, 30); } @Test @@ -575,8 +574,8 @@ class BeanFactoryGenericsTests { new ClassPathResource("genericBeanTests.xml", getClass())); GenericSetOfIntegerBean gb = (GenericSetOfIntegerBean) bf.getBean("setOfIntegerBean"); assertThat(gb.getGenericProperty()).element(0).isEqualTo(10); - assertThat(gb.getGenericListProperty().get(0)).element(0).isEqualTo(20); - assertThat(gb.getGenericListProperty().get(1)).element(0).isEqualTo(30); + assertThat(gb.getGenericListProperty().get(0)).containsExactly(20); + assertThat(gb.getGenericListProperty().get(1)).containsExactly(30); } @Test diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactorySupplierTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactorySupplierTests.java index d147b24d350..c2e49654c57 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactorySupplierTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/BeanFactorySupplierTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Phillip Webb * @author Juergen Hoeller */ -public class BeanFactorySupplierTests { +class BeanFactorySupplierTests { @Test void getBeanWhenUsingRegularSupplier() { diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/ConstructorResolverAotTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/ConstructorResolverAotTests.java index 434a232b461..144bc37564f 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/ConstructorResolverAotTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/ConstructorResolverAotTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -441,7 +441,7 @@ class ConstructorResolverAotTests { } @Test - void beanDefinitionWithMultiConstructorSimilarArgumentsAndNullValueForSpecificArgument() throws NoSuchMethodException { + void beanDefinitionWithMultiConstructorSimilarArgumentsAndNullValueForSpecificArgument() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); BeanDefinition beanDefinition = BeanDefinitionBuilder .rootBeanDefinition(MultiConstructorSimilarArgumentsSample.class) diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/DefinitionMetadataEqualsHashCodeTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/DefinitionMetadataEqualsHashCodeTests.java index 36c0c4be39c..67d8abb958b 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/DefinitionMetadataEqualsHashCodeTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/DefinitionMetadataEqualsHashCodeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Sam Brannen */ @SuppressWarnings("serial") -public class DefinitionMetadataEqualsHashCodeTests { +class DefinitionMetadataEqualsHashCodeTests { @Test - public void rootBeanDefinition() { + void rootBeanDefinition() { RootBeanDefinition master = new RootBeanDefinition(TestBean.class); RootBeanDefinition equal = new RootBeanDefinition(TestBean.class); RootBeanDefinition notEqual = new RootBeanDefinition(String.class); @@ -53,7 +53,7 @@ public class DefinitionMetadataEqualsHashCodeTests { * @see SPR-11420 */ @Test - public void rootBeanDefinitionAndMethodOverridesWithDifferentOverloadedValues() { + void rootBeanDefinitionAndMethodOverridesWithDifferentOverloadedValues() { RootBeanDefinition master = new RootBeanDefinition(TestBean.class); RootBeanDefinition equal = new RootBeanDefinition(TestBean.class); @@ -73,7 +73,7 @@ public class DefinitionMetadataEqualsHashCodeTests { } @Test - public void childBeanDefinition() { + void childBeanDefinition() { ChildBeanDefinition master = new ChildBeanDefinition("foo"); ChildBeanDefinition equal = new ChildBeanDefinition("foo"); ChildBeanDefinition notEqual = new ChildBeanDefinition("bar"); @@ -88,7 +88,7 @@ public class DefinitionMetadataEqualsHashCodeTests { } @Test - public void runtimeBeanReference() { + void runtimeBeanReference() { RuntimeBeanReference master = new RuntimeBeanReference("name"); RuntimeBeanReference equal = new RuntimeBeanReference("name"); RuntimeBeanReference notEqual = new RuntimeBeanReference("someOtherName"); @@ -104,7 +104,7 @@ public class DefinitionMetadataEqualsHashCodeTests { definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); // definition.getConstructorArgumentValues().addGenericArgumentValue("foo"); definition.setDependencyCheck(AbstractBeanDefinition.DEPENDENCY_CHECK_OBJECTS); - definition.setDependsOn(new String[] { "foo", "bar" }); + definition.setDependsOn("foo", "bar"); definition.setDestroyMethodName("destroy"); definition.setEnforceDestroyMethod(false); definition.setEnforceInitMethod(true); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/LookupMethodTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/LookupMethodTests.java index ca43b11db77..9e805c9408c 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/LookupMethodTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/LookupMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -30,13 +30,13 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Karl Pietrzak * @author Juergen Hoeller */ -public class LookupMethodTests { +class LookupMethodTests { private DefaultListableBeanFactory beanFactory; @BeforeEach - public void setup() { + void setup() { beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); reader.loadBeanDefinitions(new ClassPathResource("lookupMethodTests.xml", getClass())); @@ -44,7 +44,7 @@ public class LookupMethodTests { @Test - public void testWithoutConstructorArg() { + void testWithoutConstructorArg() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); assertThat(bean).isNotNull(); Object expected = bean.get(); @@ -52,7 +52,7 @@ public class LookupMethodTests { } @Test - public void testWithOverloadedArg() { + void testWithOverloadedArg() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); assertThat(bean).isNotNull(); TestBean expected = bean.get("haha"); @@ -61,7 +61,7 @@ public class LookupMethodTests { } @Test - public void testWithOneConstructorArg() { + void testWithOneConstructorArg() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); assertThat(bean).isNotNull(); TestBean expected = bean.getOneArgument("haha"); @@ -70,7 +70,7 @@ public class LookupMethodTests { } @Test - public void testWithTwoConstructorArg() { + void testWithTwoConstructorArg() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); assertThat(bean).isNotNull(); TestBean expected = bean.getTwoArguments("haha", 72); @@ -80,7 +80,7 @@ public class LookupMethodTests { } @Test - public void testWithThreeArgsShouldFail() { + void testWithThreeArgsShouldFail() { AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean"); assertThat(bean).isNotNull(); assertThatExceptionOfType(AbstractMethodError.class).as("does not have a three arg constructor") @@ -88,7 +88,7 @@ public class LookupMethodTests { } @Test - public void testWithOverriddenLookupMethod() { + void testWithOverriddenLookupMethod() { AbstractBean bean = (AbstractBean) beanFactory.getBean("extendedBean"); assertThat(bean).isNotNull(); TestBean expected = bean.getOneArgument("haha"); @@ -98,7 +98,7 @@ public class LookupMethodTests { } @Test - public void testWithGenericBean() { + void testWithGenericBean() { RootBeanDefinition bd = new RootBeanDefinition(NumberBean.class); bd.getMethodOverrides().addOverride(new LookupOverride("getDoubleStore", null)); bd.getMethodOverrides().addOverride(new LookupOverride("getFloatStore", null)); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedMapTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedMapTests.java index a7929bf30d9..6f98e33cee4 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedMapTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedMapTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Sam Brannen */ @SuppressWarnings({ "rawtypes", "unchecked" }) -public class ManagedMapTests { +class ManagedMapTests { @Test - public void mergeSunnyDay() { + void mergeSunnyDay() { ManagedMap parent = ManagedMap.ofEntries(Map.entry("one", "one"), Map.entry("two", "two")); ManagedMap child = ManagedMap.ofEntries(Map.entry("tree", "three")); @@ -43,14 +43,14 @@ public class ManagedMapTests { } @Test - public void mergeWithNullParent() { + void mergeWithNullParent() { ManagedMap child = new ManagedMap(); child.setMergeEnabled(true); assertThat(child.merge(null)).isSameAs(child); } @Test - public void mergeWithNonCompatibleParentType() { + void mergeWithNonCompatibleParentType() { ManagedMap map = new ManagedMap(); map.setMergeEnabled(true); assertThatIllegalArgumentException().isThrownBy(() -> @@ -58,13 +58,13 @@ public class ManagedMapTests { } @Test - public void mergeNotAllowedWhenMergeNotEnabled() { + void mergeNotAllowedWhenMergeNotEnabled() { assertThatIllegalStateException().isThrownBy(() -> new ManagedMap().merge(null)); } @Test - public void mergeEmptyChild() { + void mergeEmptyChild() { ManagedMap parent = ManagedMap.ofEntries(Map.entry("one", "one"), Map.entry("two", "two")); ManagedMap child = new ManagedMap(); @@ -74,7 +74,7 @@ public class ManagedMapTests { } @Test - public void mergeChildValuesOverrideTheParents() { + void mergeChildValuesOverrideTheParents() { ManagedMap parent = ManagedMap.ofEntries(Map.entry("one", "one"), Map.entry("two", "two")); ManagedMap child = ManagedMap.ofEntries(Map.entry("one", "fork")); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedPropertiesTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedPropertiesTests.java index 25739ac772a..7a2efffda04 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedPropertiesTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/ManagedPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; * @author Sam Brannen */ @SuppressWarnings("rawtypes") -public class ManagedPropertiesTests { +class ManagedPropertiesTests { @Test @SuppressWarnings("unchecked") @@ -46,14 +46,14 @@ public class ManagedPropertiesTests { } @Test - public void mergeWithNullParent() { + void mergeWithNullParent() { ManagedProperties child = new ManagedProperties(); child.setMergeEnabled(true); assertThat(child.merge(null)).isSameAs(child); } @Test - public void mergeWithNonCompatibleParentType() { + void mergeWithNonCompatibleParentType() { ManagedProperties map = new ManagedProperties(); map.setMergeEnabled(true); assertThatIllegalArgumentException().isThrownBy(() -> @@ -61,7 +61,7 @@ public class ManagedPropertiesTests { } @Test - public void mergeNotAllowedWhenMergeNotEnabled() { + void mergeNotAllowedWhenMergeNotEnabled() { ManagedProperties map = new ManagedProperties(); assertThatIllegalStateException().isThrownBy(() -> map.merge(null)); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/QualifierAnnotationAutowireBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/QualifierAnnotationAutowireBeanFactoryTests.java index fe190c8b9f5..f9ecb7e6c7d 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/QualifierAnnotationAutowireBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/QualifierAnnotationAutowireBeanFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -37,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Mark Fisher * @author Juergen Hoeller */ -public class QualifierAnnotationAutowireBeanFactoryTests { +class QualifierAnnotationAutowireBeanFactoryTests { private static final String JUERGEN = "juergen"; @@ -45,7 +45,7 @@ public class QualifierAnnotationAutowireBeanFactoryTests { @Test - public void testAutowireCandidateDefaultWithIrrelevantDescriptor() throws Exception { + void testAutowireCandidateDefaultWithIrrelevantDescriptor() throws Exception { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); ConstructorArgumentValues cavs = new ConstructorArgumentValues(); cavs.addGenericArgumentValue(JUERGEN); @@ -59,7 +59,7 @@ public class QualifierAnnotationAutowireBeanFactoryTests { } @Test - public void testAutowireCandidateExplicitlyFalseWithIrrelevantDescriptor() throws Exception { + void testAutowireCandidateExplicitlyFalseWithIrrelevantDescriptor() throws Exception { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); ConstructorArgumentValues cavs = new ConstructorArgumentValues(); cavs.addGenericArgumentValue(JUERGEN); @@ -75,7 +75,7 @@ public class QualifierAnnotationAutowireBeanFactoryTests { @Disabled @Test - public void testAutowireCandidateWithFieldDescriptor() throws Exception { + void testAutowireCandidateWithFieldDescriptor() throws Exception { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); cavs1.addGenericArgumentValue(JUERGEN); @@ -99,7 +99,7 @@ public class QualifierAnnotationAutowireBeanFactoryTests { } @Test - public void testAutowireCandidateExplicitlyFalseWithFieldDescriptor() throws Exception { + void testAutowireCandidateExplicitlyFalseWithFieldDescriptor() throws Exception { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); ConstructorArgumentValues cavs = new ConstructorArgumentValues(); cavs.addGenericArgumentValue(JUERGEN); @@ -117,7 +117,7 @@ public class QualifierAnnotationAutowireBeanFactoryTests { } @Test - public void testAutowireCandidateWithShortClassName() throws Exception { + void testAutowireCandidateWithShortClassName() throws Exception { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); ConstructorArgumentValues cavs = new ConstructorArgumentValues(); cavs.addGenericArgumentValue(JUERGEN); @@ -135,7 +135,7 @@ public class QualifierAnnotationAutowireBeanFactoryTests { @Disabled @Test - public void testAutowireCandidateWithConstructorDescriptor() throws Exception { + void testAutowireCandidateWithConstructorDescriptor() throws Exception { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); cavs1.addGenericArgumentValue(JUERGEN); @@ -157,7 +157,7 @@ public class QualifierAnnotationAutowireBeanFactoryTests { @Disabled @Test - public void testAutowireCandidateWithMethodDescriptor() throws Exception { + void testAutowireCandidateWithMethodDescriptor() throws Exception { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); cavs1.addGenericArgumentValue(JUERGEN); @@ -187,7 +187,7 @@ public class QualifierAnnotationAutowireBeanFactoryTests { } @Test - public void testAutowireCandidateWithMultipleCandidatesDescriptor() throws Exception { + void testAutowireCandidateWithMultipleCandidatesDescriptor() throws Exception { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); ConstructorArgumentValues cavs1 = new ConstructorArgumentValues(); cavs1.addGenericArgumentValue(JUERGEN); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/Spr8954Tests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/Spr8954Tests.java index 54ff586495e..c82af81bbc0 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/Spr8954Tests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/Spr8954Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -40,19 +40,19 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Chris Beams * @author Oliver Gierke */ -public class Spr8954Tests { +class Spr8954Tests { private DefaultListableBeanFactory bf; @BeforeEach - public void setUp() { + void setUp() { bf = new DefaultListableBeanFactory(); bf.registerBeanDefinition("foo", new RootBeanDefinition(FooFactoryBean.class)); bf.addBeanPostProcessor(new PredictingBPP()); } @Test - public void repro() { + void repro() { assertThat(bf.getBean("foo")).isInstanceOf(Foo.class); assertThat(bf.getBean("&foo")).isInstanceOf(FooFactoryBean.class); assertThat(bf.isTypeMatch("&foo", FactoryBean.class)).isTrue(); @@ -66,7 +66,7 @@ public class Spr8954Tests { } @Test - public void findsBeansByTypeIfNotInstantiated() { + void findsBeansByTypeIfNotInstantiated() { assertThat(bf.isTypeMatch("&foo", FactoryBean.class)).isTrue(); @SuppressWarnings("rawtypes") @@ -81,7 +81,7 @@ public class Spr8954Tests { * SPR-10517 */ @Test - public void findsFactoryBeanNameByTypeWithoutInstantiation() { + void findsFactoryBeanNameByTypeWithoutInstantiation() { String[] names = bf.getBeanNamesForType(AnInterface.class, false, false); assertThat(Arrays.asList(names)).contains("&foo"); @@ -93,7 +93,7 @@ public class Spr8954Tests { static class FooFactoryBean implements FactoryBean, AnInterface { @Override - public Foo getObject() throws Exception { + public Foo getObject() { return new Foo(); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanConfigurerSupportTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanConfigurerSupportTests.java index daaeab1371b..928779d2064 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanConfigurerSupportTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanConfigurerSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -33,16 +33,16 @@ import static org.mockito.Mockito.verify; * @author Juergen Hoeller * @author Sam Brannen */ -public class BeanConfigurerSupportTests { +class BeanConfigurerSupportTests { @Test - public void supplyIncompatibleBeanFactoryImplementation() { + void supplyIncompatibleBeanFactoryImplementation() { assertThatIllegalArgumentException().isThrownBy(() -> new StubBeanConfigurerSupport().setBeanFactory(mock())); } @Test - public void configureBeanDoesNothingIfBeanWiringInfoResolverResolvesToNull() throws Exception { + void configureBeanDoesNothingIfBeanWiringInfoResolverResolvesToNull() { TestBean beanInstance = new TestBean(); BeanWiringInfoResolver resolver = mock(); @@ -56,7 +56,7 @@ public class BeanConfigurerSupportTests { } @Test - public void configureBeanDoesNothingIfNoBeanFactoryHasBeenSet() throws Exception { + void configureBeanDoesNothingIfNoBeanFactoryHasBeenSet() { TestBean beanInstance = new TestBean(); BeanConfigurerSupport configurer = new StubBeanConfigurerSupport(); configurer.configureBean(beanInstance); @@ -64,7 +64,7 @@ public class BeanConfigurerSupportTests { } @Test - public void configureBeanReallyDoesDefaultToUsingTheFullyQualifiedClassNameOfTheSuppliedBeanInstance() throws Exception { + void configureBeanReallyDoesDefaultToUsingTheFullyQualifiedClassNameOfTheSuppliedBeanInstance() { TestBean beanInstance = new TestBean(); BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class); builder.addPropertyValue("name", "Harriet Wheeler"); @@ -80,7 +80,7 @@ public class BeanConfigurerSupportTests { } @Test - public void configureBeanPerformsAutowiringByNameIfAppropriateBeanWiringInfoResolverIsPluggedIn() throws Exception { + void configureBeanPerformsAutowiringByNameIfAppropriateBeanWiringInfoResolverIsPluggedIn() { TestBean beanInstance = new TestBean(); // spouse for autowiring by name... BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class); @@ -100,7 +100,7 @@ public class BeanConfigurerSupportTests { } @Test - public void configureBeanPerformsAutowiringByTypeIfAppropriateBeanWiringInfoResolverIsPluggedIn() throws Exception { + void configureBeanPerformsAutowiringByTypeIfAppropriateBeanWiringInfoResolverIsPluggedIn() { TestBean beanInstance = new TestBean(); // spouse for autowiring by type... BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanWiringInfoTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanWiringInfoTests.java index 7919ba0a0b4..48689ad4874 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanWiringInfoTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/wiring/BeanWiringInfoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -27,58 +27,58 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rick Evans * @author Sam Brannen */ -public class BeanWiringInfoTests { +class BeanWiringInfoTests { @Test - public void ctorWithNullBeanName() throws Exception { + void ctorWithNullBeanName() { assertThatIllegalArgumentException().isThrownBy(() -> new BeanWiringInfo(null)); } @Test - public void ctorWithWhitespacedBeanName() throws Exception { + void ctorWithWhitespacedBeanName() { assertThatIllegalArgumentException().isThrownBy(() -> new BeanWiringInfo(" \t")); } @Test - public void ctorWithEmptyBeanName() throws Exception { + void ctorWithEmptyBeanName() { assertThatIllegalArgumentException().isThrownBy(() -> new BeanWiringInfo("")); } @Test - public void ctorWithNegativeIllegalAutowiringValue() throws Exception { + void ctorWithNegativeIllegalAutowiringValue() { assertThatIllegalArgumentException().isThrownBy(() -> new BeanWiringInfo(-1, true)); } @Test - public void ctorWithPositiveOutOfRangeAutowiringValue() throws Exception { + void ctorWithPositiveOutOfRangeAutowiringValue() { assertThatIllegalArgumentException().isThrownBy(() -> new BeanWiringInfo(123871, true)); } @Test - public void usingAutowireCtorIndicatesAutowiring() throws Exception { + void usingAutowireCtorIndicatesAutowiring() { BeanWiringInfo info = new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, true); assertThat(info.indicatesAutowiring()).isTrue(); } @Test - public void usingBeanNameCtorDoesNotIndicateAutowiring() throws Exception { + void usingBeanNameCtorDoesNotIndicateAutowiring() { BeanWiringInfo info = new BeanWiringInfo("fooService"); assertThat(info.indicatesAutowiring()).isFalse(); } @Test - public void noDependencyCheckValueIsPreserved() throws Exception { + void noDependencyCheckValueIsPreserved() { BeanWiringInfo info = new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, true); assertThat(info.getDependencyCheck()).isTrue(); } @Test - public void dependencyCheckValueIsPreserved() throws Exception { + void dependencyCheckValueIsPreserved() { BeanWiringInfo info = new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_TYPE, false); assertThat(info.getDependencyCheck()).isFalse(); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/wiring/ClassNameBeanWiringInfoResolverTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/wiring/ClassNameBeanWiringInfoResolverTests.java index becb7961f2a..9d7eab0c4a0 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/wiring/ClassNameBeanWiringInfoResolverTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/wiring/ClassNameBeanWiringInfoResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class ClassNameBeanWiringInfoResolverTests { @Test - void resolveWiringInfoWithNullBeanInstance() throws Exception { + void resolveWiringInfoWithNullBeanInstance() { assertThatIllegalArgumentException().isThrownBy(() -> new ClassNameBeanWiringInfoResolver().resolveWiringInfo(null)); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/AutowireWithExclusionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/AutowireWithExclusionTests.java index 8ea0719a82b..8ce547df688 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/AutowireWithExclusionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/AutowireWithExclusionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rob Harrop * @author Juergen Hoeller */ -public class AutowireWithExclusionTests { +class AutowireWithExclusionTests { @Test - public void byTypeAutowireWithAutoSelfExclusion() throws Exception { + void byTypeAutowireWithAutoSelfExclusion() { CountingFactory.reset(); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml"); beanFactory.preInstantiateSingletons(); @@ -45,7 +45,7 @@ public class AutowireWithExclusionTests { } @Test - public void byTypeAutowireWithExclusion() throws Exception { + void byTypeAutowireWithExclusion() { CountingFactory.reset(); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml"); beanFactory.preInstantiateSingletons(); @@ -55,7 +55,7 @@ public class AutowireWithExclusionTests { } @Test - public void byTypeAutowireWithExclusionInParentFactory() throws Exception { + void byTypeAutowireWithExclusionInParentFactory() { CountingFactory.reset(); DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml"); parent.preInstantiateSingletons(); @@ -70,7 +70,7 @@ public class AutowireWithExclusionTests { } @Test - public void byTypeAutowireWithPrimaryInParentFactory() throws Exception { + void byTypeAutowireWithPrimaryInParentFactory() { CountingFactory.reset(); DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml"); parent.getBeanDefinition("props1").setPrimary(true); @@ -89,7 +89,7 @@ public class AutowireWithExclusionTests { } @Test - public void byTypeAutowireWithPrimaryOverridingParentFactory() throws Exception { + void byTypeAutowireWithPrimaryOverridingParentFactory() { CountingFactory.reset(); DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml"); parent.preInstantiateSingletons(); @@ -108,7 +108,7 @@ public class AutowireWithExclusionTests { } @Test - public void byTypeAutowireWithPrimaryInParentAndChild() throws Exception { + void byTypeAutowireWithPrimaryInParentAndChild() { CountingFactory.reset(); DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml"); parent.getBeanDefinition("props1").setPrimary(true); @@ -128,7 +128,7 @@ public class AutowireWithExclusionTests { } @Test - public void byTypeAutowireWithInclusion() throws Exception { + void byTypeAutowireWithInclusion() { CountingFactory.reset(); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-inclusion.xml"); beanFactory.preInstantiateSingletons(); @@ -138,7 +138,7 @@ public class AutowireWithExclusionTests { } @Test - public void byTypeAutowireWithSelectiveInclusion() throws Exception { + void byTypeAutowireWithSelectiveInclusion() { CountingFactory.reset(); DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-selective-inclusion.xml"); beanFactory.preInstantiateSingletons(); @@ -148,7 +148,7 @@ public class AutowireWithExclusionTests { } @Test - public void constructorAutowireWithAutoSelfExclusion() throws Exception { + void constructorAutowireWithAutoSelfExclusion() { DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml"); TestBean rob = (TestBean) beanFactory.getBean("rob"); TestBean sally = (TestBean) beanFactory.getBean("sally"); @@ -161,7 +161,7 @@ public class AutowireWithExclusionTests { } @Test - public void constructorAutowireWithExclusion() throws Exception { + void constructorAutowireWithExclusion() { DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml"); TestBean rob = (TestBean) beanFactory.getBean("rob"); assertThat(rob.getSomeProperties().getProperty("name")).isEqualTo("props1"); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/BeanNameGenerationTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/BeanNameGenerationTests.java index 11d0324d76f..52b5d12485e 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/BeanNameGenerationTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/BeanNameGenerationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -29,13 +29,13 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rob Harrop * @author Juergen Hoeller */ -public class BeanNameGenerationTests { +class BeanNameGenerationTests { private DefaultListableBeanFactory beanFactory; @BeforeEach - public void setUp() { + void setUp() { this.beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); @@ -43,7 +43,7 @@ public class BeanNameGenerationTests { } @Test - public void naming() { + void naming() { String className = GeneratedNameBean.class.getName(); String targetName = className + BeanDefinitionReaderUtils.GENERATED_BEAN_NAME_SEPARATOR + "0"; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/CollectionMergingTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/CollectionMergingTests.java index 64a124a016a..f3bd2e51738 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/CollectionMergingTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/CollectionMergingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import org.assertj.core.api.InstanceOfAssertFactories; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,6 +31,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.core.io.ClassPathResource; +import static java.util.Map.entry; import static org.assertj.core.api.Assertions.assertThat; /** @@ -39,29 +41,27 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rick Evans */ @SuppressWarnings("rawtypes") -public class CollectionMergingTests { +class CollectionMergingTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @BeforeEach - public void setUp() throws Exception { + void setUp() { BeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory); reader.loadBeanDefinitions(new ClassPathResource("collectionMerging.xml", getClass())); } @Test - public void mergeList() throws Exception { + void mergeList() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithList"); List list = bean.getSomeList(); - assertThat(list).as("Incorrect size").hasSize(3); - assertThat(list).element(0).isEqualTo("Rob Harrop"); - assertThat(list).element(1).isEqualTo("Rod Johnson"); - assertThat(list).element(2).isEqualTo("Juergen Hoeller"); + assertThat(list).asInstanceOf(InstanceOfAssertFactories.list(String.class)) + .containsExactly("Rob Harrop", "Rod Johnson", "Juergen Hoeller"); } @Test - public void mergeListWithInnerBeanAsListElement() throws Exception { + void mergeListWithInnerBeanAsListElement() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefs"); List list = bean.getSomeList(); assertThat(list).isNotNull(); @@ -70,16 +70,15 @@ public class CollectionMergingTests { } @Test - public void mergeSet() { + void mergeSet() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithSet"); Set set = bean.getSomeSet(); - assertThat(set).as("Incorrect size").hasSize(2); - assertThat(set.contains("Rob Harrop")).isTrue(); - assertThat(set.contains("Sally Greenwood")).isTrue(); + assertThat(set).asInstanceOf(InstanceOfAssertFactories.collection(String.class)) + .containsOnly("Rob Harrop", "Sally Greenwood"); } @Test - public void mergeSetWithInnerBeanAsSetElement() throws Exception { + void mergeSetWithInnerBeanAsSetElement() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetOfRefs"); Set set = bean.getSomeSet(); assertThat(set).isNotNull(); @@ -92,17 +91,15 @@ public class CollectionMergingTests { } @Test - public void mergeMap() throws Exception { + void mergeMap() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithMap"); Map map = bean.getSomeMap(); - assertThat(map).as("Incorrect size").hasSize(3); - assertThat(map.get("Rob")).isEqualTo("Sally"); - assertThat(map.get("Rod")).isEqualTo("Kerry"); - assertThat(map.get("Juergen")).isEqualTo("Eva"); + assertThat(map).asInstanceOf(InstanceOfAssertFactories.map(String.class,String.class)) + .containsOnly(entry("Rob", "Sally"), entry("Rod", "Kerry"), entry("Juergen", "Eva")); } @Test - public void mergeMapWithInnerBeanAsMapEntryValue() throws Exception { + void mergeMapWithInnerBeanAsMapEntryValue() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefs"); Map map = bean.getSomeMap(); assertThat(map).isNotNull(); @@ -113,7 +110,7 @@ public class CollectionMergingTests { } @Test - public void mergeProperties() throws Exception { + void mergeProperties() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithProps"); Properties props = bean.getSomeProperties(); assertThat(props).as("Incorrect size").hasSize(3); @@ -123,17 +120,15 @@ public class CollectionMergingTests { } @Test - public void mergeListInConstructor() throws Exception { + void mergeListInConstructor() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithListInConstructor"); List list = bean.getSomeList(); - assertThat(list).as("Incorrect size").hasSize(3); - assertThat(list).element(0).isEqualTo("Rob Harrop"); - assertThat(list).element(1).isEqualTo("Rod Johnson"); - assertThat(list).element(2).isEqualTo("Juergen Hoeller"); + assertThat(list).asInstanceOf(InstanceOfAssertFactories.list(String.class)) + .containsExactly("Rob Harrop", "Rod Johnson", "Juergen Hoeller"); } @Test - public void mergeListWithInnerBeanAsListElementInConstructor() throws Exception { + void mergeListWithInnerBeanAsListElementInConstructor() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefsInConstructor"); List list = bean.getSomeList(); assertThat(list).isNotNull(); @@ -143,7 +138,7 @@ public class CollectionMergingTests { } @Test - public void mergeSetInConstructor() { + void mergeSetInConstructor() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetInConstructor"); Set set = bean.getSomeSet(); assertThat(set).as("Incorrect size").hasSize(2); @@ -152,7 +147,7 @@ public class CollectionMergingTests { } @Test - public void mergeSetWithInnerBeanAsSetElementInConstructor() throws Exception { + void mergeSetWithInnerBeanAsSetElementInConstructor() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithSetOfRefsInConstructor"); Set set = bean.getSomeSet(); assertThat(set).isNotNull(); @@ -165,7 +160,7 @@ public class CollectionMergingTests { } @Test - public void mergeMapInConstructor() throws Exception { + void mergeMapInConstructor() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapInConstructor"); Map map = bean.getSomeMap(); assertThat(map).as("Incorrect size").hasSize(3); @@ -175,7 +170,7 @@ public class CollectionMergingTests { } @Test - public void mergeMapWithInnerBeanAsMapEntryValueInConstructor() throws Exception { + void mergeMapWithInnerBeanAsMapEntryValueInConstructor() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefsInConstructor"); Map map = bean.getSomeMap(); assertThat(map).isNotNull(); @@ -185,7 +180,7 @@ public class CollectionMergingTests { } @Test - public void mergePropertiesInConstructor() throws Exception { + void mergePropertiesInConstructor() { TestBean bean = (TestBean) this.beanFactory.getBean("childWithPropsInConstructor"); Properties props = bean.getSomeProperties(); assertThat(props).as("Incorrect size").hasSize(3); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/CollectionsWithDefaultTypesTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/CollectionsWithDefaultTypesTests.java index bdbb46da1aa..e9ed87d1181 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/CollectionsWithDefaultTypesTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/CollectionsWithDefaultTypesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rob Harrop * @author Juergen Hoeller */ -public class CollectionsWithDefaultTypesTests { +class CollectionsWithDefaultTypesTests { private final DefaultListableBeanFactory beanFactory; @@ -42,7 +42,7 @@ public class CollectionsWithDefaultTypesTests { } @Test - public void testListHasDefaultType() throws Exception { + void testListHasDefaultType() { TestBean bean = (TestBean) this.beanFactory.getBean("testBean"); for (Object o : bean.getSomeList()) { assertThat(o.getClass()).as("Value type is incorrect").isEqualTo(Integer.class); @@ -50,7 +50,7 @@ public class CollectionsWithDefaultTypesTests { } @Test - public void testSetHasDefaultType() throws Exception { + void testSetHasDefaultType() { TestBean bean = (TestBean) this.beanFactory.getBean("testBean"); for (Object o : bean.getSomeSet()) { assertThat(o.getClass()).as("Value type is incorrect").isEqualTo(Integer.class); @@ -58,13 +58,13 @@ public class CollectionsWithDefaultTypesTests { } @Test - public void testMapHasDefaultKeyAndValueType() throws Exception { + void testMapHasDefaultKeyAndValueType() { TestBean bean = (TestBean) this.beanFactory.getBean("testBean"); assertMap(bean.getSomeMap()); } @Test - public void testMapWithNestedElementsHasDefaultKeyAndValueType() throws Exception { + void testMapWithNestedElementsHasDefaultKeyAndValueType() { TestBean bean = (TestBean) this.beanFactory.getBean("testBean2"); assertMap(bean.getSomeMap()); } @@ -79,7 +79,7 @@ public class CollectionsWithDefaultTypesTests { @Test @SuppressWarnings("rawtypes") - public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Exception { + public void testBuildCollectionFromMixtureOfReferencesAndValues() { MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble"); assertThat(jumble.getJumble()).as("Expected 3 elements, not " + jumble.getJumble().size()).hasSize(3); List l = (List) jumble.getJumble(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/DefaultLifecycleMethodsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/DefaultLifecycleMethodsTests.java index 0c6f7f80a20..7d69e989c3e 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/DefaultLifecycleMethodsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/DefaultLifecycleMethodsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -28,20 +28,20 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rob Harrop * @author Juergen Hoeller */ -public class DefaultLifecycleMethodsTests { +class DefaultLifecycleMethodsTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @BeforeEach - public void setup() throws Exception { + void setup() { new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( new ClassPathResource("defaultLifecycleMethods.xml", getClass())); } @Test - public void lifecycleMethodsInvoked() { + void lifecycleMethodsInvoked() { LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("lifecycleAware"); assertThat(bean.isInitCalled()).as("Bean not initialized").isTrue(); assertThat(bean.isCustomInitCalled()).as("Custom init method called incorrectly").isFalse(); @@ -52,7 +52,7 @@ public class DefaultLifecycleMethodsTests { } @Test - public void lifecycleMethodsDisabled() throws Exception { + void lifecycleMethodsDisabled() { LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("lifecycleMethodsDisabled"); assertThat(bean.isInitCalled()).as("Bean init method called incorrectly").isFalse(); assertThat(bean.isCustomInitCalled()).as("Custom init method called incorrectly").isFalse(); @@ -62,7 +62,7 @@ public class DefaultLifecycleMethodsTests { } @Test - public void ignoreDefaultLifecycleMethods() throws Exception { + void ignoreDefaultLifecycleMethods() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource( "ignoreDefaultLifecycleMethods.xml", getClass())); @@ -71,7 +71,7 @@ public class DefaultLifecycleMethodsTests { } @Test - public void overrideDefaultLifecycleMethods() throws Exception { + void overrideDefaultLifecycleMethods() { LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("overrideLifecycleMethods"); assertThat(bean.isInitCalled()).as("Default init method called incorrectly").isFalse(); assertThat(bean.isCustomInitCalled()).as("Custom init method not called").isTrue(); @@ -81,7 +81,7 @@ public class DefaultLifecycleMethodsTests { } @Test - public void childWithDefaultLifecycleMethods() throws Exception { + void childWithDefaultLifecycleMethods() { LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("childWithDefaultLifecycleMethods"); assertThat(bean.isInitCalled()).as("Bean not initialized").isTrue(); assertThat(bean.isCustomInitCalled()).as("Custom init method called incorrectly").isFalse(); @@ -92,7 +92,7 @@ public class DefaultLifecycleMethodsTests { } @Test - public void childWithLifecycleMethodsDisabled() throws Exception { + void childWithLifecycleMethodsDisabled() { LifecycleAwareBean bean = (LifecycleAwareBean) this.beanFactory.getBean("childWithLifecycleMethodsDisabled"); assertThat(bean.isInitCalled()).as("Bean init method called incorrectly").isFalse(); assertThat(bean.isCustomInitCalled()).as("Custom init method called incorrectly").isFalse(); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/DelegatingEntityResolverTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/DelegatingEntityResolverTests.java index 6e05b66c7c6..3fb01df37b1 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/DelegatingEntityResolverTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/DelegatingEntityResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -28,22 +28,22 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rick Evans * @author Chris Beams */ -public class DelegatingEntityResolverTests { +class DelegatingEntityResolverTests { @Test - public void testCtorWhereDtdEntityResolverIsNull() throws Exception { + void testCtorWhereDtdEntityResolverIsNull() { assertThatIllegalArgumentException().isThrownBy(() -> new DelegatingEntityResolver(null, new NoOpEntityResolver())); } @Test - public void testCtorWhereSchemaEntityResolverIsNull() throws Exception { + void testCtorWhereSchemaEntityResolverIsNull() { assertThatIllegalArgumentException().isThrownBy(() -> new DelegatingEntityResolver(new NoOpEntityResolver(), null)); } @Test - public void testCtorWhereEntityResolversAreBothNull() throws Exception { + void testCtorWhereEntityResolversAreBothNull() { assertThatIllegalArgumentException().isThrownBy(() -> new DelegatingEntityResolver(null, null)); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/EventPublicationTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/EventPublicationTests.java index 992cb97011c..1b60156920b 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/EventPublicationTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/EventPublicationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -40,7 +40,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rob Harrop * @author Juergen Hoeller */ -@SuppressWarnings("rawtypes") class EventPublicationTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @@ -50,7 +49,7 @@ class EventPublicationTests { @BeforeEach - void setUp() throws Exception { + void setUp() { XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory); reader.setEventListener(this.eventListener); reader.setSourceExtractor(new PassThroughSourceExtractor()); @@ -58,7 +57,7 @@ class EventPublicationTests { } @Test - void defaultsEventReceived() throws Exception { + void defaultsEventReceived() { List defaultsList = this.eventListener.getDefaults(); assertThat(defaultsList).isNotEmpty(); assertThat(defaultsList).element(0).isInstanceOf(DocumentDefaultsDefinition.class); @@ -72,7 +71,7 @@ class EventPublicationTests { } @Test - void beanEventReceived() throws Exception { + void beanEventReceived() { ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean"); assertThat(componentDefinition1).isInstanceOf(BeanComponentDefinition.class); assertThat(componentDefinition1.getBeanDefinitions()).hasSize(1); @@ -98,7 +97,7 @@ class EventPublicationTests { } @Test - void aliasEventReceived() throws Exception { + void aliasEventReceived() { List aliases = this.eventListener.getAliases("testBean"); assertThat(aliases).hasSize(2); AliasDefinition aliasDefinition1 = aliases.get(0); @@ -110,7 +109,7 @@ class EventPublicationTests { } @Test - void importEventReceived() throws Exception { + void importEventReceived() { List imports = this.eventListener.getImports(); assertThat(imports).hasSize(1); ImportDefinition importDefinition = imports.get(0); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/FactoryMethodTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/FactoryMethodTests.java index abf97b228f4..418b64cc815 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/FactoryMethodTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/FactoryMethodTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -36,10 +36,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Juergen Hoeller * @author Chris Beams */ -public class FactoryMethodTests { +class FactoryMethodTests { @Test - public void testFactoryMethodsSingletonOnTargetClass() { + void testFactoryMethodsSingletonOnTargetClass() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -73,7 +73,7 @@ public class FactoryMethodTests { } @Test - public void testFactoryMethodsWithInvalidDestroyMethod() { + void testFactoryMethodsWithInvalidDestroyMethod() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -82,7 +82,7 @@ public class FactoryMethodTests { } @Test - public void testFactoryMethodsWithNullInstance() { + void testFactoryMethodsWithNullInstance() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -93,7 +93,7 @@ public class FactoryMethodTests { } @Test - public void testFactoryMethodsWithNullValue() { + void testFactoryMethodsWithNullValue() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -115,7 +115,7 @@ public class FactoryMethodTests { } @Test - public void testFactoryMethodsWithAutowire() { + void testFactoryMethodsWithAutowire() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -127,7 +127,7 @@ public class FactoryMethodTests { } @Test - public void testProtectedFactoryMethod() { + void testProtectedFactoryMethod() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -137,7 +137,7 @@ public class FactoryMethodTests { } @Test - public void testPrivateFactoryMethod() { + void testPrivateFactoryMethod() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -147,7 +147,7 @@ public class FactoryMethodTests { } @Test - public void testFactoryMethodsPrototypeOnTargetClass() { + void testFactoryMethodsPrototypeOnTargetClass() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -191,7 +191,7 @@ public class FactoryMethodTests { * Tests where the static factory method is on a different class. */ @Test - public void testFactoryMethodsOnExternalClass() { + void testFactoryMethodsOnExternalClass() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -217,7 +217,7 @@ public class FactoryMethodTests { } @Test - public void testInstanceFactoryMethodWithoutArgs() { + void testInstanceFactoryMethodWithoutArgs() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -235,7 +235,7 @@ public class FactoryMethodTests { } @Test - public void testFactoryMethodNoMatchingStaticMethod() { + void testFactoryMethodNoMatchingStaticMethod() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -244,7 +244,7 @@ public class FactoryMethodTests { } @Test - public void testNonExistingFactoryMethod() { + void testNonExistingFactoryMethod() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -254,7 +254,7 @@ public class FactoryMethodTests { } @Test - public void testFactoryMethodArgumentsForNonExistingMethod() { + void testFactoryMethodArgumentsForNonExistingMethod() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -264,7 +264,7 @@ public class FactoryMethodTests { } @Test - public void testCanSpecifyFactoryMethodArgumentsOnFactoryMethodPrototype() { + void testCanSpecifyFactoryMethodArgumentsOnFactoryMethodPrototype() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -300,7 +300,7 @@ public class FactoryMethodTests { } @Test - public void testCanSpecifyFactoryMethodArgumentsOnSingleton() { + void testCanSpecifyFactoryMethodArgumentsOnSingleton() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -315,7 +315,7 @@ public class FactoryMethodTests { } @Test - public void testCannotSpecifyFactoryMethodArgumentsOnSingletonAfterCreation() { + void testCannotSpecifyFactoryMethodArgumentsOnSingletonAfterCreation() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -329,7 +329,7 @@ public class FactoryMethodTests { } @Test - public void testFactoryMethodWithDifferentReturnType() { + void testFactoryMethodWithDifferentReturnType() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); @@ -352,7 +352,7 @@ public class FactoryMethodTests { } @Test - public void testFactoryMethodForJavaMailSession() { + void testFactoryMethodForJavaMailSession() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf); reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass())); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/MetadataAttachmentTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/MetadataAttachmentTests.java index 1c796266d1f..9548ca56272 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/MetadataAttachmentTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/MetadataAttachmentTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -29,33 +29,33 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Rob Harrop */ -public class MetadataAttachmentTests { +class MetadataAttachmentTests { private DefaultListableBeanFactory beanFactory; @BeforeEach - public void setUp() throws Exception { + void setUp() { this.beanFactory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( new ClassPathResource("withMeta.xml", getClass())); } @Test - public void metadataAttachment() throws Exception { + void metadataAttachment() { BeanDefinition beanDefinition1 = this.beanFactory.getMergedBeanDefinition("testBean1"); assertThat(beanDefinition1.getAttribute("foo")).isEqualTo("bar"); } @Test - public void metadataIsInherited() throws Exception { + void metadataIsInherited() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean2"); assertThat(beanDefinition.getAttribute("foo")).as("Metadata not inherited").isEqualTo("bar"); assertThat(beanDefinition.getAttribute("abc")).as("Child metdata not attached").isEqualTo("123"); } @Test - public void propertyMetadata() throws Exception { + void propertyMetadata() { BeanDefinition beanDefinition = this.beanFactory.getMergedBeanDefinition("testBean3"); PropertyValue pv = beanDefinition.getPropertyValues().getPropertyValue("name"); assertThat(pv.getAttribute("surname")).isEqualTo("Harrop"); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementAttributeRecursionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementAttributeRecursionTests.java index cce3bb3ca15..4efa9b5dd38 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementAttributeRecursionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementAttributeRecursionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Chris Beams */ -public class NestedBeansElementAttributeRecursionTests { +class NestedBeansElementAttributeRecursionTests { @Test - public void defaultLazyInit() { + void defaultLazyInit() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new ClassPathResource("NestedBeansElementAttributeRecursionTests-lazy-context.xml", this.getClass())); @@ -42,7 +42,7 @@ public class NestedBeansElementAttributeRecursionTests { } @Test - public void defaultLazyInitWithNonValidatingParser() { + void defaultLazyInitWithNonValidatingParser() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(bf); xmlBeanDefinitionReader.setValidating(false); @@ -67,7 +67,7 @@ public class NestedBeansElementAttributeRecursionTests { } @Test - public void defaultMerge() { + void defaultMerge() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new ClassPathResource("NestedBeansElementAttributeRecursionTests-merge-context.xml", this.getClass())); @@ -76,7 +76,7 @@ public class NestedBeansElementAttributeRecursionTests { } @Test - public void defaultMergeWithNonValidatingParser() { + void defaultMergeWithNonValidatingParser() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(bf); xmlBeanDefinitionReader.setValidating(false); @@ -106,7 +106,7 @@ public class NestedBeansElementAttributeRecursionTests { } @Test - public void defaultAutowireCandidates() { + void defaultAutowireCandidates() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new ClassPathResource("NestedBeansElementAttributeRecursionTests-autowire-candidates-context.xml", this.getClass())); @@ -115,7 +115,7 @@ public class NestedBeansElementAttributeRecursionTests { } @Test - public void defaultAutowireCandidatesWithNonValidatingParser() { + void defaultAutowireCandidatesWithNonValidatingParser() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader xmlBeanDefinitionReader = new XmlBeanDefinitionReader(bf); xmlBeanDefinitionReader.setValidating(false); @@ -146,7 +146,7 @@ public class NestedBeansElementAttributeRecursionTests { } @Test - public void initMethod() { + void initMethod() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions( new ClassPathResource("NestedBeansElementAttributeRecursionTests-init-destroy-context.xml", this.getClass())); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementTests.java index 4117c82c432..44cccf0b72f 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/NestedBeansElementTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -32,12 +32,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Chris Beams */ -public class NestedBeansElementTests { +class NestedBeansElementTests { private final Resource XML = new ClassPathResource("NestedBeansElementTests-context.xml", this.getClass()); @Test - public void getBean_withoutActiveProfile() { + void getBean_withoutActiveProfile() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(bf).loadBeanDefinitions(XML); @@ -46,7 +46,7 @@ public class NestedBeansElementTests { } @Test - public void getBean_withActiveProfile() { + void getBean_withActiveProfile() { ConfigurableEnvironment env = new StandardEnvironment(); env.setActiveProfiles("dev"); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/ProfileXmlBeanDefinitionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/ProfileXmlBeanDefinitionTests.java index 56795fe7573..cb5ad2d653b 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/ProfileXmlBeanDefinitionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/ProfileXmlBeanDefinitionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -36,7 +36,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Sam Brannen * @since 3.1 */ -public class ProfileXmlBeanDefinitionTests { +class ProfileXmlBeanDefinitionTests { private static final String PROD_ELIGIBLE_XML = "ProfileXmlBeanDefinitionTests-prodProfile.xml"; private static final String DEV_ELIGIBLE_XML = "ProfileXmlBeanDefinitionTests-devProfile.xml"; @@ -61,13 +61,13 @@ public class ProfileXmlBeanDefinitionTests { private static final String TARGET_BEAN = "foo"; @Test - public void testProfileValidation() { + void testProfileValidation() { assertThatIllegalArgumentException().isThrownBy(() -> beanFactoryFor(PROD_ELIGIBLE_XML, NULL_ACTIVE)); } @Test - public void testProfilePermutations() { + void testProfilePermutations() { assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, NONE_ACTIVE)).isNot(containingTarget()); assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, DEV_ACTIVE)).isNot(containingTarget()); assertThat(beanFactoryFor(PROD_ELIGIBLE_XML, PROD_ACTIVE)).is(containingTarget()); @@ -116,7 +116,7 @@ public class ProfileXmlBeanDefinitionTests { } @Test - public void testDefaultProfile() { + void testDefaultProfile() { { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory); @@ -140,7 +140,7 @@ public class ProfileXmlBeanDefinitionTests { } @Test - public void testDefaultAndNonDefaultProfile() { + void testDefaultAndNonDefaultProfile() { assertThat(beanFactoryFor(DEFAULT_ELIGIBLE_XML, NONE_ACTIVE)).is(containingTarget()); assertThat(beanFactoryFor(DEFAULT_ELIGIBLE_XML, "other")).isNot(containingTarget()); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/SchemaValidationTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/SchemaValidationTests.java index 70199450995..3f71ff9e8bb 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/SchemaValidationTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/SchemaValidationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Rob Harrop */ -public class SchemaValidationTests { +class SchemaValidationTests { @Test - public void withAutodetection() throws Exception { + void withAutodetection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf); assertThatExceptionOfType(BeansException.class).isThrownBy(() -> @@ -42,7 +42,7 @@ public class SchemaValidationTests { } @Test - public void withExplicitValidationMode() throws Exception { + void withExplicitValidationMode() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); @@ -52,7 +52,7 @@ public class SchemaValidationTests { } @Test - public void loadDefinitions() throws Exception { + void loadDefinitions() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf); reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandlerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandlerTests.java index 24a9d43e89b..4f1a5535cda 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandlerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -30,10 +30,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Costin Leau */ -public class SimpleConstructorNamespaceHandlerTests { +class SimpleConstructorNamespaceHandlerTests { @Test - public void simpleValue() throws Exception { + void simpleValue() { DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); String name = "simple"; // beanFactory.getBean("simple1", DummyBean.class); @@ -42,7 +42,7 @@ public class SimpleConstructorNamespaceHandlerTests { } @Test - public void simpleRef() throws Exception { + void simpleRef() { DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); String name = "simple-ref"; // beanFactory.getBean("name-value1", TestBean.class); @@ -51,7 +51,7 @@ public class SimpleConstructorNamespaceHandlerTests { } @Test - public void nameValue() throws Exception { + void nameValue() { DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); String name = "name-value"; // beanFactory.getBean("name-value1", TestBean.class); @@ -61,7 +61,7 @@ public class SimpleConstructorNamespaceHandlerTests { } @Test - public void nameRef() throws Exception { + void nameRef() { DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); TestBean nameValue = beanFactory.getBean("name-value", TestBean.class); DummyBean nameRef = beanFactory.getBean("name-ref", DummyBean.class); @@ -71,7 +71,7 @@ public class SimpleConstructorNamespaceHandlerTests { } @Test - public void typeIndexedValue() throws Exception { + void typeIndexedValue() { DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DummyBean typeRef = beanFactory.getBean("indexed-value", DummyBean.class); @@ -81,7 +81,7 @@ public class SimpleConstructorNamespaceHandlerTests { } @Test - public void typeIndexedRef() throws Exception { + void typeIndexedRef() { DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DummyBean typeRef = beanFactory.getBean("indexed-ref", DummyBean.class); @@ -90,7 +90,7 @@ public class SimpleConstructorNamespaceHandlerTests { } @Test - public void ambiguousConstructor() throws Exception { + void ambiguousConstructor() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> new XmlBeanDefinitionReader(bf).loadBeanDefinitions( @@ -98,7 +98,7 @@ public class SimpleConstructorNamespaceHandlerTests { } @Test - public void constructorWithNameEndingInRef() throws Exception { + void constructorWithNameEndingInRef() { DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml"); DummyBean derivedBean = beanFactory.getBean("beanWithRefConstructorArg", DummyBean.class); assertThat(derivedBean.getAge()).isEqualTo(10); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/SimplePropertyNamespaceHandlerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/SimplePropertyNamespaceHandlerTests.java index 68ef31d9a82..77fca219c25 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/SimplePropertyNamespaceHandlerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/SimplePropertyNamespaceHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @author Juergen Hoeller * @author Arjen Poutsma */ -public class SimplePropertyNamespaceHandlerTests { +class SimplePropertyNamespaceHandlerTests { @Test - public void simpleBeanConfigured() throws Exception { + void simpleBeanConfigured() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions( new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass())); @@ -47,7 +47,7 @@ public class SimplePropertyNamespaceHandlerTests { } @Test - public void innerBeanConfigured() throws Exception { + void innerBeanConfigured() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions( new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass())); @@ -59,7 +59,7 @@ public class SimplePropertyNamespaceHandlerTests { } @Test - public void withPropertyDefinedTwice() throws Exception { + void withPropertyDefinedTwice() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions( @@ -67,7 +67,7 @@ public class SimplePropertyNamespaceHandlerTests { } @Test - public void propertyWithNameEndingInRef() throws Exception { + void propertyWithNameEndingInRef() { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions( new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass())); diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/UtilNamespaceHandlerTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/UtilNamespaceHandlerTests.java index 687cb7f0f58..549037c8227 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/UtilNamespaceHandlerTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/UtilNamespaceHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -46,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Mark Fisher */ @SuppressWarnings("rawtypes") -public class UtilNamespaceHandlerTests { +class UtilNamespaceHandlerTests { private DefaultListableBeanFactory beanFactory; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java index 84c5ba6ddfa..785545861a8 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlBeanCollectionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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,6 +42,7 @@ import org.springframework.beans.testfixture.beans.HasMap; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.core.io.ClassPathResource; +import static java.util.Map.entry; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -53,20 +54,20 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; * @since 19.12.2004 */ @SuppressWarnings({ "rawtypes", "unchecked" }) -public class XmlBeanCollectionTests { +class XmlBeanCollectionTests { private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); @BeforeEach - public void loadBeans() { + void loadBeans() { new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions( new ClassPathResource("collections.xml", getClass())); } @Test - public void testCollectionFactoryDefaults() throws Exception { + void testCollectionFactoryDefaults() throws Exception { ListFactoryBean listFactory = new ListFactoryBean(); listFactory.setSourceList(new LinkedList()); listFactory.afterPropertiesSet(); @@ -84,7 +85,7 @@ public class XmlBeanCollectionTests { } @Test - public void testRefSubelement() { + void testRefSubelement() { //assertTrue("5 beans in reftypes, not " + this.beanFactory.getBeanDefinitionCount(), this.beanFactory.getBeanDefinitionCount() == 5); TestBean jen = (TestBean) this.beanFactory.getBean("jenny"); TestBean dave = (TestBean) this.beanFactory.getBean("david"); @@ -92,25 +93,25 @@ public class XmlBeanCollectionTests { } @Test - public void testPropertyWithLiteralValueSubelement() { + void testPropertyWithLiteralValueSubelement() { TestBean verbose = (TestBean) this.beanFactory.getBean("verbose"); assertThat(verbose.getName()).isEqualTo("verbose"); } @Test - public void testPropertyWithIdRefLocalAttrSubelement() { + void testPropertyWithIdRefLocalAttrSubelement() { TestBean verbose = (TestBean) this.beanFactory.getBean("verbose2"); assertThat(verbose.getName()).isEqualTo("verbose"); } @Test - public void testPropertyWithIdRefBeanAttrSubelement() { + void testPropertyWithIdRefBeanAttrSubelement() { TestBean verbose = (TestBean) this.beanFactory.getBean("verbose3"); assertThat(verbose.getName()).isEqualTo("verbose"); } @Test - public void testRefSubelementsBuildCollection() { + void testRefSubelementsBuildCollection() { TestBean jen = (TestBean) this.beanFactory.getBean("jenny"); TestBean dave = (TestBean) this.beanFactory.getBean("david"); TestBean rod = (TestBean) this.beanFactory.getBean("rod"); @@ -127,7 +128,7 @@ public class XmlBeanCollectionTests { } @Test - public void testRefSubelementsBuildCollectionWithPrototypes() { + void testRefSubelementsBuildCollectionWithPrototypes() { TestBean jen = (TestBean) this.beanFactory.getBean("pJenny"); TestBean dave = (TestBean) this.beanFactory.getBean("pDavid"); TestBean rod = (TestBean) this.beanFactory.getBean("pRod"); @@ -150,7 +151,7 @@ public class XmlBeanCollectionTests { } @Test - public void testRefSubelementsBuildCollectionFromSingleElement() { + void testRefSubelementsBuildCollectionFromSingleElement() { TestBean loner = (TestBean) this.beanFactory.getBean("loner"); TestBean dave = (TestBean) this.beanFactory.getBean("david"); assertThat(loner.getFriends().size()).isEqualTo(1); @@ -158,7 +159,7 @@ public class XmlBeanCollectionTests { } @Test - public void testBuildCollectionFromMixtureOfReferencesAndValues() { + void testBuildCollectionFromMixtureOfReferencesAndValues() { MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble"); assertThat(jumble.getJumble().size()).as("Expected 5 elements, not " + jumble.getJumble().size()).isEqualTo(5); List l = (List) jumble.getJumble(); @@ -172,7 +173,7 @@ public class XmlBeanCollectionTests { } @Test - public void testInvalidBeanNameReference() { + void testInvalidBeanNameReference() { assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> this.beanFactory.getBean("jumble2")) .withCauseInstanceOf(BeanDefinitionStoreException.class) @@ -180,13 +181,13 @@ public class XmlBeanCollectionTests { } @Test - public void testEmptyMap() { + void testEmptyMap() { HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyMap"); assertThat(hasMap.getMap().size()).isEqualTo(0); } @Test - public void testMapWithLiteralsOnly() { + void testMapWithLiteralsOnly() { HasMap hasMap = (HasMap) this.beanFactory.getBean("literalMap"); assertThat(hasMap.getMap().size()).isEqualTo(3); assertThat(hasMap.getMap().get("foo").equals("bar")).isTrue(); @@ -195,7 +196,7 @@ public class XmlBeanCollectionTests { } @Test - public void testMapWithLiteralsAndReferences() { + void testMapWithLiteralsAndReferences() { HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMap"); assertThat(hasMap.getMap().size()).isEqualTo(5); assertThat(hasMap.getMap().get("foo")).isEqualTo(10); @@ -209,7 +210,7 @@ public class XmlBeanCollectionTests { } @Test - public void testMapWithLiteralsAndPrototypeReferences() { + void testMapWithLiteralsAndPrototypeReferences() { TestBean jenny = (TestBean) this.beanFactory.getBean("pJenny"); HasMap hasMap = (HasMap) this.beanFactory.getBean("pMixedMap"); assertThat(hasMap.getMap().size()).isEqualTo(2); @@ -225,7 +226,7 @@ public class XmlBeanCollectionTests { } @Test - public void testMapWithLiteralsReferencesAndList() { + void testMapWithLiteralsReferencesAndList() { HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMapWithList"); assertThat(hasMap.getMap().size()).isEqualTo(4); assertThat(hasMap.getMap().get(null).equals("bar")).isTrue(); @@ -262,13 +263,13 @@ public class XmlBeanCollectionTests { } @Test - public void testEmptySet() { + void testEmptySet() { HasMap hasMap = (HasMap) this.beanFactory.getBean("emptySet"); assertThat(hasMap.getSet().size()).isEqualTo(0); } @Test - public void testPopulatedSet() { + void testPopulatedSet() { HasMap hasMap = (HasMap) this.beanFactory.getBean("set"); assertThat(hasMap.getSet().size()).isEqualTo(3); assertThat(hasMap.getSet().contains("bar")).isTrue(); @@ -282,7 +283,7 @@ public class XmlBeanCollectionTests { } @Test - public void testPopulatedConcurrentSet() { + void testPopulatedConcurrentSet() { HasMap hasMap = (HasMap) this.beanFactory.getBean("concurrentSet"); assertThat(hasMap.getConcurrentSet().size()).isEqualTo(3); assertThat(hasMap.getConcurrentSet().contains("bar")).isTrue(); @@ -292,7 +293,7 @@ public class XmlBeanCollectionTests { } @Test - public void testPopulatedIdentityMap() { + void testPopulatedIdentityMap() { HasMap hasMap = (HasMap) this.beanFactory.getBean("identityMap"); assertThat(hasMap.getIdentityMap().size()).isEqualTo(2); HashSet set = new HashSet(hasMap.getIdentityMap().keySet()); @@ -301,14 +302,14 @@ public class XmlBeanCollectionTests { } @Test - public void testEmptyProps() { + void testEmptyProps() { HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyProps"); assertThat(hasMap.getProps().size()).isEqualTo(0); assertThat(Properties.class).isEqualTo(hasMap.getProps().getClass()); } @Test - public void testPopulatedProps() { + void testPopulatedProps() { HasMap hasMap = (HasMap) this.beanFactory.getBean("props"); assertThat(hasMap.getProps().size()).isEqualTo(2); assertThat(hasMap.getProps().get("foo").equals("bar")).isTrue(); @@ -316,7 +317,7 @@ public class XmlBeanCollectionTests { } @Test - public void testObjectArray() { + void testObjectArray() { HasMap hasMap = (HasMap) this.beanFactory.getBean("objectArray"); assertThat(hasMap.getObjectArray().length).isEqualTo(2); assertThat(hasMap.getObjectArray()[0].equals("one")).isTrue(); @@ -324,7 +325,7 @@ public class XmlBeanCollectionTests { } @Test - public void testIntegerArray() { + void testIntegerArray() { HasMap hasMap = (HasMap) this.beanFactory.getBean("integerArray"); assertThat(hasMap.getIntegerArray().length).isEqualTo(3); assertThat(hasMap.getIntegerArray()[0]).isEqualTo(0); @@ -333,7 +334,7 @@ public class XmlBeanCollectionTests { } @Test - public void testClassArray() { + void testClassArray() { HasMap hasMap = (HasMap) this.beanFactory.getBean("classArray"); assertThat(hasMap.getClassArray().length).isEqualTo(2); assertThat(hasMap.getClassArray()[0].equals(String.class)).isTrue(); @@ -341,7 +342,7 @@ public class XmlBeanCollectionTests { } @Test - public void testClassList() { + void testClassList() { HasMap hasMap = (HasMap) this.beanFactory.getBean("classList"); assertThat(hasMap.getClassList().size()).isEqualTo(2); assertThat(hasMap.getClassList().get(0).equals(String.class)).isTrue(); @@ -349,7 +350,7 @@ public class XmlBeanCollectionTests { } @Test - public void testProps() { + void testProps() { HasMap hasMap = (HasMap) this.beanFactory.getBean("props"); assertThat(hasMap.getProps()).hasSize(2); assertThat(hasMap.getProps().getProperty("foo")).isEqualTo("bar"); @@ -362,76 +363,55 @@ public class XmlBeanCollectionTests { } @Test - public void testListFactory() { + void testListFactory() { List list = (List) this.beanFactory.getBean("listFactory"); - assertThat(list).isInstanceOf(LinkedList.class); - assertThat(list.size()).isEqualTo(2); - assertThat(list).element(0).isEqualTo("bar"); - assertThat(list).element(1).isEqualTo("jenny"); + assertThat(list).isInstanceOf(LinkedList.class).containsExactly("bar", "jenny"); } @Test - public void testPrototypeListFactory() { + void testPrototypeListFactory() { List list = (List) this.beanFactory.getBean("pListFactory"); - assertThat(list).isInstanceOf(LinkedList.class); - assertThat(list.size()).isEqualTo(2); - assertThat(list).element(0).isEqualTo("bar"); - assertThat(list).element(1).isEqualTo("jenny"); + assertThat(list).isInstanceOf(LinkedList.class).containsExactly("bar", "jenny"); } @Test - public void testSetFactory() { + void testSetFactory() { Set set = (Set) this.beanFactory.getBean("setFactory"); - assertThat(set).isInstanceOf(TreeSet.class); - assertThat(set.size()).isEqualTo(2); - assertThat(set).contains("bar"); - assertThat(set).contains("jenny"); + assertThat(set).isInstanceOf(TreeSet.class).containsOnly("bar", "jenny"); } @Test - public void testPrototypeSetFactory() { + void testPrototypeSetFactory() { Set set = (Set) this.beanFactory.getBean("pSetFactory"); - assertThat(set).isInstanceOf(TreeSet.class); - assertThat(set.size()).isEqualTo(2); - assertThat(set).contains("bar"); - assertThat(set).contains("jenny"); + assertThat(set).isInstanceOf(TreeSet.class).containsOnly("bar", "jenny"); } @Test - public void testMapFactory() { + void testMapFactory() { Map map = (Map) this.beanFactory.getBean("mapFactory"); - assertThat(map).isInstanceOf(TreeMap.class); - assertThat(map.size()).isEqualTo(2); - assertThat(map.get("foo")).isEqualTo("bar"); - assertThat(map.get("jen")).isEqualTo("jenny"); + assertThat(map).isInstanceOf(TreeMap.class).containsOnly( + entry("foo", "bar"), entry("jen", "jenny")); } @Test - public void testPrototypeMapFactory() { + void testPrototypeMapFactory() { Map map = (Map) this.beanFactory.getBean("pMapFactory"); - assertThat(map).isInstanceOf(TreeMap.class); - assertThat(map.size()).isEqualTo(2); - assertThat(map.get("foo")).isEqualTo("bar"); - assertThat(map.get("jen")).isEqualTo("jenny"); + assertThat(map).isInstanceOf(TreeMap.class).containsOnly( + entry("foo", "bar"), entry("jen", "jenny")); } @Test - public void testChoiceBetweenSetAndMap() { + void testChoiceBetweenSetAndMap() { MapAndSet sam = (MapAndSet) this.beanFactory.getBean("setAndMap"); assertThat(sam.getObject() instanceof Map).as("Didn't choose constructor with Map argument").isTrue(); Map map = (Map) sam.getObject(); - assertThat(map).hasSize(3); - assertThat(map.get("key1")).isEqualTo("val1"); - assertThat(map.get("key2")).isEqualTo("val2"); - assertThat(map.get("key3")).isEqualTo("val3"); + assertThat(map).containsOnly(entry("key1", "val1"), entry("key2", "val2"), entry("key3", "val3")); } @Test - public void testEnumSetFactory() { + void testEnumSetFactory() { Set set = (Set) this.beanFactory.getBean("enumSetFactory"); - assertThat(set.size()).isEqualTo(2); - assertThat(set).contains("ONE"); - assertThat(set).contains("TWO"); + assertThat(set).containsOnly("ONE", "TWO"); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlListableBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlListableBeanFactoryTests.java index c77c851a8ed..0699edb4a58 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlListableBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/XmlListableBeanFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -44,7 +44,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @since 09.11.2003 */ @SuppressWarnings({"rawtypes", "unchecked"}) -public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTests { +class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTests { private DefaultListableBeanFactory parent; @@ -52,7 +52,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest @BeforeEach - public void setup() { + void setup() { parent = new DefaultListableBeanFactory(); Map map = new HashMap(); @@ -105,24 +105,24 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest } @Test - public void beanCount() { + void beanCount() { assertTestBeanCount(13); } @Test - public void lifecycleMethods() { + void lifecycleMethods() { LifecycleBean bean = (LifecycleBean) getBeanFactory().getBean("lifecycle"); bean.businessMethod(); } @Test - public void protectedLifecycleMethods() { + void protectedLifecycleMethods() { ProtectedLifecycleBean bean = (ProtectedLifecycleBean) getBeanFactory().getBean("protectedLifecycle"); bean.businessMethod(); } @Test - public void descriptionButNoProperties() { + void descriptionButNoProperties() { TestBean validEmpty = (TestBean) getBeanFactory().getBean("validEmptyWithDescription"); assertThat(validEmpty.getAge()).isZero(); } @@ -131,7 +131,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest * Test that properties with name as well as id creating an alias up front. */ @Test - public void autoAliasing() { + void autoAliasing() { List beanNames = Arrays.asList(getListableBeanFactory().getBeanDefinitionNames()); TestBean tb1 = (TestBean) getBeanFactory().getBean("aliased"); @@ -191,7 +191,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest } @Test - public void factoryNesting() { + void factoryNesting() { ITestBean father = (ITestBean) getBeanFactory().getBean("father"); assertThat(father).as("Bean from root context").isNotNull(); @@ -204,7 +204,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest } @Test - public void factoryReferences() { + void factoryReferences() { DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory"); DummyReferencer ref = (DummyReferencer) getBeanFactory().getBean("factoryReferencer"); @@ -217,7 +217,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest } @Test - public void prototypeReferences() { + void prototypeReferences() { // check that not broken by circular reference resolution mechanism DummyReferencer ref1 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer"); assertThat(ref1.getTestBean1()).as("Not referencing same bean twice").isNotSameAs(ref1.getTestBean2()); @@ -230,7 +230,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest } @Test - public void beanPostProcessor() { + void beanPostProcessor() { TestBean kerry = (TestBean) getBeanFactory().getBean("kerry"); TestBean kathy = (TestBean) getBeanFactory().getBean("kathy"); DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory"); @@ -242,7 +242,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest } @Test - public void emptyValues() { + void emptyValues() { TestBean rod = (TestBean) getBeanFactory().getBean("rod"); TestBean kerry = (TestBean) getBeanFactory().getBean("kerry"); assertThat(rod.getTouchy()).as("Touchy is empty").isEqualTo(""); @@ -250,7 +250,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest } @Test - public void commentsAndCdataInValue() { + void commentsAndCdataInValue() { TestBean bean = (TestBean) getBeanFactory().getBean("commentsInValue"); assertThat(bean.getName()).as("Failed to handle comments and CDATA properly").isEqualTo("this is a "); } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java index faa41995e6d..0aa52baa162 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/support/DefaultNamespaceHandlerResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2024 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. @@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rob Harrop * @author Rick Evans */ -public class DefaultNamespaceHandlerResolverTests { +class DefaultNamespaceHandlerResolverTests { @Test - public void testResolvedMappedHandler() { + void testResolvedMappedHandler() { DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader()); NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util"); assertThat(handler).as("Handler should not be null.").isNotNull(); @@ -42,7 +42,7 @@ public class DefaultNamespaceHandlerResolverTests { } @Test - public void testResolvedMappedHandlerWithNoArgCtor() { + void testResolvedMappedHandlerWithNoArgCtor() { DefaultNamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(); NamespaceHandler handler = resolver.resolve("http://www.springframework.org/schema/util"); assertThat(handler).as("Handler should not be null.").isNotNull(); @@ -50,25 +50,25 @@ public class DefaultNamespaceHandlerResolverTests { } @Test - public void testNonExistentHandlerClass() { + void testNonExistentHandlerClass() { String mappingPath = "org/springframework/beans/factory/xml/support/nonExistent.properties"; new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), mappingPath); } @Test - public void testCtorWithNullClassLoaderArgument() { + void testCtorWithNullClassLoaderArgument() { // simply must not bail... new DefaultNamespaceHandlerResolver(null); } @Test - public void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() { + void testCtorWithNullClassLoaderArgumentAndNullMappingLocationArgument() { assertThatIllegalArgumentException().isThrownBy(() -> new DefaultNamespaceHandlerResolver(null, null)); } @Test - public void testCtorWithNonExistentMappingLocationArgument() { + void testCtorWithNonExistentMappingLocationArgument() { // simply must not bail; we don't want non-existent resources to result in an Exception new DefaultNamespaceHandlerResolver(null, "738trbc bobabloobop871"); } diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/BeanInfoTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/BeanInfoTests.java index 7b91fc60e64..73dbf712458 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/BeanInfoTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/BeanInfoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 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. @@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @since 06.03.2006 */ -public class BeanInfoTests { +class BeanInfoTests { @Test - public void testComplexObject() { + void testComplexObject() { ValueBean bean = new ValueBean(); BeanWrapper bw = new BeanWrapperImpl(bean); Integer value = 1; diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditorTests.java index ef5bdc87d76..d2789c44f97 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -27,12 +27,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rick Evans */ -public class ByteArrayPropertyEditorTests { +class ByteArrayPropertyEditorTests { private final PropertyEditor byteEditor = new ByteArrayPropertyEditor(); @Test - public void sunnyDaySetAsText() throws Exception { + void sunnyDaySetAsText() { final String text = "Hideous towns make me throw... up"; byteEditor.setAsText(text); @@ -46,7 +46,7 @@ public class ByteArrayPropertyEditorTests { } @Test - public void getAsTextReturnsEmptyStringIfValueIsNull() throws Exception { + void getAsTextReturnsEmptyStringIfValueIsNull() { assertThat(byteEditor.getAsText()).isEmpty(); byteEditor.setAsText(null); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditorTests.java index af09ae6c6e0..f11de8c9137 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -27,12 +27,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Rick Evans */ -public class CharArrayPropertyEditorTests { +class CharArrayPropertyEditorTests { private final PropertyEditor charEditor = new CharArrayPropertyEditor(); @Test - public void sunnyDaySetAsText() throws Exception { + void sunnyDaySetAsText() { final String text = "Hideous towns make me throw... up"; charEditor.setAsText(text); @@ -46,7 +46,7 @@ public class CharArrayPropertyEditorTests { } @Test - public void getAsTextReturnsEmptyStringIfValueIsNull() throws Exception { + void getAsTextReturnsEmptyStringIfValueIsNull() { assertThat(charEditor.getAsText()).isEmpty(); charEditor.setAsText(null); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomCollectionEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomCollectionEditorTests.java index 2a2e219c94d..8b679705706 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomCollectionEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomCollectionEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rick Evans * @author Chris Beams */ -public class CustomCollectionEditorTests { +class CustomCollectionEditorTests { @Test - public void testCtorWithNullCollectionType() { + void testCtorWithNullCollectionType() { assertThatIllegalArgumentException().isThrownBy(() -> new CustomCollectionEditor(null)); } @@ -47,38 +47,34 @@ public class CustomCollectionEditorTests { } @Test - public void testWithCollectionTypeThatDoesNotExposeAPublicNoArgCtor() { + void testWithCollectionTypeThatDoesNotExposeAPublicNoArgCtor() { CustomCollectionEditor editor = new CustomCollectionEditor(CollectionTypeWithNoNoArgCtor.class); assertThatIllegalArgumentException().isThrownBy(() -> editor.setValue("1")); } @Test - public void testSunnyDaySetValue() { + void testSunnyDaySetValue() { CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class); editor.setValue(new int[] {0, 1, 2}); Object value = editor.getValue(); assertThat(value).isNotNull(); assertThat(value).isInstanceOf(ArrayList.class); - List list = (List) value; - assertThat(list).as("There must be 3 elements in the converted collection").hasSize(3); - assertThat(list).element(0).isEqualTo(0); - assertThat(list).element(1).isEqualTo(1); - assertThat(list).element(2).isEqualTo(2); + assertThat(value).asList().containsExactly(0, 1, 2); } @Test - public void testWhenTargetTypeIsExactlyTheCollectionInterfaceUsesFallbackCollectionType() { + void testWhenTargetTypeIsExactlyTheCollectionInterfaceUsesFallbackCollectionType() { CustomCollectionEditor editor = new CustomCollectionEditor(Collection.class); editor.setValue("0, 1, 2"); Collection value = (Collection) editor.getValue(); assertThat(value).isNotNull(); assertThat(value).as("There must be 1 element in the converted collection").hasSize(1); - assertThat(value).element(0).isEqualTo("0, 1, 2"); + assertThat(value).singleElement().isEqualTo("0, 1, 2"); } @Test - public void testSunnyDaySetAsTextYieldsSingleValue() { + void testSunnyDaySetAsTextYieldsSingleValue() { CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class); editor.setValue("0, 1, 2"); Object value = editor.getValue(); @@ -86,7 +82,7 @@ public class CustomCollectionEditorTests { assertThat(value).isInstanceOf(ArrayList.class); List list = (List) value; assertThat(list).as("There must be 1 element in the converted collection").hasSize(1); - assertThat(list).element(0).isEqualTo("0, 1, 2"); + assertThat(list).singleElement().isEqualTo("0, 1, 2"); } diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java index 61137bb2ee2..cc9c22048dd 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/CustomEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -18,7 +18,6 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditor; import java.beans.PropertyEditorSupport; -import java.beans.PropertyVetoException; import java.io.File; import java.math.BigDecimal; import java.math.BigInteger; @@ -1319,7 +1318,6 @@ class CustomEditorTests { } @Test - @SuppressWarnings("unchecked") void indexedPropertiesWithListPropertyEditor() { IndexedTestBean bean = new IndexedTestBean(); BeanWrapper bw = new BeanWrapperImpl(bean); @@ -1334,11 +1332,11 @@ class CustomEditorTests { bw.setPropertyValue("list", "1"); assertThat(((TestBean) bean.getList().get(0)).getName()).isEqualTo("list1"); bw.setPropertyValue("list[0]", "test"); - assertThat(bean.getList()).element(0).isEqualTo("test"); + assertThat(bean.getList()).singleElement().isEqualTo("test"); } @Test - void conversionToOldCollections() throws PropertyVetoException { + void conversionToOldCollections() { OldCollectionsBean tb = new OldCollectionsBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(Vector.class, new CustomCollectionEditor(Vector.class)); @@ -1355,7 +1353,6 @@ class CustomEditorTests { } @Test - @SuppressWarnings("unchecked") void uninitializedArrayPropertyWithCustomEditor() { IndexedTestBean bean = new IndexedTestBean(false); BeanWrapper bw = new BeanWrapperImpl(bean); @@ -1372,7 +1369,7 @@ class CustomEditorTests { } @Test - void arrayToArrayConversion() throws PropertyVetoException { + void arrayToArrayConversion() { IndexedTestBean tb = new IndexedTestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() { @@ -1388,7 +1385,7 @@ class CustomEditorTests { } @Test - void arrayToStringConversion() throws PropertyVetoException { + void arrayToStringConversion() { TestBean tb = new TestBean(); BeanWrapper bw = new BeanWrapperImpl(tb); bw.registerCustomEditor(String.class, new PropertyEditorSupport() { diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java index 7fbb37bb072..ff4dbeb6c9a 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Chris Beams * @author Juergen Hoeller */ -public class FileEditorTests { +class FileEditorTests { @Test - public void testClasspathFileName() { + void testClasspathFileName() { PropertyEditor fileEditor = new FileEditor(); fileEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"); @@ -45,14 +45,14 @@ public class FileEditorTests { } @Test - public void testWithNonExistentResource() { + void testWithNonExistentResource() { PropertyEditor propertyEditor = new FileEditor(); assertThatIllegalArgumentException().isThrownBy(() -> propertyEditor.setAsText("classpath:no_way_this_file_is_found.doc")); } @Test - public void testWithNonExistentFile() { + void testWithNonExistentFile() { PropertyEditor fileEditor = new FileEditor(); fileEditor.setAsText("file:no_way_this_file_is_found.doc"); Object value = fileEditor.getValue(); @@ -62,7 +62,7 @@ public class FileEditorTests { } @Test - public void testAbsoluteFileName() { + void testAbsoluteFileName() { PropertyEditor fileEditor = new FileEditor(); fileEditor.setAsText("/no_way_this_file_is_found.doc"); Object value = fileEditor.getValue(); @@ -72,7 +72,7 @@ public class FileEditorTests { } @Test - public void testUnqualifiedFileNameFound() { + void testUnqualifiedFileNameFound() { PropertyEditor fileEditor = new FileEditor(); String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"; @@ -86,7 +86,7 @@ public class FileEditorTests { } @Test - public void testUnqualifiedFileNameNotFound() { + void testUnqualifiedFileNameNotFound() { PropertyEditor fileEditor = new FileEditor(); String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".clazz"; diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java index 37b3b77c22d..f58f178cd4b 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -32,16 +32,16 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rick Evans * @author Chris Beams */ -public class InputStreamEditorTests { +class InputStreamEditorTests { @Test - public void testCtorWithNullResourceEditor() { + void testCtorWithNullResourceEditor() { assertThatIllegalArgumentException().isThrownBy(() -> new InputStreamEditor(null)); } @Test - public void testSunnyDay() throws IOException { + void testSunnyDay() throws IOException { InputStream stream = null; try { String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + @@ -62,14 +62,14 @@ public class InputStreamEditorTests { } @Test - public void testWhenResourceDoesNotExist() { + void testWhenResourceDoesNotExist() { InputStreamEditor editor = new InputStreamEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("classpath:bingo!")); } @Test - public void testGetAsTextReturnsNullByDefault() { + void testGetAsTextReturnsNullByDefault() { assertThat(new InputStreamEditor().getAsText()).isNull(); String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"; diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java index d55cc18d48a..52098fe5ce2 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Juergen Hoeller * @since 4.3.2 */ -public class PathEditorTests { +class PathEditorTests { @Test - public void testClasspathPathName() { + void testClasspathPathName() { PropertyEditor pathEditor = new PathEditor(); pathEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"); @@ -45,14 +45,14 @@ public class PathEditorTests { } @Test - public void testWithNonExistentResource() { + void testWithNonExistentResource() { PropertyEditor propertyEditor = new PathEditor(); assertThatIllegalArgumentException().isThrownBy(() -> propertyEditor.setAsText("classpath:/no_way_this_file_is_found.doc")); } @Test - public void testWithNonExistentPath() { + void testWithNonExistentPath() { PropertyEditor pathEditor = new PathEditor(); pathEditor.setAsText("file:/no_way_this_file_is_found.doc"); Object value = pathEditor.getValue(); @@ -62,7 +62,7 @@ public class PathEditorTests { } @Test - public void testAbsolutePath() { + void testAbsolutePath() { PropertyEditor pathEditor = new PathEditor(); pathEditor.setAsText("/no_way_this_file_is_found.doc"); Object value = pathEditor.getValue(); @@ -72,7 +72,7 @@ public class PathEditorTests { } @Test - public void testWindowsAbsolutePath() { + void testWindowsAbsolutePath() { PropertyEditor pathEditor = new PathEditor(); pathEditor.setAsText("C:\\no_way_this_file_is_found.doc"); Object value = pathEditor.getValue(); @@ -82,7 +82,7 @@ public class PathEditorTests { } @Test - public void testWindowsAbsoluteFilePath() { + void testWindowsAbsoluteFilePath() { PropertyEditor pathEditor = new PathEditor(); try { pathEditor.setAsText("file://C:\\no_way_this_file_is_found.doc"); @@ -99,7 +99,7 @@ public class PathEditorTests { } @Test - public void testUnqualifiedPathNameFound() { + void testUnqualifiedPathNameFound() { PropertyEditor pathEditor = new PathEditor(); String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"; @@ -117,7 +117,7 @@ public class PathEditorTests { } @Test - public void testUnqualifiedPathNameNotFound() { + void testUnqualifiedPathNameNotFound() { PropertyEditor pathEditor = new PathEditor(); String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".clazz"; diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PropertiesEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PropertiesEditorTests.java index 9a0b3f89473..7f879672805 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PropertiesEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/PropertiesEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @author Rick Evans */ -public class PropertiesEditorTests { +class PropertiesEditorTests { @Test - public void oneProperty() { + void oneProperty() { String s = "foo=bar"; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); @@ -45,7 +45,7 @@ public class PropertiesEditorTests { } @Test - public void twoProperties() { + void twoProperties() { String s = "foo=bar with whitespace\n" + "me=mi"; PropertiesEditor pe= new PropertiesEditor(); @@ -57,7 +57,7 @@ public class PropertiesEditorTests { } @Test - public void handlesEqualsInValue() { + void handlesEqualsInValue() { String s = """ foo=bar me=mi @@ -72,7 +72,7 @@ public class PropertiesEditorTests { } @Test - public void handlesEmptyProperty() { + void handlesEmptyProperty() { String s = "foo=bar\nme=mi\nx="; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); @@ -84,7 +84,7 @@ public class PropertiesEditorTests { } @Test - public void handlesEmptyPropertyWithoutEquals() { + void handlesEmptyPropertyWithoutEquals() { String s = "foo\nme=mi\nx=x"; PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(s); @@ -98,7 +98,7 @@ public class PropertiesEditorTests { * Comments begin with # */ @Test - public void ignoresCommentLinesAndEmptyLines() { + void ignoresCommentLinesAndEmptyLines() { String s = """ #Ignore this comment foo=bar @@ -122,7 +122,7 @@ public class PropertiesEditorTests { * still ignored: The standard syntax doesn't allow this on JDK 1.3. */ @Test - public void ignoresLeadingSpacesAndTabs() { + void ignoresLeadingSpacesAndTabs() { String s = " #Ignore this comment\n" + "\t\tfoo=bar\n" + "\t#Another comment more junk \n" + @@ -138,7 +138,7 @@ public class PropertiesEditorTests { } @Test - public void nullValue() { + void nullValue() { PropertiesEditor pe= new PropertiesEditor(); pe.setAsText(null); Properties p = (Properties) pe.getValue(); @@ -146,7 +146,7 @@ public class PropertiesEditorTests { } @Test - public void emptyString() { + void emptyString() { PropertiesEditor pe = new PropertiesEditor(); pe.setAsText(""); Properties p = (Properties) pe.getValue(); @@ -154,7 +154,7 @@ public class PropertiesEditorTests { } @Test - public void usingMapAsValueSource() { + void usingMapAsValueSource() { Map map = new HashMap<>(); map.put("one", "1"); map.put("two", "2"); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java index bb05b193e60..1badc91dea2 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -32,16 +32,16 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Juergen Hoeller * @since 4.2 */ -public class ReaderEditorTests { +class ReaderEditorTests { @Test - public void testCtorWithNullResourceEditor() { + void testCtorWithNullResourceEditor() { assertThatIllegalArgumentException().isThrownBy(() -> new ReaderEditor(null)); } @Test - public void testSunnyDay() throws IOException { + void testSunnyDay() throws IOException { Reader reader = null; try { String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + @@ -62,7 +62,7 @@ public class ReaderEditorTests { } @Test - public void testWhenResourceDoesNotExist() { + void testWhenResourceDoesNotExist() { String resource = "classpath:bingo!"; ReaderEditor editor = new ReaderEditor(); assertThatIllegalArgumentException().isThrownBy(() -> @@ -70,7 +70,7 @@ public class ReaderEditorTests { } @Test - public void testGetAsTextReturnsNullByDefault() { + void testGetAsTextReturnsNullByDefault() { assertThat(new ReaderEditor().getAsText()).isNull(); String resource = "classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"; diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ResourceBundleEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ResourceBundleEditorTests.java index 4cbdef1ddc4..469c71db2fd 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ResourceBundleEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/ResourceBundleEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rick Evans * @author Chris Beams */ -public class ResourceBundleEditorTests { +class ResourceBundleEditorTests { private static final String BASE_NAME = ResourceBundleEditorTests.class.getName(); @@ -37,7 +37,7 @@ public class ResourceBundleEditorTests { @Test - public void testSetAsTextWithJustBaseName() { + void testSetAsTextWithJustBaseName() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME); Object value = editor.getValue(); @@ -49,7 +49,7 @@ public class ResourceBundleEditorTests { } @Test - public void testSetAsTextWithBaseNameThatEndsInDefaultSeparator() { + void testSetAsTextWithBaseNameThatEndsInDefaultSeparator() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME + "_"); Object value = editor.getValue(); @@ -61,7 +61,7 @@ public class ResourceBundleEditorTests { } @Test - public void testSetAsTextWithBaseNameAndLanguageCode() { + void testSetAsTextWithBaseNameAndLanguageCode() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME + "Lang" + "_en"); Object value = editor.getValue(); @@ -73,7 +73,7 @@ public class ResourceBundleEditorTests { } @Test - public void testSetAsTextWithBaseNameLanguageAndCountryCode() { + void testSetAsTextWithBaseNameLanguageAndCountryCode() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME + "LangCountry" + "_en_GB"); Object value = editor.getValue(); @@ -85,7 +85,7 @@ public class ResourceBundleEditorTests { } @Test - public void testSetAsTextWithTheKitchenSink() { + void testSetAsTextWithTheKitchenSink() { ResourceBundleEditor editor = new ResourceBundleEditor(); editor.setAsText(BASE_NAME + "LangCountryDialect" + "_en_GB_GLASGOW"); Object value = editor.getValue(); @@ -97,28 +97,28 @@ public class ResourceBundleEditorTests { } @Test - public void testSetAsTextWithNull() { + void testSetAsTextWithNull() { ResourceBundleEditor editor = new ResourceBundleEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText(null)); } @Test - public void testSetAsTextWithEmptyString() { + void testSetAsTextWithEmptyString() { ResourceBundleEditor editor = new ResourceBundleEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("")); } @Test - public void testSetAsTextWithWhiteSpaceString() { + void testSetAsTextWithWhiteSpaceString() { ResourceBundleEditor editor = new ResourceBundleEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText(" ")); } @Test - public void testSetAsTextWithJustSeparatorString() { + void testSetAsTextWithJustSeparatorString() { ResourceBundleEditor editor = new ResourceBundleEditor(); assertThatIllegalArgumentException().isThrownBy(() -> editor.setAsText("_")); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java index 4402d6fe53c..18c28234c21 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -29,30 +29,30 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Juergen Hoeller * @author Arjen Poutsma */ -public class URIEditorTests { +class URIEditorTests { @Test - public void standardURI() { + void standardURI() { doTestURI("mailto:juergen.hoeller@interface21.com"); } @Test - public void withNonExistentResource() { + void withNonExistentResource() { doTestURI("gonna:/freak/in/the/morning/freak/in/the.evening"); } @Test - public void standardURL() { + void standardURL() { doTestURI("https://www.springframework.org"); } @Test - public void standardURLWithFragment() { + void standardURLWithFragment() { doTestURI("https://www.springframework.org#1"); } @Test - public void standardURLWithWhitespace() { + void standardURLWithWhitespace() { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText(" https://www.springframework.org "); Object value = uriEditor.getValue(); @@ -62,7 +62,7 @@ public class URIEditorTests { } @Test - public void classpathURL() { + void classpathURL() { PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader()); uriEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"); @@ -74,7 +74,7 @@ public class URIEditorTests { } @Test - public void classpathURLWithWhitespace() { + void classpathURLWithWhitespace() { PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader()); uriEditor.setAsText(" classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class "); @@ -86,7 +86,7 @@ public class URIEditorTests { } @Test - public void classpathURLAsIs() { + void classpathURLAsIs() { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText("classpath:test.txt"); Object value = uriEditor.getValue(); @@ -97,7 +97,7 @@ public class URIEditorTests { } @Test - public void setAsTextWithNull() { + void setAsTextWithNull() { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText(null); assertThat(uriEditor.getValue()).isNull(); @@ -105,13 +105,13 @@ public class URIEditorTests { } @Test - public void getAsTextReturnsEmptyStringIfValueNotSet() { + void getAsTextReturnsEmptyStringIfValueNotSet() { PropertyEditor uriEditor = new URIEditor(); assertThat(uriEditor.getAsText()).isEmpty(); } @Test - public void encodeURI() { + void encodeURI() { PropertyEditor uriEditor = new URIEditor(); uriEditor.setAsText("https://example.com/spaces and \u20AC"); Object value = uriEditor.getValue(); @@ -122,7 +122,7 @@ public class URIEditorTests { } @Test - public void encodeAlreadyEncodedURI() { + void encodeAlreadyEncodedURI() { PropertyEditor uriEditor = new URIEditor(false); uriEditor.setAsText("https://example.com/spaces%20and%20%E2%82%AC"); Object value = uriEditor.getValue(); diff --git a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java index 82079afc7f2..4b63b6e7f60 100644 --- a/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -30,16 +30,16 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException * @author Rick Evans * @author Chris Beams */ -public class URLEditorTests { +class URLEditorTests { @Test - public void testCtorWithNullResourceEditor() { + void testCtorWithNullResourceEditor() { assertThatIllegalArgumentException().isThrownBy(() -> new URLEditor(null)); } @Test - public void testStandardURI() { + void testStandardURI() { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("mailto:juergen.hoeller@interface21.com"); Object value = urlEditor.getValue(); @@ -49,7 +49,7 @@ public class URLEditorTests { } @Test - public void testStandardURL() { + void testStandardURL() { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("https://www.springframework.org"); Object value = urlEditor.getValue(); @@ -59,7 +59,7 @@ public class URLEditorTests { } @Test - public void testClasspathURL() { + void testClasspathURL() { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText("classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class"); @@ -71,14 +71,14 @@ public class URLEditorTests { } @Test - public void testWithNonExistentResource() { + void testWithNonExistentResource() { PropertyEditor urlEditor = new URLEditor(); assertThatIllegalArgumentException().isThrownBy(() -> urlEditor.setAsText("gonna:/freak/in/the/morning/freak/in/the.evening")); } @Test - public void testSetAsTextWithNull() { + void testSetAsTextWithNull() { PropertyEditor urlEditor = new URLEditor(); urlEditor.setAsText(null); assertThat(urlEditor.getValue()).isNull(); @@ -86,7 +86,7 @@ public class URLEditorTests { } @Test - public void testGetAsTextReturnsEmptyStringIfValueNotSet() { + void testGetAsTextReturnsEmptyStringIfValueNotSet() { PropertyEditor urlEditor = new URLEditor(); assertThat(urlEditor.getAsText()).isEmpty(); } diff --git a/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java b/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java index 876233fb3f2..110ea997974 100644 --- a/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Chris Beams * @since 20.05.2003 */ -public class PagedListHolderTests { +class PagedListHolderTests { @Test @SuppressWarnings({ "rawtypes", "unchecked" }) diff --git a/spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java b/spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java index aac0b2097b0..c584e9caa31 100644 --- a/spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -28,10 +28,10 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Keith Donald * @author Chris Beams */ -public class PropertyComparatorTests { +class PropertyComparatorTests { @Test - public void testPropertyComparator() { + void testPropertyComparator() { Dog dog = new Dog(); dog.setNickName("mace"); @@ -45,7 +45,7 @@ public class PropertyComparatorTests { } @Test - public void testPropertyComparatorNulls() { + void testPropertyComparatorNulls() { Dog dog = new Dog(); Dog dog2 = new Dog(); PropertyComparator c = new PropertyComparator<>("nickName", false, true); @@ -53,7 +53,7 @@ public class PropertyComparatorTests { } @Test - public void testChainedComparators() { + void testChainedComparators() { Comparator c = new PropertyComparator<>("lastName", false, true); Dog dog1 = new Dog(); @@ -74,7 +74,7 @@ public class PropertyComparatorTests { } @Test - public void testChainedComparatorsReversed() { + void testChainedComparatorsReversed() { Comparator c = (new PropertyComparator("lastName", false, true)). thenComparing(new PropertyComparator<>("firstName", false, true)); diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/StringFactoryBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/StringFactoryBean.java new file mode 100644 index 00000000000..65f72324536 --- /dev/null +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/StringFactoryBean.java @@ -0,0 +1,40 @@ +/* + * Copyright 2002-2024 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans.testfixture.beans.factory; + +import org.springframework.beans.factory.FactoryBean; + +public class StringFactoryBean implements FactoryBean { + + @Override + public String getObject() { + return ""; + } + + @Override + public Class getObjectType() { + return String.class; + } + + @Override + public boolean isSingleton() { + return true; + } + +} + +