|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.boot.env;
|
18 | 18 |
|
19 | 19 | import java.util.Collections;
|
| 20 | +import java.util.Map; |
20 | 21 |
|
21 | 22 | import org.junit.jupiter.api.Test;
|
22 | 23 |
|
|
26 | 27 | import org.springframework.core.env.MapPropertySource;
|
27 | 28 | import org.springframework.core.env.PropertySource;
|
28 | 29 | import org.springframework.core.env.StandardEnvironment;
|
| 30 | +import org.springframework.mock.env.MockPropertySource; |
29 | 31 | import org.springframework.test.context.support.TestPropertySourceUtils;
|
30 | 32 | import org.springframework.web.context.support.StandardServletEnvironment;
|
31 | 33 |
|
@@ -170,6 +172,39 @@ void propertySourceOrderingWhenMultipleServletSpecificPropertySources() {
|
170 | 172 | assertThat(this.environment.getPropertySources()).containsSequence(custom, json, servlet, jndi);
|
171 | 173 | }
|
172 | 174 |
|
| 175 | + @Test |
| 176 | + void nullValuesShouldBeAddedToPropertySource() { |
| 177 | + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, |
| 178 | + "SPRING_APPLICATION_JSON={\"foo\":null}"); |
| 179 | + this.processor.postProcessEnvironment(this.environment, null); |
| 180 | + assertThat(this.environment.containsProperty("foo")).isTrue(); |
| 181 | + } |
| 182 | + |
| 183 | + @Test |
| 184 | + void emptyValuesForCollectionShouldNotBeIgnored() { |
| 185 | + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, |
| 186 | + "SPRING_APPLICATION_JSON={\"foo\":[]}"); |
| 187 | + MockPropertySource source = new MockPropertySource(); |
| 188 | + source.setProperty("foo", "bar"); |
| 189 | + this.environment.getPropertySources().addLast(source); |
| 190 | + assertThat(this.environment.resolvePlaceholders("${foo}")).isEqualTo("bar"); |
| 191 | + this.environment.getPropertySources().addLast(source); |
| 192 | + this.processor.postProcessEnvironment(this.environment, null); |
| 193 | + assertThat(this.environment.resolvePlaceholders("${foo}")).isEmpty(); |
| 194 | + } |
| 195 | + |
| 196 | + @Test |
| 197 | + @SuppressWarnings("unchecked") |
| 198 | + void emptyMapValuesShouldNotBeIgnored() { |
| 199 | + TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment, |
| 200 | + "SPRING_APPLICATION_JSON={\"foo\":{}}"); |
| 201 | + MockPropertySource source = new MockPropertySource(); |
| 202 | + source.setProperty("foo.baz", "bar"); |
| 203 | + this.environment.getPropertySources().addLast(source); |
| 204 | + this.processor.postProcessEnvironment(this.environment, null); |
| 205 | + assertThat(this.environment.getProperty("foo", Map.class)).isEmpty(); |
| 206 | + } |
| 207 | + |
173 | 208 | private void testServletPropertySource(String servletPropertySourceName) {
|
174 | 209 | this.environment.getPropertySources().addFirst(getPropertySource(servletPropertySourceName, "servlet"));
|
175 | 210 | TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.environment,
|
|
0 commit comments