Browse Source

Polish

pull/47286/head
Phillip Webb 3 months ago
parent
commit
2cf854c5b6
  1. 26
      core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java
  2. 2
      core/spring-boot-test/src/main/java/org/springframework/boot/test/system/OutputCaptureRule.java
  3. 2
      core/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java
  4. 32
      core/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java
  5. 13
      module/spring-boot-data-mongodb/src/main/java/org/springframework/boot/data/mongodb/autoconfigure/MongoDataConfiguration.java
  6. 2
      module/spring-boot-http-converter/src/test/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersAutoConfigurationTests.java

26
core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java

@ -42,6 +42,7 @@ import org.skyscreamer.jsonassert.comparator.JSONComparator; @@ -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 @@ -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 @@ -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) {

2
core/spring-boot-test/src/main/java/org/springframework/boot/test/system/OutputCaptureRule.java

@ -52,7 +52,7 @@ import static org.hamcrest.Matchers.allOf; @@ -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();

2
core/spring-boot-test/src/test/java/org/springframework/boot/test/system/OutputCaptureRuleTests.java

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

32
core/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.java

@ -176,10 +176,10 @@ public class Log4J2LoggingSystem extends AbstractLoggingSystem { @@ -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 { @@ -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 { @@ -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();

13
module/spring-boot-data-mongodb/src/main/java/org/springframework/boot/data/mongodb/autoconfigure/MongoDataConfiguration.java

@ -32,7 +32,7 @@ import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver; @@ -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 { @@ -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

2
module/spring-boot-http-converter/src/test/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersAutoConfigurationTests.java

@ -324,9 +324,7 @@ class HttpMessageConvertersAutoConfigurationTests { @@ -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);
}

Loading…
Cancel
Save