Tolerate Integer values for port properties

Closes gh-14682
This commit is contained in:
Andy Wilkinson
2018-10-04 09:53:28 +01:00
parent b473f2996d
commit da7daece08
2 changed files with 40 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link SpringBootTestRandomPortEnvironmentPostProcessor}.
*
* @author Madhura Bhave
* @author Andy Wilkinson
*/
public class SpringBootTestRandomPortEnvironmentPostProcessorTests {
@@ -130,6 +131,16 @@ public class SpringBootTestRandomPortEnvironmentPostProcessorTests {
.isEqualTo("-1");
}
@Test
public void postProcessWhenTestServerPortIsZeroAndManagementPortIsAnInteger() {
addTestPropertySource("0", null);
this.propertySources.addLast(new MapPropertySource("other",
Collections.singletonMap("management.server.port", 8081)));
this.postProcessor.postProcessEnvironment(this.environment, null);
assertThat(this.environment.getProperty("server.port")).isEqualTo("0");
assertThat(this.environment.getProperty("management.server.port")).isEqualTo("0");
}
private void addTestPropertySource(String serverPort, String managementPort) {
Map<String, Object> source = new HashMap<>();
source.put("server.port", serverPort);