### Question:
CloudFoundryContainerPlatform extends CloudFoundryPlatform implements SshBasedExperiment<CloudFoundryContainer> { Instant getTimeInState (CloudFoundryContainer container) { log.debug("Looking for time in state of {}", v(DataDogConstants.DATADOG_CONTAINER_KEY, container)); String applicationId = container.getApplicationId(); String instanceIndex = container.getInstance().toString(); final ApplicationInstanceInfo applicationInstanceInfo = cloudFoundryClient.applicationsV2() .instances(ApplicationInstancesRequest .builder() .applicationId(applicationId) .build()) .blockOptional() .orElseThrow(EMPTY_RESPONSE.asChaosException()) .getInstances() .get(instanceIndex); log.debug("Time in state from Application Instance Info: {}", v("applicationInstanceInfo", applicationInstanceInfo)); Double since = applicationInstanceInfo.getSince(); return since == null ? null : Instant.ofEpochSecond(since.longValue()); } @Autowired  CloudFoundryContainerPlatform(); @Override boolean isContainerRecycled(Container container); ContainerHealth checkHealth(String applicationId, Integer instanceId); @Override List<Container> generateRoster(); void restartInstance(RestartApplicationInstanceRequest restartApplicationInstanceRequest); @Override String getEndpoint(CloudFoundryContainer container); @Override SSHCredentials getSshCredentials(CloudFoundryContainer container); @Override void recycleContainer(CloudFoundryContainer container);  }### Answer:
@Test public void getTimeInState () { String applicationId = UUID.randomUUID().toString(); Integer index = new Random().nextInt(100) + 1; CloudFoundryContainer container = CloudFoundryContainer.builder().applicationId(applicationId).instance(index).build(); ApplicationsV2 applicationsV2 = mock(ApplicationsV2.class); doReturn(applicationsV2).when(cloudFoundryClient).applicationsV2(); Double since = 1552569958D; ApplicationInstanceInfo instanceInfo = ApplicationInstanceInfo.builder().since(since).build(); ApplicationInstancesResponse response = ApplicationInstancesResponse.builder() .instance(index.toString(), instanceInfo) .build(); doReturn(Mono.just(response)).when(applicationsV2) .instances(ApplicationInstancesRequest.builder().applicationId(applicationId).build()); Instant expected = DateTimeFormatter.ISO_INSTANT.parse("2019-03-14T13:25:58Z", Instant::from); assertEquals(expected, cloudFoundryContainerPlatform.getTimeInState(container)); }
@Test(expected = ChaosException.class) public void getTimeInStateChaosException () { String applicationId = UUID.randomUUID().toString(); Integer index = new Random().nextInt(100) + 1; CloudFoundryContainer container = CloudFoundryContainer.builder().applicationId(applicationId).instance(index).build(); ApplicationsV2 applicationsV2 = mock(ApplicationsV2.class); doReturn(applicationsV2).when(cloudFoundryClient).applicationsV2(); doReturn(Mono.empty()).when(applicationsV2).instances(ApplicationInstancesRequest.builder().applicationId(applicationId).build()); cloudFoundryContainerPlatform.getTimeInState(container); }