Skip to content

Commit 149fcae

Browse files
committed
Check warning messages in tests
1 parent 3c3e29b commit 149fcae

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

log4j-api-test/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
import java.util.Map;
3939
import java.util.Properties;
4040
import java.util.stream.Stream;
41+
import org.apache.logging.log4j.Level;
42+
import org.apache.logging.log4j.test.ListStatusListener;
43+
import org.apache.logging.log4j.test.junit.UsingStatusListener;
4144
import org.junit.jupiter.api.BeforeEach;
4245
import org.junit.jupiter.api.Test;
4346
import org.junit.jupiter.api.parallel.ResourceAccessMode;
@@ -193,16 +196,21 @@ void testPublish() {
193196
@Test
194197
@ResourceLock(value = Resources.SYSTEM_PROPERTIES, mode = ResourceAccessMode.READ)
195198
@Issue("https://github.com/spring-projects/spring-boot/issues/33450")
196-
void testErrorPropertySource() {
199+
@UsingStatusListener
200+
void testErrorPropertySource(ListStatusListener statusListener) {
197201
final String key = "testKey";
198202
final Properties props = new Properties();
199203
props.put(key, "test");
200204
final PropertiesUtil util = new PropertiesUtil(props);
201205
final ErrorPropertySource source = new ErrorPropertySource();
202206
util.addPropertySource(source);
203207
try {
208+
statusListener.clear();
204209
assertEquals("test", util.getStringProperty(key));
205210
assertTrue(source.exceptionThrown);
211+
assertThat(statusListener.findStatusData(Level.WARN))
212+
.anySatisfy(data ->
213+
assertThat(data.getMessage().getFormattedMessage()).contains("Failed"));
206214
} finally {
207215
util.removePropertySource(source);
208216
}
@@ -211,7 +219,8 @@ void testErrorPropertySource() {
211219
@Test
212220
@ResourceLock(value = Resources.SYSTEM_PROPERTIES, mode = ResourceAccessMode.READ)
213221
@Issue("https://github.com/apache/logging-log4j2/issues/3252")
214-
void testRecursivePropertySource() {
222+
@UsingStatusListener
223+
void testRecursivePropertySource(ListStatusListener statusListener) {
215224
final String key = "testKey";
216225
final Properties props = new Properties();
217226
props.put(key, "test");
@@ -220,8 +229,20 @@ void testRecursivePropertySource() {
220229
util.addPropertySource(source);
221230
try {
222231
// We ignore the recursive source
232+
statusListener.clear();
223233
assertThat(util.getStringProperty(key)).isEqualTo("test");
234+
assertThat(statusListener.findStatusData(Level.WARN))
235+
.anySatisfy(data -> assertThat(data.getMessage().getFormattedMessage())
236+
.contains("Recursive call", "getProperty"));
237+
238+
statusListener.clear();
239+
// To check for existence, the sources are looked up in a random order.
224240
assertThat(util.hasProperty(key)).isTrue();
241+
// To find a missing key, all the sources must be used.
242+
assertThat(util.hasProperty("noSuchKey")).isFalse();
243+
assertThat(statusListener.findStatusData(Level.WARN))
244+
.anySatisfy(data -> assertThat(data.getMessage().getFormattedMessage())
245+
.contains("Recursive call", "containsProperty"));
225246
// We check that the source is recursive
226247
assertThat(source.getProperty(key)).isEqualTo("test");
227248
assertThat(source.containsProperty(key)).isTrue();

0 commit comments

Comments
 (0)