Treat null as CloudPlatform.NONE

See gh-38510
This commit is contained in:
Yanming Zhou 2023-11-23 10:40:01 +08:00 committed by Andy Wilkinson
parent 71a155677d
commit 01bb806672
2 changed files with 12 additions and 3 deletions

View File

@ -32,6 +32,7 @@ import org.springframework.util.ObjectUtils;
*
* @author Phillip Webb
* @author Madhura Bhave
* @author Yanming Zhou
*/
class ConfigDataProperties {
@ -118,14 +119,14 @@ class ConfigDataProperties {
if (activationContext == null) {
return false;
}
boolean activate = true;
activate = activate && isActive(activationContext.getCloudPlatform());
boolean activate = isActive(activationContext.getCloudPlatform());
activate = activate && isActive(activationContext.getProfiles());
return activate;
}
private boolean isActive(CloudPlatform cloudPlatform) {
return this.onCloudPlatform == null || this.onCloudPlatform == cloudPlatform;
return this.onCloudPlatform == null || this.onCloudPlatform == CloudPlatform.NONE && cloudPlatform == null
|| this.onCloudPlatform == cloudPlatform;
}
private boolean isActive(Profiles profiles) {

View File

@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
* @author Madhura Bhave
* @author Yanming Zhou
*/
class ConfigDataPropertiesTests {
@ -98,6 +99,13 @@ class ConfigDataPropertiesTests {
assertThat(properties.isActive(context)).isFalse();
}
@Test
void isActiveWhenSpecificNoneCloudPlatformAgainstNullCloudPlatform() {
ConfigDataProperties properties = new ConfigDataProperties(NO_IMPORTS, new Activate(CloudPlatform.NONE, null));
ConfigDataActivationContext context = new ConfigDataActivationContext(NULL_CLOUD_PLATFORM, NULL_PROFILES);
assertThat(properties.isActive(context)).isTrue();
}
@Test
void isActiveWhenNullProfilesAgainstNullProfiles() {
ConfigDataProperties properties = new ConfigDataProperties(NO_IMPORTS, new Activate(null, null));