Filter empty health contributions

Update `HealthEndpointSupport` so that aggregate elements that don't
ultimately provide a contribution are filtered out. Prior to this
commit an NPE was returned when calculating the aggregate status.

Fixes gh-18687
This commit is contained in:
Phillip Webb
2019-10-23 12:37:42 -07:00
parent 6378863771
commit 7c9ac03014
2 changed files with 13 additions and 3 deletions

View File

@@ -207,6 +207,14 @@ abstract class HealthEndpointSupportTests<R extends ContributorRegistry<C>, C, T
assertThat(getHealth(result)).isNotInstanceOf(SystemHealth.class);
}
@Test
void getHealthWithEmptyCompositeReturnsNullResult() { // gh-18687
this.registry.registerContributor("test", createCompositeContributor(Collections.emptyMap()));
HealthResult<T> result = create(this.registry, this.groups).getHealth(ApiVersion.V3, SecurityContext.NONE,
false);
assertThat(result).isNull();
}
protected abstract HealthEndpointSupport<C, T> create(R registry, HealthEndpointGroups groups);
protected abstract R createRegistry();