### Question:
CloudFoundryPlatform extends Platform { @Override public PlatformHealth getPlatformHealth () { Flux<ApplicationSummary> runningInstances = cloudFoundryOperations.applications() .list() .filter(a -> a.getRequestedState().equals(CloudFoundryConstants.CLOUDFOUNDRY_APPLICATION_STARTED)); if (runningInstances.filter(a -> a.getInstances() > 0) .filter(a -> a.getRunningInstances() == 0) .hasElements() .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException())) { return PlatformHealth.FAILED; } else if (runningInstances.filter(a -> a.getInstances() > 0) .filter(a -> a.getRunningInstances() < a.getInstances()) .hasElements() .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException())) { return PlatformHealth.DEGRADED; } return PlatformHealth.OK; } @Autowired  CloudFoundryPlatform(); boolean isChaosEngine(String applicationName); @Override ApiStatus getApiStatus(); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); @Override List<Container> generateRoster(); void restageApplication(RestageApplicationRequest restageApplicationRequest);  }### Answer:
@Test public void getPlatformHealth () { ApplicationSummary stoppedApplicationSummary = builder_1.requestedState(CLOUDFOUNDRY_APPLICATION_STOPPED).build(); ApplicationSummary zeroInstancesApplicationSummary = builder_1.instances(0).build(); Flux<ApplicationSummary> applicationsFlux = Flux.just(applicationSummary_1, applicationSummary_2, stoppedApplicationSummary, zeroInstancesApplicationSummary); doReturn(applications).when(cloudFoundryOperations).applications(); doReturn(applicationsFlux).when(applications).list(); assertEquals(PlatformHealth.OK, cfp.getPlatformHealth()); }
@Test public void getPlatformDegradated () { applicationSummary_1 = builder_1.instances(10) .runningInstances(1) .requestedState(CLOUDFOUNDRY_APPLICATION_STARTED) .build(); Flux<ApplicationSummary> applicationsFlux = Flux.just(applicationSummary_1, applicationSummary_2); doReturn(applications).when(cloudFoundryOperations).applications(); doReturn(applicationsFlux).when(applications).list(); assertEquals(PlatformHealth.DEGRADED, cfp.getPlatformHealth()); }
@Test public void getPlatformFailed () { applicationSummary_1 = builder_1.instances(10) .runningInstances(0) .requestedState(CLOUDFOUNDRY_APPLICATION_STARTED) .build(); applicationSummary_2 = builder_2.instances(20) .runningInstances(0) .requestedState(CLOUDFOUNDRY_APPLICATION_STARTED) .build(); Flux<ApplicationSummary> applicationsFlux = Flux.just(applicationSummary_1, applicationSummary_2); doReturn(applications).when(cloudFoundryOperations).applications(); doReturn(applicationsFlux).when(applications).list(); assertEquals(PlatformHealth.FAILED, cfp.getPlatformHealth()); }