This commit is contained in:
Phillip Webb 2025-09-18 13:29:47 -07:00
parent 4cb2c62230
commit 2cf854c5b6
6 changed files with 36 additions and 41 deletions

View File

@ -42,6 +42,7 @@ import org.skyscreamer.jsonassert.comparator.JSONComparator;
import org.springframework.core.io.Resource;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.function.ThrowingFunction;
/**
* AssertJ {@link Assert} for {@link JsonContent}.
@ -997,24 +998,17 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
}
private JSONCompareResult compare(@Nullable CharSequence expectedJson, JSONCompareMode compareMode) {
if (this.actual == null) {
return compareForNull(expectedJson);
}
if (expectedJson == null) {
return fail("Expected JSON but got null");
}
try {
return JSONCompare.compareJSON(expectedJson.toString(), this.actual.toString(), compareMode);
}
catch (Exception ex) {
if (ex instanceof RuntimeException runtimeException) {
throw runtimeException;
}
throw new IllegalStateException(ex);
}
return compare(expectedJson,
(expected) -> JSONCompare.compareJSON(expected, this.actual.toString(), compareMode));
}
private JSONCompareResult compare(@Nullable CharSequence expectedJson, JSONComparator comparator) {
return compare(expectedJson,
(expected) -> JSONCompare.compareJSON(expected, this.actual.toString(), comparator));
}
private JSONCompareResult compare(@Nullable CharSequence expectedJson,
ThrowingFunction<String, JSONCompareResult> compareAction) {
if (this.actual == null) {
return compareForNull(expectedJson);
}
@ -1022,7 +1016,7 @@ public class JsonContentAssert extends AbstractAssert<JsonContentAssert, CharSeq
return fail("Expected JSON but got null");
}
try {
return JSONCompare.compareJSON(expectedJson.toString(), this.actual.toString(), comparator);
return compareAction.applyWithException(expectedJson.toString());
}
catch (Exception ex) {
if (ex instanceof RuntimeException runtimeException) {

View File

@ -52,7 +52,7 @@ import static org.hamcrest.Matchers.allOf;
* @since 2.2.0
* @deprecated since 4.0.0 in favor of JUnit 5 and {@link OutputCaptureExtension}
*/
@Deprecated(since = "4.0.0")
@Deprecated(since = "4.0.0", forRemoval = true)
public class OutputCaptureRule implements TestRule, CapturedOutput {
private final OutputCapture delegate = new OutputCapture();

View File

@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Roland Weisleder
*/
@SuppressWarnings("deprecation")
@SuppressWarnings("removal")
public class OutputCaptureRuleTests {
@Rule

View File

@ -176,10 +176,10 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
LoggerContext loggerContext = getLoggerContext();
String contextName = loggerContext.getName();
List<String> extensions = getStandardConfigExtensions();
extensions.forEach((e) -> locations.add("log4j2-test" + contextName + e));
extensions.forEach((e) -> locations.add("log4j2-test" + e));
extensions.forEach((e) -> locations.add("log4j2" + contextName + e));
extensions.forEach((e) -> locations.add("log4j2" + e));
addLocation(locations, "log4j2-test" + contextName, extensions);
addLocation(locations, "log4j2-test", extensions);
addLocation(locations, "log4j2" + contextName, extensions);
addLocation(locations, "log4j2", extensions);
}
private List<String> getStandardConfigExtensions() {
@ -188,22 +188,26 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
ClassLoader classLoader = LoggerContext.class.getClassLoader();
// The order of the extensions corresponds to the order in which Log4j Core 2 and
// 3 will try to load them, in decreasing value of @Order.
if (isClassAvailable(classLoader, PROPS_CONFIGURATION_FACTORY_V2)
|| isClassAvailable(classLoader, PROPS_CONFIGURATION_FACTORY_V3)) {
if (isPresent(classLoader, PROPS_CONFIGURATION_FACTORY_V2)
|| isPresent(classLoader, PROPS_CONFIGURATION_FACTORY_V3)) {
extensions.add(".properties");
}
if (areAllClassesAvailable(classLoader, YAML_CONFIGURATION_FACTORY_V2, YAML_TREE_PARSER_V2)
|| isClassAvailable(classLoader, YAML_CONFIGURATION_FACTORY_V3)) {
if (isPresent(classLoader, YAML_CONFIGURATION_FACTORY_V2, YAML_TREE_PARSER_V2)
|| isPresent(classLoader, YAML_CONFIGURATION_FACTORY_V3)) {
Collections.addAll(extensions, ".yaml", ".yml");
}
if (isClassAvailable(classLoader, JSON_TREE_PARSER_V2) || isClassAvailable(classLoader, JSON_TREE_PARSER_V3)) {
if (isPresent(classLoader, JSON_TREE_PARSER_V2) || isPresent(classLoader, JSON_TREE_PARSER_V3)) {
Collections.addAll(extensions, ".json", ".jsn");
}
extensions.add(".xml");
return extensions;
}
private boolean areAllClassesAvailable(ClassLoader classLoader, String... classNames) {
private void addLocation(List<String> locations, String location, List<String> extensions) {
extensions.forEach((extension) -> locations.add(location + extension));
}
private boolean isPresent(ClassLoader classLoader, String... classNames) {
for (String className : classNames) {
if (!isClassAvailable(classLoader, className)) {
return false;
@ -212,15 +216,15 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
return true;
}
protected boolean isClassAvailable(ClassLoader classLoader, String className) {
return ClassUtils.isPresent(className, classLoader);
}
@Deprecated(since = "4.0.0", forRemoval = true)
protected boolean isClassAvailable(String className) {
return ClassUtils.isPresent(className, getClassLoader());
}
protected boolean isClassAvailable(ClassLoader classLoader, String className) {
return ClassUtils.isPresent(className, classLoader);
}
@Override
public void beforeInitialize() {
LoggerContext loggerContext = getLoggerContext();

View File

@ -32,7 +32,7 @@ import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions.BigDecimalRepresentation;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions.MongoConverterConfigurationAdapter;
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
@ -77,12 +77,11 @@ class MongoDataConfiguration {
@Bean
@ConditionalOnMissingBean
MongoCustomConversions mongoCustomConversions() {
return MongoCustomConversions.create((configurer) -> {
BigDecimalRepresentation bigDecimaRepresentation = this.properties.getRepresentation().getBigDecimal();
if (bigDecimaRepresentation != null) {
configurer.bigDecimal(bigDecimaRepresentation);
}
});
return MongoCustomConversions.create(this::configureConversions);
}
private void configureConversions(MongoConverterConfigurationAdapter configurer) {
PropertyMapper.get().from(this.properties.getRepresentation()::getBigDecimal).to(configurer::bigDecimal);
}
@Bean

View File

@ -324,9 +324,7 @@ class HttpMessageConvertersAutoConfigurationTests {
private void assertConvertersBeanRegisteredWithHttpMessageConverters(AssertableApplicationContext context,
List<Class<? extends HttpMessageConverter<?>>> types) {
List<? extends HttpMessageConverter<?>> converterInstances = types.stream().map(context::getBean).toList();
HttpMessageConverters converters = context.getBean(HttpMessageConverters.class);
assertThat(converters.getConverters()).containsSubsequence(converterInstances);
}