@NonNull
    @Override
    public HealthResponse healthResponse(final Map<String, Collection<String>> queryParams) {
        final String type = queryParams.getOrDefault(CHECK_TYPE_QUERY_PARAM, Collections.emptyList())
            .stream()
            .findFirst()
            .orElse(null);

        final Collection<HealthStateView> views = getViews(queryParams);

        final String responseBody;
        try {
            responseBody = mapper.writeValueAsString(views);
        } catch (final Exception e) {
            LOGGER.error("Failed to serialize health state views: {}", views, e);
            throw new RuntimeException(e);
        }
        final boolean healthy = healthStatusChecker.isHealthy(type);

        final int status;
        if (healthy) {
            // HTTP OK
            status = 200;
        } else {
            // HTTP Service unavailable
            status = 503;
        }

        return new HealthResponse(healthy, responseBody, MEDIA_TYPE, status);
    }
@Test
    void shouldHandleSingleHealthStateViewCorrectly() throws IOException {
        // given
        final HealthStateView view = new HealthStateView("foo", true, HealthCheckType.READY, true);
        final Map<String, Collection<String>> queryParams = Collections.singletonMap(
            JsonHealthResponseProvider.NAME_QUERY_PARAM, Collections.singleton(view.getName()));

        // when
        when(healthStateAggregator.healthStateView(view.getName())).thenReturn(Optional.of(view));
        when(healthStatusChecker.isHealthy(isNull())).thenReturn(true);
        final HealthResponse response = jsonHealthResponseProvider.healthResponse(queryParams);

        // then
        assertThat(response.isHealthy()).isTrue();
        assertThat(response.getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
        assertThat(mapper.readTree(response.getMessage())).isEqualTo(mapper.readTree(fixture("/json/single-healthy-response.json")));
    }