Skip to content

Commit

Permalink
Treat ClouldPlatform.NONE as null
Browse files Browse the repository at this point in the history
  • Loading branch information
quaff committed Nov 23, 2023
1 parent 9c68a2a commit 48b05d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*
* @author Phillip Webb
* @author Madhura Bhave
* @author Yanming Zhou
*/
class ConfigDataProperties {

Expand Down Expand Up @@ -118,14 +119,14 @@ boolean isActive(ConfigDataActivationContext activationContext) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*
* @author Phillip Webb
* @author Madhura Bhave
* @author Yanming Zhou
*/
class ConfigDataPropertiesTests {

Expand Down Expand Up @@ -98,6 +99,13 @@ void isActiveWhenSpecificCloudPlatformAgainstDifferentSpecificCloudPlatform() {
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));
Expand Down

0 comments on commit 48b05d2

Please sign in to comment.