This commit is contained in:
Stéphane Nicoll
2024-01-15 11:17:11 +01:00
parent e1236a8672
commit 0c42965fc3
71 changed files with 543 additions and 828 deletions

View File

@@ -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,8 +41,7 @@ class AnnotationAwareOrderComparatorTests {
list.add(new B());
list.add(new A());
AnnotationAwareOrderComparator.sort(list);
assertThat(list).element(0).isInstanceOf(A.class);
assertThat(list).element(1).isInstanceOf(B.class);
assertThat(list).hasExactlyElementsOfTypes(A.class, B.class);
}
@Test
@@ -51,8 +50,7 @@ class AnnotationAwareOrderComparatorTests {
list.add(new B2());
list.add(new A2());
AnnotationAwareOrderComparator.sort(list);
assertThat(list).element(0).isInstanceOf(A2.class);
assertThat(list).element(1).isInstanceOf(B2.class);
assertThat(list).hasExactlyElementsOfTypes(A2.class, B2.class);
}
@Test
@@ -61,8 +59,7 @@ class AnnotationAwareOrderComparatorTests {
list.add(new B());
list.add(new A2());
AnnotationAwareOrderComparator.sort(list);
assertThat(list).element(0).isInstanceOf(A2.class);
assertThat(list).element(1).isInstanceOf(B.class);
assertThat(list).hasExactlyElementsOfTypes(A2.class, B.class);
}
@Test
@@ -71,8 +68,7 @@ class AnnotationAwareOrderComparatorTests {
list.add(new B());
list.add(new C());
AnnotationAwareOrderComparator.sort(list);
assertThat(list).element(0).isInstanceOf(C.class);
assertThat(list).element(1).isInstanceOf(B.class);
assertThat(list).hasExactlyElementsOfTypes(C.class, B.class);
}
@Test
@@ -81,8 +77,7 @@ class AnnotationAwareOrderComparatorTests {
list.add(B.class);
list.add(A.class);
AnnotationAwareOrderComparator.sort(list);
assertThat(list).element(0).isEqualTo(A.class);
assertThat(list).element(1).isEqualTo(B.class);
assertThat(list).containsExactly(A.class, B.class);
}
@Test
@@ -91,8 +86,7 @@ class AnnotationAwareOrderComparatorTests {
list.add(B.class);
list.add(C.class);
AnnotationAwareOrderComparator.sort(list);
assertThat(list).element(0).isEqualTo(C.class);
assertThat(list).element(1).isEqualTo(B.class);
assertThat(list).containsExactly(C.class, B.class);
}
@Test
@@ -103,13 +97,9 @@ class AnnotationAwareOrderComparatorTests {
list.add(null);
list.add(A.class);
AnnotationAwareOrderComparator.sort(list);
assertThat(list).element(0).isEqualTo(A.class);
assertThat(list).element(1).isEqualTo(B.class);
assertThat(list).element(2).isNull();
assertThat(list).element(3).isNull();
assertThat(list).containsExactly(A.class, B.class, null, null);
}
@Order(1)
private static class A {
}

View File

@@ -133,10 +133,11 @@ class CollectionToCollectionConverterTests {
TypeDescriptor targetType = new TypeDescriptor(getClass().getField("objectToCollection"));
assertThat(conversionService.canConvert(sourceType, targetType)).isTrue();
List<List<List<Integer>>> result = (List<List<List<Integer>>>) conversionService.convert(list, sourceType, targetType);
assertThat(result.get(0).get(0)).element(0).isEqualTo(9);
assertThat(result.get(0).get(1)).element(0).isEqualTo(12);
assertThat(result.get(1).get(0)).element(0).isEqualTo(37);
assertThat(result.get(1).get(1)).element(0).isEqualTo(23);
assertThat(result).hasSize(2);
assertThat(result.get(0).get(0)).singleElement().isEqualTo(9);
assertThat(result.get(0).get(1)).singleElement().isEqualTo(12);
assertThat(result.get(1).get(0)).singleElement().isEqualTo(37);
assertThat(result.get(1).get(1)).singleElement().isEqualTo(23);
}
@Test
@@ -153,10 +154,9 @@ class CollectionToCollectionConverterTests {
TypeDescriptor targetType = new TypeDescriptor(getClass().getField("objectToCollection"));
assertThat(conversionService.canConvert(sourceType, targetType)).isTrue();
List<List<List<Integer>>> result = (List<List<List<Integer>>>) conversionService.convert(list, sourceType, targetType);
assertThat(result.get(0).get(0)).element(0).isEqualTo(9);
assertThat(result.get(0).get(0)).element(1).isEqualTo(12);
assertThat(result.get(1).get(0)).element(0).isEqualTo(37);
assertThat(result.get(1).get(0)).element(1).isEqualTo(23);
assertThat(result).satisfiesExactly(
zero -> assertThat(zero.get(0)).containsExactly(9, 12),
one -> assertThat(one.get(0)).containsExactly(37, 23));
}
@Test

