Fix broken tests, update copyright dates, and polish
See gh-29414
This commit is contained in:
parent
b2c8546013
commit
f26a7dee97
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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<Integer> result = (List<Integer>) 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<Integer> result = (Stream<Integer>) 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<Color> colors = (List<Color>) 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<String> list = new ArrayList<>();
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
List<String> 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<String> list = new ArrayList<>();
|
||||
list.add("1");
|
||||
list.add("2");
|
||||
list.add("3");
|
||||
List<String> 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<String> list = Arrays.asList("foo", "bar");
|
||||
List<String> list = List.of("foo", "bar");
|
||||
String result = conversionService.convert(list, String.class);
|
||||
assertThat(result).isEqualTo("foo,bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void convertCollectionToStringWithElementConversion() throws Exception {
|
||||
List<Integer> list = Arrays.asList(3, 5);
|
||||
List<Integer> 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<Long> 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<String> 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<Integer> result = (List<Integer>) 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<Object> list = Arrays.asList(new TestEntity(1L), new TestEntity(2L));
|
||||
List<Object> 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<String> list = Arrays.asList("Foo", "Bar");
|
||||
List<String> 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<String> list1 = Arrays.asList("Foo", "Bar");
|
||||
List<String> list2 = Arrays.asList("Baz", "Boop");
|
||||
List<List<String>> list = Arrays.asList(list1, list2);
|
||||
List<String> list1 = List.of("Foo", "Bar");
|
||||
List<String> list2 = List.of("Baz", "Boop");
|
||||
List<List<String>> 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<Integer> bar = (List<Integer>) 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<Integer> bar = (List<Integer>) 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<Integer> integers = (List<Integer>) 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<Integer, Integer> integers = (Map<Integer, Integer>) 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<List<Integer>>) actual).get()).isEqualTo(Arrays.asList(1, 2, 3));
|
||||
assertThat(((Optional<List<Integer>>) actual).get()).isEqualTo(List.of(1, 2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -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<Object> raw = new ArrayList<>();
|
||||
raw.add("one");
|
||||
raw.add("two");
|
||||
List<Object> raw = List.of("one", "two");
|
||||
Object converted = conversionService.convert(raw, Iterable.class);
|
||||
assertThat(converted).isSameAs(raw);
|
||||
}
|
||||
|
||||
@Test
|
||||
void listToObjectConversion() {
|
||||
List<Object> raw = new ArrayList<>();
|
||||
raw.add("one");
|
||||
raw.add("two");
|
||||
List<Object> raw = List.of("one", "two");
|
||||
Object converted = conversionService.convert(raw, Object.class);
|
||||
assertThat(converted).isSameAs(raw);
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapToObjectConversion() {
|
||||
Map<Object, Object> raw = new HashMap<>();
|
||||
raw.put("key", "value");
|
||||
Map<Object, Object> raw = Map.of("key", "value");
|
||||
Object converted = conversionService.convert(raw, Object.class);
|
||||
assertThat(converted).isSameAs(raw);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue