|
16 | 16 |
|
17 | 17 | package org.springframework.aop.interceptor;
|
18 | 18 |
|
| 19 | +import java.lang.reflect.Field; |
| 20 | +import java.util.Arrays; |
| 21 | +import java.util.List; |
| 22 | + |
19 | 23 | import org.aopalliance.intercept.MethodInvocation;
|
20 | 24 | import org.apache.commons.logging.Log;
|
21 | 25 | import org.junit.jupiter.api.Test;
|
22 | 26 |
|
| 27 | +import org.springframework.util.ReflectionUtils; |
| 28 | + |
| 29 | +import static org.assertj.core.api.Assertions.assertThat; |
23 | 30 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
24 | 31 | import static org.mockito.ArgumentMatchers.anyString;
|
25 | 32 | import static org.mockito.ArgumentMatchers.eq;
|
26 | 33 | import static org.mockito.BDDMockito.given;
|
27 | 34 | import static org.mockito.Mockito.mock;
|
28 | 35 | import static org.mockito.Mockito.times;
|
29 | 36 | import static org.mockito.Mockito.verify;
|
| 37 | +import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.ALLOWED_PLACEHOLDERS; |
30 | 38 | import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENTS;
|
31 | 39 | import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.PLACEHOLDER_ARGUMENT_TYPES;
|
32 | 40 | import static org.springframework.aop.interceptor.CustomizableTraceInterceptor.PLACEHOLDER_EXCEPTION;
|
@@ -164,6 +172,34 @@ void sunnyDayPathLogsCorrectlyWithPrettyMuchAllPlaceholdersMatching() throws Thr
|
164 | 172 | verify(log, times(2)).trace(anyString());
|
165 | 173 | }
|
166 | 174 |
|
| 175 | + /** |
| 176 | + * This test effectively verifies that the internal ALLOWED_PLACEHOLDERS set |
| 177 | + * is properly configured in {@link CustomizableTraceInterceptor}. |
| 178 | + */ |
| 179 | + @Test |
| 180 | + @SuppressWarnings("deprecation") |
| 181 | + void supportedPlaceholderValues() { |
| 182 | + assertThat(ALLOWED_PLACEHOLDERS).containsAll(getPlaceholderConstantValues()); |
| 183 | + } |
| 184 | + |
| 185 | + private List<String> getPlaceholderConstantValues() { |
| 186 | + return Arrays.stream(CustomizableTraceInterceptor.class.getFields()) |
| 187 | + .filter(ReflectionUtils::isPublicStaticFinal) |
| 188 | + .filter(field -> field.getName().startsWith("PLACEHOLDER_")) |
| 189 | + .map(this::getFieldValue) |
| 190 | + .map(String.class::cast) |
| 191 | + .toList(); |
| 192 | + } |
| 193 | + |
| 194 | + private Object getFieldValue(Field field) { |
| 195 | + try { |
| 196 | + return field.get(null); |
| 197 | + } |
| 198 | + catch (Exception ex) { |
| 199 | + throw new RuntimeException(ex); |
| 200 | + } |
| 201 | + } |
| 202 | + |
167 | 203 |
|
168 | 204 | @SuppressWarnings("serial")
|
169 | 205 | private static class StubCustomizableTraceInterceptor extends CustomizableTraceInterceptor {
|
|
0 commit comments