Skip to content

Commit 2cf854c

Browse files
committed
Polish
1 parent 4cb2c62 commit 2cf854c

File tree

6 files changed

+36
-41
lines changed

6 files changed

+36
-41
lines changed

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.core.io.Resource;
4343
import org.springframework.util.ObjectUtils;
4444
import org.springframework.util.StringUtils;
45+
import org.springframework.util.function.ThrowingFunction;
4546

4647
/**
4748
* AssertJ {@link Assert} for {@link JsonContent}.
@@ -997,32 +998,25 @@ public <K, V> MapAssert<K, V> extractingJsonPathMapValue(CharSequence expression
997998
}
998999

9991000
private JSONCompareResult compare(@Nullable CharSequence expectedJson, JSONCompareMode compareMode) {
1000-
if (this.actual == null) {
1001-
return compareForNull(expectedJson);
1002-
}
1003-
if (expectedJson == null) {
1004-
return fail("Expected JSON but got null");
1005-
}
1006-
try {
1007-
return JSONCompare.compareJSON(expectedJson.toString(), this.actual.toString(), compareMode);
1008-
}
1009-
catch (Exception ex) {
1010-
if (ex instanceof RuntimeException runtimeException) {
1011-
throw runtimeException;
1012-
}
1013-
throw new IllegalStateException(ex);
1014-
}
1001+
return compare(expectedJson,
1002+
(expected) -> JSONCompare.compareJSON(expected, this.actual.toString(), compareMode));
10151003
}
10161004

10171005
private JSONCompareResult compare(@Nullable CharSequence expectedJson, JSONComparator comparator) {
1006+
return compare(expectedJson,
1007+
(expected) -> JSONCompare.compareJSON(expected, this.actual.toString(), comparator));
1008+
}
1009+
1010+
private JSONCompareResult compare(@Nullable CharSequence expectedJson,
1011+
ThrowingFunction<String, JSONCompareResult> compareAction) {
10181012
if (this.actual == null) {
10191013
return compareForNull(expectedJson);
10201014
}
10211015
if (expectedJson == null) {
10221016
return fail("Expected JSON but got null");
10231017
}
10241018
try {
1025-
return JSONCompare.compareJSON(expectedJson.toString(), this.actual.toString(), comparator);
1019+
return compareAction.applyWithException(expectedJson.toString());
10261020
}
10271021
catch (Exception ex) {
10281022
if (ex instanceof RuntimeException runtimeException) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* @since 2.2.0
5353
* @deprecated since 4.0.0 in favor of JUnit 5 and {@link OutputCaptureExtension}
5454
*/
55-
@Deprecated(since = "4.0.0")
55+
@Deprecated(since = "4.0.0", forRemoval = true)
5656
public class OutputCaptureRule implements TestRule, CapturedOutput {
5757

5858
private final OutputCapture delegate = new OutputCapture();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* @author Roland Weisleder
2828
*/
29-
@SuppressWarnings("deprecation")
29+
@SuppressWarnings("removal")
3030
public class OutputCaptureRuleTests {
3131

3232
@Rule

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ private void addStandardLocations(List<String> locations) {
176176
LoggerContext loggerContext = getLoggerContext();
177177
String contextName = loggerContext.getName();
178178
List<String> extensions = getStandardConfigExtensions();
179-
extensions.forEach((e) -> locations.add("log4j2-test" + contextName + e));
180-
extensions.forEach((e) -> locations.add("log4j2-test" + e));
181-
extensions.forEach((e) -> locations.add("log4j2" + contextName + e));
182-
extensions.forEach((e) -> locations.add("log4j2" + e));
179+
addLocation(locations, "log4j2-test" + contextName, extensions);
180+
addLocation(locations, "log4j2-test", extensions);
181+
addLocation(locations, "log4j2" + contextName, extensions);
182+
addLocation(locations, "log4j2", extensions);
183183
}
184184

185185
private List<String> getStandardConfigExtensions() {
@@ -188,22 +188,26 @@ private List<String> getStandardConfigExtensions() {
188188
ClassLoader classLoader = LoggerContext.class.getClassLoader();
189189
// The order of the extensions corresponds to the order in which Log4j Core 2 and
190190
// 3 will try to load them, in decreasing value of @Order.
191-
if (isClassAvailable(classLoader, PROPS_CONFIGURATION_FACTORY_V2)
192-
|| isClassAvailable(classLoader, PROPS_CONFIGURATION_FACTORY_V3)) {
191+
if (isPresent(classLoader, PROPS_CONFIGURATION_FACTORY_V2)
192+
|| isPresent(classLoader, PROPS_CONFIGURATION_FACTORY_V3)) {
193193
extensions.add(".properties");
194194
}
195-
if (areAllClassesAvailable(classLoader, YAML_CONFIGURATION_FACTORY_V2, YAML_TREE_PARSER_V2)
196-
|| isClassAvailable(classLoader, YAML_CONFIGURATION_FACTORY_V3)) {
195+
if (isPresent(classLoader, YAML_CONFIGURATION_FACTORY_V2, YAML_TREE_PARSER_V2)
196+
|| isPresent(classLoader, YAML_CONFIGURATION_FACTORY_V3)) {
197197
Collections.addAll(extensions, ".yaml", ".yml");
198198
}
199-
if (isClassAvailable(classLoader, JSON_TREE_PARSER_V2) || isClassAvailable(classLoader, JSON_TREE_PARSER_V3)) {
199+
if (isPresent(classLoader, JSON_TREE_PARSER_V2) || isPresent(classLoader, JSON_TREE_PARSER_V3)) {
200200
Collections.addAll(extensions, ".json", ".jsn");
201201
}
202202
extensions.add(".xml");
203203
return extensions;
204204
}
205205

206-
private boolean areAllClassesAvailable(ClassLoader classLoader, String... classNames) {
206+
private void addLocation(List<String> locations, String location, List<String> extensions) {
207+
extensions.forEach((extension) -> locations.add(location + extension));
208+
}
209+
210+
private boolean isPresent(ClassLoader classLoader, String... classNames) {
207211
for (String className : classNames) {
208212
if (!isClassAvailable(classLoader, className)) {
209213
return false;
@@ -212,15 +216,15 @@ private boolean areAllClassesAvailable(ClassLoader classLoader, String... classN
212216
return true;
213217
}
214218

219+
protected boolean isClassAvailable(ClassLoader classLoader, String className) {
220+
return ClassUtils.isPresent(className, classLoader);
221+
}
222+
215223
@Deprecated(since = "4.0.0", forRemoval = true)
216224
protected boolean isClassAvailable(String className) {
217225
return ClassUtils.isPresent(className, getClassLoader());
218226
}
219227

220-
protected boolean isClassAvailable(ClassLoader classLoader, String className) {
221-
return ClassUtils.isPresent(className, classLoader);
222-
}
223-
224228
@Override
225229
public void beforeInitialize() {
226230
LoggerContext loggerContext = getLoggerContext();

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
3333
import org.springframework.data.mongodb.core.convert.MongoConverter;
3434
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
35-
import org.springframework.data.mongodb.core.convert.MongoCustomConversions.BigDecimalRepresentation;
35+
import org.springframework.data.mongodb.core.convert.MongoCustomConversions.MongoConverterConfigurationAdapter;
3636
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver;
3737
import org.springframework.data.mongodb.core.mapping.Document;
3838
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
@@ -77,12 +77,11 @@ MongoMappingContext mongoMappingContext(MongoCustomConversions conversions, Mong
7777
@Bean
7878
@ConditionalOnMissingBean
7979
MongoCustomConversions mongoCustomConversions() {
80-
return MongoCustomConversions.create((configurer) -> {
81-
BigDecimalRepresentation bigDecimaRepresentation = this.properties.getRepresentation().getBigDecimal();
82-
if (bigDecimaRepresentation != null) {
83-
configurer.bigDecimal(bigDecimaRepresentation);
84-
}
85-
});
80+
return MongoCustomConversions.create(this::configureConversions);
81+
}
82+
83+
private void configureConversions(MongoConverterConfigurationAdapter configurer) {
84+
PropertyMapper.get().from(this.properties.getRepresentation()::getBigDecimal).to(configurer::bigDecimal);
8685
}
8786

8887
@Bean

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,7 @@ private void assertConverterBeanRegisteredWithHttpMessageConverters(AssertableAp
324324

325325
private void assertConvertersBeanRegisteredWithHttpMessageConverters(AssertableApplicationContext context,
326326
List<Class<? extends HttpMessageConverter<?>>> types) {
327-
328327
List<? extends HttpMessageConverter<?>> converterInstances = types.stream().map(context::getBean).toList();
329-
330328
HttpMessageConverters converters = context.getBean(HttpMessageConverters.class);
331329
assertThat(converters.getConverters()).containsSubsequence(converterInstances);
332330
}

0 commit comments

Comments
 (0)