View File

@@ -122,8 +122,7 @@ class SimpleCommandLinePropertySourceTests {
@SuppressWarnings("unchecked")
List<String> nonOptionArgsList = env.getProperty("nonOptionArgs", List.class);
assertThat(nonOptionArgsList).element(0).isEqualTo("noa1");
assertThat(nonOptionArgsList).element(1).isEqualTo("noa2");
assertThat(nonOptionArgsList).containsExactly("noa1", "noa2");
}
}

View File

@@ -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.
@@ -84,9 +84,7 @@ class SpringFactoriesLoaderTests {
@Test
void loadWhenDuplicateRegistrationsPresentReturnsListInCorrectOrder() {
List<DummyFactory> factories = SpringFactoriesLoader.forDefaultResourceLocation().load(DummyFactory.class);
assertThat(factories).hasSize(2);
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
assertThat(factories).element(1).isInstanceOf(MyDummyFactory2.class);
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class, MyDummyFactory2.class);
}
@Test
@@ -118,10 +116,8 @@ class SpringFactoriesLoaderTests {
ArgumentResolver resolver = ArgumentResolver.of(String.class, "injected");
List<DummyFactory> factories = SpringFactoriesLoader.forDefaultResourceLocation(LimitedClassLoader.constructorArgumentFactories)
.load(DummyFactory.class, resolver);
assertThat(factories).hasSize(3);
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
assertThat(factories).element(1).isInstanceOf(MyDummyFactory2.class);
assertThat(factories).element(2).isInstanceOf(ConstructorArgsDummyFactory.class);
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class, MyDummyFactory2.class,
ConstructorArgsDummyFactory.class);
assertThat(factories).extracting(DummyFactory::getString).containsExactly("Foo", "Bar", "injected");
}
@@ -142,18 +138,14 @@ class SpringFactoriesLoaderTests {
FailureHandler failureHandler = FailureHandler.logging(logger);
List<DummyFactory> factories = SpringFactoriesLoader.forDefaultResourceLocation(LimitedClassLoader.multipleArgumentFactories)
.load(DummyFactory.class, failureHandler);
assertThat(factories).hasSize(2);
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
assertThat(factories).element(1).isInstanceOf(MyDummyFactory2.class);
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class, MyDummyFactory2.class);
}
@Test
void loadFactoriesLoadsFromDefaultLocation() {
List<DummyFactory> factories = SpringFactoriesLoader.loadFactories(
DummyFactory.class, null);
assertThat(factories).hasSize(2);
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
assertThat(factories).element(1).isInstanceOf(MyDummyFactory2.class);
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class, MyDummyFactory2.class);
}
@Test
@@ -167,8 +159,7 @@ class SpringFactoriesLoaderTests {
void loadForResourceLocationLoadsFactories() {
List<DummyFactory> factories = SpringFactoriesLoader.forResourceLocation(
"META-INF/custom/custom-spring.factories").load(DummyFactory.class);
assertThat(factories).hasSize(1);
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class);
}
@Test
@@ -220,8 +211,7 @@ class SpringFactoriesLoaderTests {
RuntimeException cause = new RuntimeException();
handler.handleFailure(DummyFactory.class, MyDummyFactory1.class.getName(), cause);
assertThat(failures).containsExactly(cause);
assertThat(messages).hasSize(1);
assertThat(messages).element(0).asString().startsWith("Unable to instantiate factory class");
assertThat(messages).singleElement().asString().startsWith("Unable to instantiate factory class");
}
}

View File

