From f26a7dee977a0f109596cdc42f3aa8cb2fc1d846 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 8 Nov 2022 20:03:01 +0100 Subject: [PATCH] Fix broken tests, update copyright dates, and polish See gh-29414 --- .../beans/AbstractPropertyAccessorTests.java | 2 +- .../springframework/beans/BeanUtilsTests.java | 22 ++- .../beans/BeanWrapperGenericsTests.java | 2 +- .../config/YamlMapFactoryBeanTests.java | 2 +- .../propertyeditors/CustomEditorTests.java | 2 +- .../beans/testfixture/beans/TestBean.java | 2 +- .../aop/aspectj/AroundAdviceBindingTests.java | 2 +- .../config/ScriptingDefaultsTests.java | 2 +- .../springframework/core/ConstantsTests.java | 2 +- .../core/convert/TypeDescriptorTests.java | 2 +- .../DefaultConversionServiceTests.java | 155 ++++++------------ .../GenericConversionServiceTests.java | 18 +- .../util/CollectionUtilsTests.java | 2 +- .../util/NumberUtilsTests.java | 2 +- .../spel/AbstractExpressionTests.java | 2 +- .../spel/ast/FormatHelperTests.java | 2 +- .../expression/spel/ast/OpPlusTests.java | 2 +- .../jdbc/core/JdbcTemplateQueryTests.java | 2 +- .../namedparam/NamedParameterQueryTests.java | 2 +- .../dao/support/DataAccessUtilsTests.java | 2 +- ...jectToStringHttpMessageConverterTests.java | 2 +- .../ServletRequestAttributesTests.java | 2 +- .../web/servlet/tags/form/InputTagTests.java | 2 +- 23 files changed, 87 insertions(+), 148 deletions(-) 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 e22c7cffc6..cae248880f 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-2021 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java index 07cb72da6e..6be56ed7ec 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java @@ -28,7 +28,6 @@ import java.net.URL; import java.time.DayOfWeek; import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Locale; @@ -227,8 +226,8 @@ class BeanUtilsTests { IntegerListHolder2 integerListHolder2 = new IntegerListHolder2(); BeanUtils.copyProperties(integerListHolder1, integerListHolder2); - assertThat(integerListHolder1.getList()).containsOnly(42); - assertThat(integerListHolder2.getList()).containsOnly(42); + assertThat(integerListHolder1.getList()).containsExactly(42); + assertThat(integerListHolder2.getList()).containsExactly(42); } /** @@ -236,7 +235,7 @@ class BeanUtilsTests { */ @Test void copyPropertiesHonorsGenericTypeMatchesFromWildcardToWildcard() { - List list = Arrays.asList("foo", 42); + List list = List.of("foo", 42); WildcardListHolder1 wildcardListHolder1 = new WildcardListHolder1(); wildcardListHolder1.setList(list); WildcardListHolder2 wildcardListHolder2 = new WildcardListHolder2(); @@ -257,8 +256,8 @@ class BeanUtilsTests { WildcardListHolder2 wildcardListHolder2 = new WildcardListHolder2(); BeanUtils.copyProperties(integerListHolder1, wildcardListHolder2); - assertThat(integerListHolder1.getList()).containsOnly(42); - assertThat(wildcardListHolder2.getList()).isEqualTo(Arrays.asList(42)); + assertThat(integerListHolder1.getList()).containsExactly(42); + assertThat(wildcardListHolder2.getList()).isEqualTo(List.of(42)); } /** @@ -271,9 +270,8 @@ class BeanUtilsTests { NumberUpperBoundedWildcardListHolder numberListHolder = new NumberUpperBoundedWildcardListHolder(); BeanUtils.copyProperties(integerListHolder1, numberListHolder); - assertThat(integerListHolder1.getList()).containsOnly(42); - assertThat(numberListHolder.getList()).hasSize(1); - assertThat(numberListHolder.getList().contains(42)).isTrue(); + assertThat(integerListHolder1.getList()).containsExactly(42); + assertThat(numberListHolder.getList()).isEqualTo(List.of(42)); } /** @@ -300,7 +298,7 @@ class BeanUtilsTests { LongListHolder longListHolder = new LongListHolder(); BeanUtils.copyProperties(integerListHolder, longListHolder); - assertThat(integerListHolder.getList()).containsOnly(42); + assertThat(integerListHolder.getList()).containsExactly(42); assertThat(longListHolder.getList()).isEmpty(); } @@ -314,13 +312,13 @@ class BeanUtilsTests { NumberListHolder numberListHolder = new NumberListHolder(); BeanUtils.copyProperties(integerListHolder, numberListHolder); - assertThat(integerListHolder.getList()).containsOnly(42); + assertThat(integerListHolder.getList()).containsExactly(42); assertThat(numberListHolder.getList()).isEmpty(); } @Test // gh-26531 void copyPropertiesIgnoresGenericsIfSourceOrTargetHasUnresolvableGenerics() throws Exception { - Order original = new Order("test", Arrays.asList("foo", "bar")); + Order original = new Order("test", List.of("foo", "bar")); // Create a Proxy that loses the generic type information for the getLineItems() method. OrderSummary proxy = proxyOrder(original); 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 3b87c24e76..16bc4de0e2 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-2021 the original author or authors. + * Copyright 2002-2022 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. 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 09acfd2864..b5d4459612 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-2019 the original author or authors. + * Copyright 2002-2022 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. 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 9ccb93e112..aa3b733412 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-2021 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java index 8b9e6442b9..e9f9e107e8 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/AroundAdviceBindingTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/AroundAdviceBindingTests.java index c78008d33a..267c82df47 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/AroundAdviceBindingTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/AroundAdviceBindingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-context/src/test/java/org/springframework/scripting/config/ScriptingDefaultsTests.java b/spring-context/src/test/java/org/springframework/scripting/config/ScriptingDefaultsTests.java index 710705d155..770758e0e7 100644 --- a/spring-context/src/test/java/org/springframework/scripting/config/ScriptingDefaultsTests.java +++ b/spring-context/src/test/java/org/springframework/scripting/config/ScriptingDefaultsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-core/src/test/java/org/springframework/core/ConstantsTests.java b/spring-core/src/test/java/org/springframework/core/ConstantsTests.java index ccb3d9a225..a7331ec97d 100644 --- a/spring-core/src/test/java/org/springframework/core/ConstantsTests.java +++ b/spring-core/src/test/java/org/springframework/core/ConstantsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java b/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java index 8430ebd4c4..82e0535d44 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java index 12ad90e551..3f875f4bbe 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java @@ -25,7 +25,6 @@ import java.nio.charset.StandardCharsets; import java.time.ZoneId; import java.util.AbstractList; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Currency; @@ -154,7 +153,7 @@ class DefaultConversionServiceTests { @Test void stringToInteger() { - assertThat(conversionService.convert("1", Integer.class)).isEqualTo((int) 1); + assertThat(conversionService.convert("1", Integer.class)).isEqualTo(1); } @Test @@ -259,7 +258,7 @@ class DefaultConversionServiceTests { @Test void enumToInteger() { - assertThat(conversionService.convert(Foo.BAR, Integer.class)).isEqualTo((int) 0); + assertThat(conversionService.convert(Foo.BAR, Integer.class)).isEqualTo(0); } @Test @@ -343,9 +342,7 @@ class DefaultConversionServiceTests { @Test void convertArrayToCollectionInterface() { List result = conversionService.convert(new String[] {"1", "2", "3"}, List.class); - assertThat(result.get(0)).isEqualTo("1"); - assertThat(result.get(1)).isEqualTo("2"); - assertThat(result.get(2)).isEqualTo("3"); + assertThat(result).isEqualTo(List.of("1", "2", "3")); } @Test @@ -353,9 +350,7 @@ class DefaultConversionServiceTests { @SuppressWarnings("unchecked") List result = (List) conversionService.convert(new String[] {"1", "2", "3"}, TypeDescriptor .valueOf(String[].class), new TypeDescriptor(getClass().getDeclaredField("genericList"))); - assertThat((int) result.get(0)).isEqualTo((int) 1); - assertThat((int) result.get(1)).isEqualTo((int) 2); - assertThat((int) result.get(2)).isEqualTo((int) 3); + assertThat(result).isEqualTo(List.of(1, 2, 3)); } @Test @@ -365,7 +360,7 @@ class DefaultConversionServiceTests { Stream result = (Stream) this.conversionService.convert(source, TypeDescriptor.valueOf(String[].class), new TypeDescriptor(getClass().getDeclaredField("genericStream"))); - assertThat(result.mapToInt(x -> x).sum()).isEqualTo(8); + assertThat(result).containsExactly(1, 3, 4); } @Test @@ -376,17 +371,13 @@ class DefaultConversionServiceTests { List colors = (List) conversionService.convert(new String[] {"ffffff", "#000000"}, TypeDescriptor.valueOf(String[].class), new TypeDescriptor(new MethodParameter(getClass().getMethod("handlerMethod", List.class), 0))); - assertThat(colors.size()).isEqualTo(2); - assertThat(colors.get(0)).isEqualTo(Color.WHITE); - assertThat(colors.get(1)).isEqualTo(Color.BLACK); + assertThat(colors).containsExactly(Color.WHITE, Color.BLACK); } @Test void convertArrayToCollectionImpl() { ArrayList result = conversionService.convert(new String[] {"1", "2", "3"}, ArrayList.class); - assertThat(result.get(0)).isEqualTo("1"); - assertThat(result.get(1)).isEqualTo("2"); - assertThat(result.get(2)).isEqualTo("3"); + assertThat(result).isEqualTo(List.of("1", "2", "3")); } @Test @@ -416,34 +407,25 @@ class DefaultConversionServiceTests { @Test void convertStringToArray() { String[] result = conversionService.convert("1,2,3", String[].class); - assertThat(result.length).isEqualTo(3); - assertThat(result[0]).isEqualTo("1"); - assertThat(result[1]).isEqualTo("2"); - assertThat(result[2]).isEqualTo("3"); + assertThat(result).containsExactly("1", "2", "3"); } @Test void convertStringToArrayWithElementConversion() { Integer[] result = conversionService.convert("1,2,3", Integer[].class); - assertThat(result.length).isEqualTo(3); - assertThat((int) result[0]).isEqualTo((int) 1); - assertThat((int) result[1]).isEqualTo((int) 2); - assertThat((int) result[2]).isEqualTo((int) 3); + assertThat(result).containsExactly(1, 2, 3); } @Test void convertStringToPrimitiveArrayWithElementConversion() { int[] result = conversionService.convert("1,2,3", int[].class); - assertThat(result.length).isEqualTo(3); - assertThat(result[0]).isEqualTo(1); - assertThat(result[1]).isEqualTo(2); - assertThat(result[2]).isEqualTo(3); + assertThat(result).containsExactly(1, 2, 3); } @Test void convertEmptyStringToArray() { String[] result = conversionService.convert("", String[].class); - assertThat(result.length).isEqualTo(0); + assertThat(result).isEmpty(); } @Test @@ -457,7 +439,7 @@ class DefaultConversionServiceTests { void convertArrayToObjectWithElementConversion() { String[] array = new String[] {"3"}; Integer result = conversionService.convert(array, Integer.class); - assertThat((int) result).isEqualTo((int) 3); + assertThat(result).isEqualTo(3); } @Test @@ -477,44 +459,33 @@ class DefaultConversionServiceTests { @Test void convertObjectToArrayWithElementConversion() { Integer[] result = conversionService.convert(3L, Integer[].class); - assertThat(result.length).isEqualTo(1); - assertThat((int) result[0]).isEqualTo((int) 3); + assertThat(result).containsExactly(3); } @Test void convertCollectionToArray() { - List list = new ArrayList<>(); - list.add("1"); - list.add("2"); - list.add("3"); + List list = List.of("1", "2", "3"); String[] result = conversionService.convert(list, String[].class); - assertThat(result[0]).isEqualTo("1"); - assertThat(result[1]).isEqualTo("2"); - assertThat(result[2]).isEqualTo("3"); + assertThat(result).containsExactly("1", "2", "3"); } @Test void convertCollectionToArrayWithElementConversion() { - List list = new ArrayList<>(); - list.add("1"); - list.add("2"); - list.add("3"); + List list = List.of("1", "2", "3"); Integer[] result = conversionService.convert(list, Integer[].class); - assertThat((int) result[0]).isEqualTo((int) 1); - assertThat((int) result[1]).isEqualTo((int) 2); - assertThat((int) result[2]).isEqualTo((int) 3); + assertThat(result).containsExactly(1, 2, 3); } @Test void convertCollectionToString() { - List list = Arrays.asList("foo", "bar"); + List list = List.of("foo", "bar"); String result = conversionService.convert(list, String.class); assertThat(result).isEqualTo("foo,bar"); } @Test void convertCollectionToStringWithElementConversion() throws Exception { - List list = Arrays.asList(3, 5); + List list = List.of(3, 5); String result = (String) conversionService.convert(list, new TypeDescriptor(getClass().getField("genericList")), TypeDescriptor.valueOf(String.class)); assertThat(result).isEqualTo("3,5"); @@ -523,40 +494,34 @@ class DefaultConversionServiceTests { @Test void convertStringToCollection() { List result = conversionService.convert("1,2,3", List.class); - assertThat(result.size()).isEqualTo(3); - assertThat(result.get(0)).isEqualTo("1"); - assertThat(result.get(1)).isEqualTo("2"); - assertThat(result.get(2)).isEqualTo("3"); + assertThat(result).isEqualTo(List.of("1", "2", "3")); } @Test void convertStringToCollectionWithElementConversion() throws Exception { List result = (List) conversionService.convert("1,2,3", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("genericList"))); - assertThat(result.size()).isEqualTo(3); - assertThat(result.get(0)).isEqualTo(1); - assertThat(result.get(1)).isEqualTo(2); - assertThat(result.get(2)).isEqualTo(3); + assertThat(result).isEqualTo(List.of(1, 2, 3)); } @Test void convertEmptyStringToCollection() { Collection result = conversionService.convert("", Collection.class); - assertThat(result.size()).isEqualTo(0); + assertThat(result).isEmpty(); } @Test void convertCollectionToObject() { List list = Collections.singletonList(3L); Long result = conversionService.convert(list, Long.class); - assertThat(result).isEqualTo(Long.valueOf(3)); + assertThat(result).isEqualTo(3L); } @Test void convertCollectionToObjectWithElementConversion() { List list = Collections.singletonList("3"); Integer result = conversionService.convert(list, Integer.class); - assertThat((int) result).isEqualTo((int) 3); + assertThat(result).isEqualTo(3); } @Test @@ -580,8 +545,7 @@ class DefaultConversionServiceTests { @Test void convertObjectToCollection() { List result = conversionService.convert(3L, List.class); - assertThat(result.size()).isEqualTo(1); - assertThat(result.get(0)).isEqualTo(3L); + assertThat(result).isEqualTo(List.of(3L)); } @Test @@ -589,56 +553,43 @@ class DefaultConversionServiceTests { @SuppressWarnings("unchecked") List result = (List) conversionService.convert(3L, TypeDescriptor.valueOf(Long.class), new TypeDescriptor(getClass().getField("genericList"))); - assertThat(result.size()).isEqualTo(1); - assertThat((int) result.get(0)).isEqualTo((int) 3); + assertThat(result).containsExactly(3); } @Test void convertStringArrayToIntegerArray() { Integer[] result = conversionService.convert(new String[] {"1", "2", "3"}, Integer[].class); - assertThat((int) result[0]).isEqualTo((int) 1); - assertThat((int) result[1]).isEqualTo((int) 2); - assertThat((int) result[2]).isEqualTo((int) 3); + assertThat(result).containsExactly(1, 2, 3); } @Test void convertStringArrayToIntArray() { int[] result = conversionService.convert(new String[] {"1", "2", "3"}, int[].class); - assertThat(result[0]).isEqualTo(1); - assertThat(result[1]).isEqualTo(2); - assertThat(result[2]).isEqualTo(3); + assertThat(result).containsExactly(1, 2, 3); } @Test void convertIntegerArrayToIntegerArray() { Integer[] result = conversionService.convert(new Integer[] {1, 2, 3}, Integer[].class); - assertThat((int) result[0]).isEqualTo((int) 1); - assertThat((int) result[1]).isEqualTo((int) 2); - assertThat((int) result[2]).isEqualTo((int) 3); + assertThat(result).containsExactly(1, 2, 3); } @Test void convertIntegerArrayToIntArray() { int[] result = conversionService.convert(new Integer[] {1, 2, 3}, int[].class); - assertThat(result[0]).isEqualTo(1); - assertThat(result[1]).isEqualTo(2); - assertThat(result[2]).isEqualTo(3); + assertThat(result).containsExactly(1, 2, 3); } @Test void convertObjectArrayToIntegerArray() { Integer[] result = conversionService.convert(new Object[] {1, 2, 3}, Integer[].class); - assertThat((int) result[0]).isEqualTo((int) 1); - assertThat((int) result[1]).isEqualTo((int) 2); - assertThat((int) result[2]).isEqualTo((int) 3); + assertThat(result).containsExactly(1, 2, 3); } @Test void convertObjectArrayToIntArray() { int[] result = conversionService.convert(new Object[] {1, 2, 3}, int[].class); - assertThat(result[0]).isEqualTo(1); - assertThat(result[1]).isEqualTo(2); - assertThat(result[2]).isEqualTo(3); + assertThat(result).containsExactly(1, 2, 3); } @Test @@ -651,28 +602,26 @@ class DefaultConversionServiceTests { @Test void convertArrayToArrayAssignable() { int[] result = conversionService.convert(new int[] {1, 2, 3}, int[].class); - assertThat(result[0]).isEqualTo(1); - assertThat(result[1]).isEqualTo(2); - assertThat(result[2]).isEqualTo(3); + assertThat(result).containsExactly(1, 2, 3); } @Test void convertListOfNonStringifiable() { - List list = Arrays.asList(new TestEntity(1L), new TestEntity(2L)); + List list = List.of(new TestEntity(1L), new TestEntity(2L)); assertThat(conversionService.canConvert(list.getClass(), String.class)).isTrue(); try { conversionService.convert(list, String.class); } catch (ConversionFailedException ex) { - assertThat(ex.getMessage().contains(list.getClass().getName())).isTrue(); - assertThat(ex.getCause() instanceof ConverterNotFoundException).isTrue(); - assertThat(ex.getCause().getMessage().contains(TestEntity.class.getName())).isTrue(); + assertThat(ex.getMessage()).contains(list.getClass().getName()); + assertThat(ex.getCause()).isInstanceOf(ConverterNotFoundException.class); + assertThat(ex.getCause().getMessage()).contains(TestEntity.class.getName()); } } @Test void convertListOfStringToString() { - List list = Arrays.asList("Foo", "Bar"); + List list = List.of("Foo", "Bar"); assertThat(conversionService.canConvert(list.getClass(), String.class)).isTrue(); String result = conversionService.convert(list, String.class); assertThat(result).isEqualTo("Foo,Bar"); @@ -680,9 +629,9 @@ class DefaultConversionServiceTests { @Test void convertListOfListToString() { - List list1 = Arrays.asList("Foo", "Bar"); - List list2 = Arrays.asList("Baz", "Boop"); - List> list = Arrays.asList(list1, list2); + List list1 = List.of("Foo", "Bar"); + List list2 = List.of("Baz", "Boop"); + List> list = List.of(list1, list2); assertThat(conversionService.canConvert(list.getClass(), String.class)).isTrue(); String result = conversionService.convert(list, String.class); assertThat(result).isEqualTo("Foo,Bar,Baz,Boop"); @@ -697,9 +646,7 @@ class DefaultConversionServiceTests { @SuppressWarnings("unchecked") List bar = (List) conversionService.convert(foo, TypeDescriptor.forObject(foo), new TypeDescriptor(getClass().getField("genericList"))); - assertThat((int) bar.get(0)).isEqualTo((int) 1); - assertThat((int) bar.get(1)).isEqualTo((int) 2); - assertThat((int) bar.get(2)).isEqualTo((int) 3); + assertThat(bar).containsExactly(1, 2, 3); } @Test @@ -735,9 +682,9 @@ class DefaultConversionServiceTests { List bar = (List) conversionService.convert(values, TypeDescriptor.forObject(values), new TypeDescriptor(getClass().getField("genericList"))); assertThat(bar.size()).isEqualTo(3); - assertThat((int) bar.get(0)).isEqualTo((int) 1); - assertThat((int) bar.get(1)).isEqualTo((int) 2); - assertThat((int) bar.get(2)).isEqualTo((int) 3); + assertThat(bar.get(0)).isEqualTo(1); + assertThat(bar.get(1)).isEqualTo(2); + assertThat(bar.get(2)).isEqualTo(3); } @Test @@ -748,8 +695,8 @@ class DefaultConversionServiceTests { @SuppressWarnings("unchecked") List integers = (List) conversionService.convert(strings, TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(Integer.class))); - assertThat((int) integers.get(0)).isEqualTo((int) 3); - assertThat((int) integers.get(1)).isEqualTo((int) 9); + assertThat(integers.get(0)).isEqualTo(3); + assertThat(integers.get(1)).isEqualTo(9); } @Test @@ -770,7 +717,7 @@ class DefaultConversionServiceTests { hashMap.put("1", 1); hashMap.put("2", 2); List converted = conversionService.convert(hashMap.values(), List.class); - assertThat(converted).isEqualTo(Arrays.asList(1, 2)); + assertThat(converted).isEqualTo(List.of(1, 2)); } @Test @@ -781,8 +728,8 @@ class DefaultConversionServiceTests { @SuppressWarnings("unchecked") Map integers = (Map) conversionService.convert(strings, TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(Integer.class))); - assertThat((int) integers.get(3)).isEqualTo((int) 9); - assertThat((int) integers.get(6)).isEqualTo((int) 31); + assertThat(integers.get(3)).isEqualTo(9); + assertThat(integers.get(6)).isEqualTo(31); } @Test @@ -947,7 +894,7 @@ class DefaultConversionServiceTests { TypeDescriptor descriptor = new TypeDescriptor(parameter); Object actual = conversionService.convert("1,2,3", TypeDescriptor.valueOf(String.class), descriptor); assertThat(actual.getClass()).isEqualTo(Optional.class); - assertThat(((Optional>) actual).get()).isEqualTo(Arrays.asList(1, 2, 3)); + assertThat(((Optional>) actual).get()).isEqualTo(List.of(1, 2, 3)); } @Test diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java index 6cef077787..7634f58060 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java @@ -24,7 +24,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -104,7 +103,7 @@ class GenericConversionServiceTests { @Test void convert() { conversionService.addConverterFactory(new StringToNumberConverterFactory()); - assertThat(conversionService.convert("3", Integer.class)).isEqualTo((int) 3); + assertThat(conversionService.convert("3", Integer.class)).isEqualTo(3); } @Test @@ -192,7 +191,7 @@ class GenericConversionServiceTests { void convertSuperSourceType() { conversionService.addConverter(CharSequence.class, Integer.class, source -> Integer.valueOf(source.toString())); Integer result = conversionService.convert("3", Integer.class); - assertThat((int) result).isEqualTo((int) 3); + assertThat(result).isEqualTo(3); } // SPR-8718 @@ -221,7 +220,7 @@ class GenericConversionServiceTests { conversionService.addConverterFactory(new StringToNumberConverterFactory()); assertThat(conversionService.canConvert(String.class, int.class)).isTrue(); Integer three = conversionService.convert("3", int.class); - assertThat(three.intValue()).isEqualTo(3); + assertThat(three).isEqualTo(3); } @Test @@ -234,26 +233,21 @@ class GenericConversionServiceTests { @Test void listToIterableConversion() { - List raw = new ArrayList<>(); - raw.add("one"); - raw.add("two"); + List raw = List.of("one", "two"); Object converted = conversionService.convert(raw, Iterable.class); assertThat(converted).isSameAs(raw); } @Test void listToObjectConversion() { - List raw = new ArrayList<>(); - raw.add("one"); - raw.add("two"); + List raw = List.of("one", "two"); Object converted = conversionService.convert(raw, Object.class); assertThat(converted).isSameAs(raw); } @Test void mapToObjectConversion() { - Map raw = new HashMap<>(); - raw.put("key", "value"); + Map raw = Map.of("key", "value"); Object converted = conversionService.convert(raw, Object.class); assertThat(converted).isSameAs(raw); } diff --git a/spring-core/src/test/java/org/springframework/util/CollectionUtilsTests.java b/spring-core/src/test/java/org/springframework/util/CollectionUtilsTests.java index ee353ae3e7..56d520157f 100644 --- a/spring-core/src/test/java/org/springframework/util/CollectionUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/CollectionUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-core/src/test/java/org/springframework/util/NumberUtilsTests.java b/spring-core/src/test/java/org/springframework/util/NumberUtilsTests.java index 14a8d8f3df..8c1bf473d0 100644 --- a/spring-core/src/test/java/org/springframework/util/NumberUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/NumberUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/AbstractExpressionTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/AbstractExpressionTests.java index 0829263fe4..dee0d3259e 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/AbstractExpressionTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/AbstractExpressionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/ast/FormatHelperTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/ast/FormatHelperTests.java index 656f22fbb3..56ababdb63 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/ast/FormatHelperTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/ast/FormatHelperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/ast/OpPlusTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/ast/OpPlusTests.java index 5f1400edfc..15420e0fd4 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/ast/OpPlusTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/ast/OpPlusTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java index a015fee1ff..8f0cf9d8ca 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateQueryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java index c49318eb07..68f6876d62 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java b/spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java index cdc15caa0c..cee7165746 100644 --- a/spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java +++ b/spring-tx/src/test/java/org/springframework/dao/support/DataAccessUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-web/src/test/java/org/springframework/http/converter/ObjectToStringHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/ObjectToStringHttpMessageConverterTests.java index 9d114d3f6a..51ac8b6fcd 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/ObjectToStringHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/ObjectToStringHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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. diff --git a/spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java b/spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java index a2d9eee40b..a8b0a7f16b 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/ServletRequestAttributesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/InputTagTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/InputTagTests.java index 093c0ab504..6a88081f8e 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/InputTagTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/tags/form/InputTagTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 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.