CloudFoundryApi implements CloudFoundryApiService { @Override public boolean isAppRunning(String appUid) throws CloudFoundryException { log.debug("isAppRunning"); try { return !(Optional.ofNullable(getApplicationInstances(appUid) .flatMapMany(response -> Flux.fromIterable(response.getInstances().values())) .filter(instanceInfo -> "RUNNING".equals(instanceInfo.getState())) .collect(ArrayList<ApplicationInstanceInfo>::new, ArrayList::add) .block(Config.CF_API_TIMEOUT))).get() .isEmpty(); } catch (RuntimeException r) { throw new CloudFoundryException(r); } }  @Override void bindApplications(String serviceInstanceId, List<ApplicationIdentity> applications); void bindRoutes(String serviceInstanceId, List<String> routeIds); @Override ApplicationActivity getApplicationActivity(String appUid); Instant getInstantFromLogMessageTimestamp(Long logMessageTimestamp); @Override String getApplicationState(String applicationUuid); @Override String getHost(String routeId); @Override boolean isAppRunning(String appUid); @Override List<ApplicationIdentity> listAliveApplications(String spaceUuid, Pattern excludeNames); @Override List<String> listApplicationRoutes(String applicationUuid); @Override List<String> listRouteApplications(String routeUuid); @Override boolean startApplication(String applicationUuid); @Override boolean stopApplication(String applicationUuid); @Override void unbind(String bindingId); boolean isValidOrganization(String organizationGuid);  }
@Test public void test_is_app_running_should_return_true() throws CloudFoundryException { ApplicationsV2 applications = mock(ApplicationsV2.class); when(cfClient.applicationsV2()).thenReturn(applications); when(applications.instances(any(ApplicationInstancesRequest.class))) .thenReturn(Mono.just(ApplicationInstancesResponse.builder() .instance("1", ApplicationInstanceInfo.builder() .state("STAGING") .build()) .instance("2", ApplicationInstanceInfo.builder() .state("STAGING") .build()) .instance("3", ApplicationInstanceInfo.builder() .state("CRASHED") .build()) .instance("4", ApplicationInstanceInfo.builder() .state("RUNNING") .build()) .build())); assertTrue(cloudFoundryApi.isAppRunning("application-id")); verify(applications, times(1)).instances(any(ApplicationInstancesRequest.class)); }