@@ -513,74 +513,63 @@ class AntPathMatcherTests {
paths.add(null);
paths.add("/hotels/new");
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/new");
assertThat(paths).element(1).isNull();
assertThat(paths).containsExactly("/hotels/new", null);
paths.clear();
paths.add("/hotels/new");
paths.add(null);
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/new");
assertThat(paths).element(1).isNull();
assertThat(paths).containsExactly("/hotels/new", null);
paths.clear();
paths.add("/hotels/*");
paths.add("/hotels/new");
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/new");
assertThat(paths).element(1).isEqualTo("/hotels/*");
assertThat(paths).containsExactly("/hotels/new", "/hotels/*");
paths.clear();
paths.add("/hotels/new");
paths.add("/hotels/*");
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/new");
assertThat(paths).element(1).isEqualTo("/hotels/*");
assertThat(paths).containsExactly("/hotels/new", "/hotels/*");
paths.clear();
paths.add("/hotels/**");
paths.add("/hotels/*");
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/*");
assertThat(paths).element(1).isEqualTo("/hotels/**");
assertThat(paths).containsExactly("/hotels/*", "/hotels/**");
paths.clear();
paths.add("/hotels/*");
paths.add("/hotels/**");
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/*");
assertThat(paths).element(1).isEqualTo("/hotels/**");
assertThat(paths).containsExactly("/hotels/*", "/hotels/**");
paths.clear();
paths.add("/hotels/{hotel}");
paths.add("/hotels/new");
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/new");
assertThat(paths).element(1).isEqualTo("/hotels/{hotel}");
assertThat(paths).containsExactly("/hotels/new", "/hotels/{hotel}");
paths.clear();
paths.add("/hotels/new");
paths.add("/hotels/{hotel}");
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/new");
assertThat(paths).element(1).isEqualTo("/hotels/{hotel}");
assertThat(paths).containsExactly("/hotels/new", "/hotels/{hotel}");
paths.clear();
paths.add("/hotels/*");
paths.add("/hotels/{hotel}");
paths.add("/hotels/new");
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/new");
assertThat(paths).element(1).isEqualTo("/hotels/{hotel}");
assertThat(paths).element(2).isEqualTo("/hotels/*");
assertThat(paths).containsExactly("/hotels/new", "/hotels/{hotel}", "/hotels/*");
paths.clear();
paths.add("/hotels/ne*");
paths.add("/hotels/n*");
Collections.shuffle(paths);
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/ne*");
assertThat(paths).element(1).isEqualTo("/hotels/n*");
assertThat(paths).containsExactly("/hotels/ne*", "/hotels/n*");
paths.clear();
comparator = pathMatcher.getPatternComparator("/hotels/new.html");
@@ -588,16 +577,14 @@ class AntPathMatcherTests {
paths.add("/hotels/{hotel}");
Collections.shuffle(paths);
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/hotels/new.*");
assertThat(paths).element(1).isEqualTo("/hotels/{hotel}");
assertThat(paths).containsExactly("/hotels/new.*", "/hotels/{hotel}");
paths.clear();
comparator = pathMatcher.getPatternComparator("/web/endUser/action/login.html");
paths.add("/**/login.*");
paths.add("/**/endUser/action/login.*");
paths.sort(comparator);
assertThat(paths).element(0).isEqualTo("/**/endUser/action/login.*");
assertThat(paths).element(1).isEqualTo("/**/login.*");
assertThat(paths).containsExactly("/**/endUser/action/login.*", "/**/login.*");
paths.clear();
}

View File

@@ -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,6 +18,7 @@ package org.springframework.util;
import java.util.ArrayList;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.springframework.core.testfixture.io.SerializationTestUtils;
@@ -65,7 +66,7 @@ class AutoPopulatingListTests {
String helloWorld = "Hello World!";
list.add(10, null);
list.add(11, helloWorld);
assertThat(list).element(11).isEqualTo(helloWorld);
assertThat(list).element(11, InstanceOfAssertFactories.STRING).isEqualTo(helloWorld);
boolean condition3 = list.get(10) instanceof TestObject;
assertThat(condition3).isTrue();

View File

@@ -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.
@@ -66,9 +66,7 @@ class CollectionUtilsTests {
list.add("value3");
CollectionUtils.mergeArrayIntoCollection(arr, list);
assertThat(list).element(0).isEqualTo("value3");
assertThat(list).element(1).isEqualTo("value1");
assertThat(list).element(2).isEqualTo("value2");
assertThat(list).containsExactly("value3", "value1", "value2");
}
@Test
@@ -78,9 +76,7 @@ class CollectionUtilsTests {
list.add(3);
CollectionUtils.mergeArrayIntoCollection(arr, list);
assertThat(list).element(0).isEqualTo(3);
assertThat(list).element(1).isEqualTo(1);
assertThat(list).element(2).isEqualTo(2);
assertThat(list).containsExactly(3, 1, 2);
}
@Test