Skip to content

Commit f136e27

Browse files
committed
Merge branch '6.2.x'
2 parents 99bcd3a + f802c0c commit f136e27

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

spring-core/src/test/java/org/springframework/util/PropertyPlaceholderHelperTests.java

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,11 +17,13 @@
1717
package org.springframework.util;
1818

1919
import java.util.Properties;
20+
import java.util.stream.Stream;
2021

2122
import org.junit.jupiter.api.Nested;
2223
import org.junit.jupiter.api.Test;
2324
import org.junit.jupiter.params.ParameterizedTest;
24-
import org.junit.jupiter.params.provider.CsvSource;
25+
import org.junit.jupiter.params.provider.Arguments;
26+
import org.junit.jupiter.params.provider.MethodSource;
2527

2628
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
2729

@@ -125,14 +127,7 @@ class DefaultValueTests {
125127
private final PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}", ":", null, true);
126128

127129
@ParameterizedTest(name = "{0} -> {1}")
128-
@CsvSource(delimiterString = "->", textBlock = """
129-
${invalid:test} -> test
130-
${invalid:${one}} -> 1
131-
${invalid:${one}${two}} -> 12
132-
${invalid:${one}:${two}} -> 1:2
133-
${invalid:${also_invalid:test}} -> test
134-
${invalid:${also_invalid:${one}}} -> 1
135-
""")
130+
@MethodSource("defaultValues")
136131
void defaultValueIsApplied(String text, String value) {
137132
Properties properties = new Properties();
138133
properties.setProperty("one", "1");
@@ -148,18 +143,33 @@ void defaultValueIsNotEvaluatedEarly() {
148143
verify(resolver, never()).resolvePlaceholder("two");
149144
}
150145

146+
static Stream<Arguments> defaultValues() {
147+
return Stream.of(
148+
Arguments.of("${invalid:test}", "test"),
149+
Arguments.of("${invalid:${one}}", "1"),
150+
Arguments.of("${invalid:${one}${two}}", "12"),
151+
Arguments.of("${invalid:${one}:${two}}", "1:2"),
152+
Arguments.of("${invalid:${also_invalid:test}}", "test"),
153+
Arguments.of("${invalid:${also_invalid:${one}}}", "1")
154+
);
155+
}
156+
151157
@ParameterizedTest(name = "{0} -> {1}")
152-
@CsvSource(delimiterString = "->", textBlock = """
153-
${prefix://my-service} -> example-service
154-
${p1} -> example-service
155-
""")
158+
@MethodSource("exactMatchPlaceholders")
156159
void placeholdersWithExactMatchAreConsidered(String text, String expected) {
157160
Properties properties = new Properties();
158161
properties.setProperty("prefix://my-service", "example-service");
159162
properties.setProperty("px", "prefix");
160163
properties.setProperty("p1", "${prefix://my-service}");
161164
assertThat(this.helper.replacePlaceholders(text, properties)).isEqualTo(expected);
162165
}
166+
167+
static Stream<Arguments> exactMatchPlaceholders() {
168+
return Stream.of(
169+
Arguments.of("${prefix://my-service}", "example-service"),
170+
Arguments.of("${p1}", "example-service")
171+
);
172+
}
163173
}
164174

165175

0 commit comments

Comments
 (0)