Use modern language features in tests

This commit is contained in:
Sam Brannen
2022-02-03 14:50:10 +01:00
parent 82a2544918
commit f8a5a8d7be
91 changed files with 577 additions and 1059 deletions

View File

@@ -1700,7 +1700,7 @@ class MergedAnnotationsTests {
assertThat(componentScan).isNotNull();
assertThat(componentScan.value().pattern()).isEqualTo("*Foo");
Map<String, Object> map = MergedAnnotation.from(componentScan).asMap(
annotation -> new LinkedHashMap<String, Object>(),
annotation -> new LinkedHashMap<>(),
Adapt.ANNOTATION_TO_MAP);
Map<String, Object> filterMap = (Map<String, Object>) map.get("value");
assertThat(filterMap.get("pattern")).isEqualTo("*Foo");
@@ -1720,7 +1720,7 @@ class MergedAnnotationsTests {
ComponentScan.class);
assertThat(componentScan).isNotNull();
Map<String, Object> map = MergedAnnotation.from(componentScan).asMap(
annotation -> new LinkedHashMap<String, Object>(),
annotation -> new LinkedHashMap<>(),
Adapt.ANNOTATION_TO_MAP);
Map<String, Object>[] filters = (Map[]) map.get("excludeFilters");
List<String> patterns = Arrays.stream(filters).map(

View File

@@ -140,7 +140,7 @@ class ConvertingComparatorTests {
assertThat(o2).isInstanceOf(Integer.class);
this.called = true;
return super.compare(o1, o2);
};
}
public void assertCalled() {
assertThat(this.called).isTrue();

View File

@@ -48,7 +48,7 @@ class AutoPopulatingListTests {
@Test
void withElementFactoryAndUserSuppliedBackingList() throws Exception {
doTestWithElementFactory(new AutoPopulatingList<Object>(new ArrayList<>(), new MockElementFactory()));
doTestWithElementFactory(new AutoPopulatingList<>(new ArrayList<>(), new MockElementFactory()));
}
private void doTestWithClass(AutoPopulatingList<Object> list) {

View File

@@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
*/
class ConcurrentReferenceHashMapTests {
private static final Comparator<? super String> NULL_SAFE_STRING_SORT = new NullSafeComparator<String>(
private static final Comparator<? super String> NULL_SAFE_STRING_SORT = new NullSafeComparator<>(
new ComparableComparator<String>(), true);
private TestWeakConcurrentCache<Integer, String> map = new TestWeakConcurrentCache<>();

View File

@@ -391,8 +391,8 @@ class ReflectionUtilsTests {
int add(int... args) {
int sum = 0;
for (int i = 0; i < args.length; i++) {
sum += args[i];
for (int arg : args) {
sum += arg;
}
return sum;
}

View File

@@ -620,14 +620,8 @@ class StringUtilsTests {
}
private void doTestCommaDelimitedListToStringArrayLegalMatch(String[] components) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < components.length; i++) {
if (i != 0) {
sb.append(',');
}
sb.append(components[i]);
}
String[] sa = StringUtils.commaDelimitedListToStringArray(sb.toString());
String sb = String.join(String.valueOf(','), components);
String[] sa = StringUtils.commaDelimitedListToStringArray(sb);
assertThat(sa != null).as("String array isn't null with legal match").isTrue();
assertThat(sa.length).as("String array length is correct with legal match").isEqualTo(components.length);
assertThat(Arrays.equals(sa, components)).as("Output equals input").isTrue();