|
12 | 12 | import java.util.Optional;
|
13 | 13 | import java.util.stream.Stream;
|
14 | 14 |
|
| 15 | +import jakarta.annotation.Priority; |
| 16 | + |
15 | 17 | import org.junit.jupiter.api.Test;
|
16 | 18 |
|
17 | 19 | class ExpressionConfigSourceInterceptorTest {
|
@@ -203,10 +205,39 @@ void windowPath() {
|
203 | 205 | assertEquals("C:\\Some\\Path", config.getRawValue("window.path"));
|
204 | 206 | }
|
205 | 207 |
|
| 208 | + @Test |
| 209 | + void nullValue() { |
| 210 | + SmallRyeConfig config = buildConfigWithCustomInterceptor("sth", null); |
| 211 | + ConfigValue configValue = config.getConfigValue("sth"); |
| 212 | + |
| 213 | + assertNotNull(configValue); |
| 214 | + |
| 215 | + // No exception is thrown, only null is returned |
| 216 | + assertNull(configValue.getValue()); |
| 217 | + } |
| 218 | + |
206 | 219 | private static SmallRyeConfig buildConfig(String... keyValues) {
|
207 | 220 | return new SmallRyeConfigBuilder()
|
208 | 221 | .addDefaultInterceptors()
|
209 | 222 | .withSources(KeyValuesConfigSource.config(keyValues))
|
210 | 223 | .build();
|
211 | 224 | }
|
| 225 | + |
| 226 | + private static SmallRyeConfig buildConfigWithCustomInterceptor(String... keyValues) { |
| 227 | + return new SmallRyeConfigBuilder() |
| 228 | + .addDefaultInterceptors() |
| 229 | + .withInterceptors(new CustomConfigSourceInterceptor()) |
| 230 | + .withInterceptors(new ExpressionConfigSourceInterceptor()) |
| 231 | + .withSources(KeyValuesConfigSource.config(keyValues)) |
| 232 | + .build(); |
| 233 | + } |
| 234 | + |
| 235 | + @Priority(Priorities.LIBRARY + 201) |
| 236 | + private static class CustomConfigSourceInterceptor implements ConfigSourceInterceptor { |
| 237 | + |
| 238 | + @Override |
| 239 | + public ConfigValue getValue(ConfigSourceInterceptorContext context, String name) { |
| 240 | + return ConfigValue.builder().withName(name).withValue(null).build(); |
| 241 | + } |
| 242 | + } |
212 | 243 | }
|
0 commit comments