Upgrade to AssertJ 3.25.1

Closes gh-38997
This commit is contained in:
Andy Wilkinson 2024-01-04 16:31:37 +00:00
parent c19c18f998
commit a1c7c0bccc
18 changed files with 62 additions and 43 deletions

View File

@ -4,7 +4,7 @@ org.gradle.caching=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
assertjVersion=3.24.2
assertjVersion=3.25.1
commonsCodecVersion=1.16.0
hamcrestVersion=2.2
jacksonVersion=2.15.3

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +29,7 @@ import io.micrometer.core.instrument.binder.mongodb.MongoCommandTagsProvider;
import io.micrometer.core.instrument.binder.mongodb.MongoConnectionPoolTagsProvider;
import io.micrometer.core.instrument.binder.mongodb.MongoMetricsCommandListener;
import io.micrometer.core.instrument.binder.mongodb.MongoMetricsConnectionPoolListener;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
@ -62,7 +63,7 @@ class MongoMetricsAutoConfigurationTests {
assertThat(context).hasSingleBean(MongoMetricsCommandListener.class);
assertThat(getActualMongoClientSettingsUsedToConstructClient(context))
.extracting(MongoClientSettings::getCommandListeners)
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsExactly(context.getBean(MongoMetricsCommandListener.class));
assertThat(getMongoCommandTagsProviderUsedToConstructListener(context))
.isInstanceOf(DefaultMongoCommandTagsProvider.class);
@ -168,7 +169,7 @@ class MongoMetricsAutoConfigurationTests {
assertThat(context).doesNotHaveBean(MongoMetricsCommandListener.class);
assertThat(getActualMongoClientSettingsUsedToConstructClient(context))
.extracting(MongoClientSettings::getCommandListeners)
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.isEmpty();
};
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.
@ -333,13 +333,13 @@ class BraveAutoConfigurationTests {
.getBean(CompositeSpanHandlerComponentsConfiguration.class);
CompositeSpanHandler composite = context.getBean(CompositeSpanHandler.class);
assertThat(composite).extracting("spanFilters")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsExactly(components.filter1, components.filter2);
assertThat(composite).extracting("filters")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsExactly(components.predicate2, components.predicate1);
assertThat(composite).extracting("reporters")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsExactly(components.reporter1, components.reporter3, components.reporter2);
});
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +26,7 @@ import java.util.function.Function;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import reactor.core.publisher.Mono;
@ -143,7 +144,8 @@ class WebMvcEndpointChildContextConfigurationIntegrationTests {
(value) -> assertThat(value).asString().contains("MethodArgumentNotValidException"));
assertThat(body).hasEntrySatisfying("message",
(value) -> assertThat(value).asString().contains("Validation failed"));
assertThat(body).hasEntrySatisfying("errors", (value) -> assertThat(value).asList().isNotEmpty());
assertThat(body).hasEntrySatisfying("errors",
(value) -> assertThat(value).asInstanceOf(InstanceOfAssertFactories.LIST).isNotEmpty());
}));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +26,7 @@ import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.ReflectionException;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@ -165,7 +166,7 @@ class EndpointMBeanTests {
new TestJmxOperation((arguments) -> Flux.just("flux", "result")));
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
Object result = bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE);
assertThat(result).asList().containsExactly("flux", "result");
assertThat(result).asInstanceOf(InstanceOfAssertFactories.LIST).containsExactly("flux", "result");
}
@Test

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.
@ -83,7 +83,7 @@ class CouchbaseAutoConfigurationTests {
.doesNotHaveBean(PropertiesCouchbaseConnectionDetails.class);
Cluster cluster = context.getBean(Cluster.class);
assertThat(cluster.core()).extracting("connectionString.hosts")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.extractingResultOf("host")
.containsExactly("couchbase.example.com");
});
@ -109,7 +109,7 @@ class CouchbaseAutoConfigurationTests {
assertThat(context).hasSingleBean(ClusterEnvironment.class).hasSingleBean(Cluster.class);
Cluster cluster = context.getBean(Cluster.class);
assertThat(cluster.core()).extracting("connectionString.hosts")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.extractingResultOf("host")
.containsExactly("couchbase.example.com");
});

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.
@ -126,7 +126,9 @@ class GraphQlAutoConfigurationTests {
assertThat(graphQL.getQueryStrategy()).extracting("dataFetcherExceptionHandler")
.satisfies((exceptionHandler) -> {
assertThat(exceptionHandler.getClass().getName()).endsWith("ExceptionResolversExceptionHandler");
assertThat(exceptionHandler).extracting("resolvers").asList().hasSize(2);
assertThat(exceptionHandler).extracting("resolvers")
.asInstanceOf(InstanceOfAssertFactories.LIST)
.hasSize(2);
});
});
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +28,7 @@ import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.kstream.KStream;
import org.apache.kafka.streams.kstream.KTable;
import org.apache.kafka.streams.kstream.Materialized;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
@ -115,7 +116,7 @@ class KafkaAutoConfigurationIntegrationTests {
assertThat(listener).extracting(RetryListener::getKey, RetryListener::getReceived)
.containsExactly("foo", "bar");
assertThat(listener).extracting(RetryListener::getTopics)
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.hasSize(5)
.containsSequence("testRetryTopic", "testRetryTopic-retry-0", "testRetryTopic-retry-1",
"testRetryTopic-retry-2");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +27,7 @@ import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.ReaderBuilder;
import org.apache.pulsar.client.api.interceptor.ProducerInterceptor;
import org.apache.pulsar.common.schema.SchemaType;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
@ -287,7 +288,7 @@ class PulsarAutoConfigurationTests {
this.contextRunner.withBean("customProducerInterceptor", ProducerInterceptor.class, () -> interceptor)
.run((context) -> assertThat(context).getBean(PulsarTemplate.class)
.extracting("interceptors")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.contains(interceptor));
}
@ -296,7 +297,7 @@ class PulsarAutoConfigurationTests {
this.contextRunner.withUserConfiguration(InterceptorTestConfiguration.class)
.run((context) -> assertThat(context).getBean(PulsarTemplate.class)
.extracting("interceptors")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.containsExactly(context.getBean("interceptorBar"), context.getBean("interceptorFoo")));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.
@ -424,7 +424,7 @@ class OAuth2ResourceServerAutoConfigurationTests {
assertThat(context).hasSingleBean(OpaqueTokenIntrospector.class);
assertThat(context).hasSingleBean(JwtDecoder.class);
assertThat(getBearerTokenFilter(context)).extracting("authenticationManagerResolver.arg$1.providers")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.hasAtLeastOneElementOfType(JwtAuthenticationProvider.class);
});
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.boot.autoconfigure.transaction;
import java.util.Collections;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
@ -42,7 +43,7 @@ class TransactionManagerCustomizationAutoConfigurationTests {
this.contextRunner.run((context) -> {
TransactionManagerCustomizers customizers = context.getBean(TransactionManagerCustomizers.class);
assertThat(customizers).extracting("customizers")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.hasSize(2)
.hasAtLeastOneElementOfType(TransactionProperties.class)
.hasAtLeastOneElementOfType(ExecutionListenersTransactionManagerCustomizer.class);
@ -54,7 +55,9 @@ class TransactionManagerCustomizationAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CustomTransactionManagerCustomizersConfiguration.class)
.run((context) -> {
TransactionManagerCustomizers customizers = context.getBean(TransactionManagerCustomizers.class);
assertThat(customizers).extracting("customizers").asList().isEmpty();
assertThat(customizers).extracting("customizers")
.asInstanceOf(InstanceOfAssertFactories.LIST)
.isEmpty();
});
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.
@ -198,7 +198,9 @@ class WebFluxAutoConfigurationTests {
SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class);
assertThat(hm.getUrlMap().get("/static/**")).isInstanceOf(ResourceWebHandler.class);
ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/static/**");
assertThat(staticHandler).extracting("locationValues").asList().hasSize(4);
assertThat(staticHandler).extracting("locationValues")
.asInstanceOf(InstanceOfAssertFactories.LIST)
.hasSize(4);
});
}
@ -599,7 +601,7 @@ class WebFluxAutoConfigurationTests {
.withBean(LowPrecedenceConfigurer.class, LowPrecedenceConfigurer::new)
.run((context) -> assertThat(context.getBean(DelegatingWebFluxConfiguration.class))
.extracting("configurers.delegates")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.extracting((configurer) -> (Class) configurer.getClass())
.containsExactly(HighPrecedenceConfigurer.class, WebFluxConfig.class, LowPrecedenceConfigurer.class));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +28,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@ -152,7 +153,7 @@ abstract class AbstractJsonMarshalTesterTests {
void parseListShouldReturnContent() throws Exception {
ResolvableType type = ResolvableTypes.get("listOfExampleObject");
AbstractJsonMarshalTester<Object> tester = createTester(type);
assertThat(tester.parse(ARRAY_JSON)).asList().containsOnly(OBJECT);
assertThat(tester.parse(ARRAY_JSON)).asInstanceOf(InstanceOfAssertFactories.LIST).containsOnly(OBJECT);
}
@Test

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +21,7 @@ import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -61,7 +62,7 @@ class GsonTesterIntegrationTests {
@Test
void typicalListTest() throws Exception {
String example = "[" + JSON + "]";
assertThat(this.listJson.parse(example)).asList().hasSize(1);
assertThat(this.listJson.parse(example)).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(1);
assertThat(this.listJson.parse(example).getObject().get(0).getName()).isEqualTo("Spring");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +25,7 @@ import java.util.Map;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ByteArrayResource;
@ -63,7 +64,7 @@ class JacksonTesterIntegrationTests {
void typicalListTest() throws Exception {
JacksonTester.initFields(this, new ObjectMapper());
String example = "[" + JSON + "]";
assertThat(this.listJson.parse(example)).asList().hasSize(1);
assertThat(this.listJson.parse(example)).asInstanceOf(InstanceOfAssertFactories.LIST).hasSize(1);
assertThat(this.listJson.parse(example).getObject().get(0).getName()).isEqualTo("Spring");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
@ -354,7 +355,7 @@ class ConfigDataEnvironmentTests {
TestConfigDataEnvironment configDataEnvironment = new TestConfigDataEnvironment(this.logFactory,
this.bootstrapContext, this.environment, resourceLoader, this.additionalProfiles, null);
assertThat(configDataEnvironment).extracting("loaders.loaders")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.extracting((item) -> (Class) item.getClass())
.containsOnly(SeparateClassLoaderConfigDataLoader.class);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +23,7 @@ import java.util.List;
import java.util.function.Supplier;
import org.apache.commons.logging.Log;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@ -65,7 +66,7 @@ class ConfigDataLoadersTests {
ConfigDataLoaders loaders = new ConfigDataLoaders(this.logFactory, this.bootstrapContext,
springFactoriesLoader);
assertThat(loaders).extracting("loaders")
.asList()
.asInstanceOf(InstanceOfAssertFactories.LIST)
.satisfies(this::containsValidDeferredLogFactoryConfigDataLoader);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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,6 +21,7 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;
import org.springframework.util.StreamUtils;
@ -105,7 +106,7 @@ abstract class AbstractJsonParserTests {
.parseMap("{\"foo\":[{\"foo\":\"bar\",\"spam\":1},{\"foo\":\"baz\",\"spam\":2}]}");
assertThat(map).hasSize(1);
assertThat(((List<Object>) map.get("foo"))).hasSize(2);
assertThat(map.get("foo")).asList().allMatch(Map.class::isInstance);
assertThat(map.get("foo")).asInstanceOf(InstanceOfAssertFactories.LIST).allMatch(Map.class::isInstance);
}
@SuppressWarnings("unchecked")
@ -115,7 +116,7 @@ abstract class AbstractJsonParserTests {
.parseMap(" {\"foo\": [ { \"foo\" : \"bar\" , \"spam\" : 1 } , { \"foo\" : \"baz\" , \"spam\" : 2 } ] } ");
assertThat(map).hasSize(1);
assertThat(((List<Object>) map.get("foo"))).hasSize(2);
assertThat(map.get("foo")).asList().allMatch(Map.class::isInstance);
assertThat(map.get("foo")).asInstanceOf(InstanceOfAssertFactories.LIST).allMatch(Map.class::isInstance);
}
@Test