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

View File

@ -52,7 +52,7 @@ import static org.hamcrest.Matchers.allOf;
* @since 2.2.0 * @since 2.2.0
* @deprecated since 4.0.0 in favor of JUnit 5 and {@link OutputCaptureExtension} * @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 { public class OutputCaptureRule implements TestRule, CapturedOutput {
private final OutputCapture delegate = new OutputCapture(); private final OutputCapture delegate = new OutputCapture();

View File

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

View File

@ -176,10 +176,10 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
LoggerContext loggerContext = getLoggerContext(); LoggerContext loggerContext = getLoggerContext();
String contextName = loggerContext.getName(); String contextName = loggerContext.getName();
List<String> extensions = getStandardConfigExtensions(); List<String> extensions = getStandardConfigExtensions();
extensions.forEach((e) -> locations.add("log4j2-test" + contextName + e)); addLocation(locations, "log4j2-test" + contextName, extensions);
extensions.forEach((e) -> locations.add("log4j2-test" + e)); addLocation(locations, "log4j2-test", extensions);
extensions.forEach((e) -> locations.add("log4j2" + contextName + e)); addLocation(locations, "log4j2" + contextName, extensions);
extensions.forEach((e) -> locations.add("log4j2" + e)); addLocation(locations, "log4j2", extensions);
} }
private List<String> getStandardConfigExtensions() { private List<String> getStandardConfigExtensions() {
@ -188,22 +188,26 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
ClassLoader classLoader = LoggerContext.class.getClassLoader(); ClassLoader classLoader = LoggerContext.class.getClassLoader();
// The order of the extensions corresponds to the order in which Log4j Core 2 and // 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. // 3 will try to load them, in decreasing value of @Order.
if (isClassAvailable(classLoader, PROPS_CONFIGURATION_FACTORY_V2) if (isPresent(classLoader, PROPS_CONFIGURATION_FACTORY_V2)
|| isClassAvailable(classLoader, PROPS_CONFIGURATION_FACTORY_V3)) { || isPresent(classLoader, PROPS_CONFIGURATION_FACTORY_V3)) {
extensions.add(".properties"); extensions.add(".properties");
} }
if (areAllClassesAvailable(classLoader, YAML_CONFIGURATION_FACTORY_V2, YAML_TREE_PARSER_V2) if (isPresent(classLoader, YAML_CONFIGURATION_FACTORY_V2, YAML_TREE_PARSER_V2)
|| isClassAvailable(classLoader, YAML_CONFIGURATION_FACTORY_V3)) { || isPresent(classLoader, YAML_CONFIGURATION_FACTORY_V3)) {
Collections.addAll(extensions, ".yaml", ".yml"); 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"); Collections.addAll(extensions, ".json", ".jsn");
} }
extensions.add(".xml"); extensions.add(".xml");
return extensions; 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) { for (String className : classNames) {
if (!isClassAvailable(classLoader, className)) { if (!isClassAvailable(classLoader, className)) {
return false; return false;
@ -212,15 +216,15 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem {
return true; return true;
} }
protected boolean isClassAvailable(ClassLoader classLoader, String className) {
return ClassUtils.isPresent(className, classLoader);
}
@Deprecated(since = "4.0.0", forRemoval = true) @Deprecated(since = "4.0.0", forRemoval = true)
protected boolean isClassAvailable(String className) { protected boolean isClassAvailable(String className) {
return ClassUtils.isPresent(className, getClassLoader()); return ClassUtils.isPresent(className, getClassLoader());
} }
protected boolean isClassAvailable(ClassLoader classLoader, String className) {
return ClassUtils.isPresent(className, classLoader);
}
@Override @Override
public void beforeInitialize() { public void beforeInitialize() {
LoggerContext loggerContext = getLoggerContext(); 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.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoConverter; import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions; 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.convert.NoOpDbRefResolver;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext; import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
@ -77,12 +77,11 @@ class MongoDataConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
MongoCustomConversions mongoCustomConversions() { MongoCustomConversions mongoCustomConversions() {
return MongoCustomConversions.create((configurer) -> { return MongoCustomConversions.create(this::configureConversions);
BigDecimalRepresentation bigDecimaRepresentation = this.properties.getRepresentation().getBigDecimal(); }
if (bigDecimaRepresentation != null) {
configurer.bigDecimal(bigDecimaRepresentation); private void configureConversions(MongoConverterConfigurationAdapter configurer) {
} PropertyMapper.get().from(this.properties.getRepresentation()::getBigDecimal).to(configurer::bigDecimal);
});
} }
@Bean @Bean

View File

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