### Question:
CloudFoundryAppManager implements AppManager { @Override public Mono<Void> stop(StopApplicationRequest request) { return Mono.justOrEmpty(request) .flatMap(req -> operationsUtils.getOperations(req.getProperties()) .flatMap(cfOperations -> Mono.justOrEmpty(req.getName()) .flatMap(appName -> cfOperations.applications().stop( org.cloudfoundry.operations.applications.StopApplicationRequest.builder() .name(appName) .build()) .doOnRequest(l -> { LOG.info("Stopping application. appName={}", appName); LOG.debug(REQUEST_LOG_TEMPLATE, request); }) .doOnSuccess(v -> { LOG.info("Success stopping application. appName={}", appName); LOG.debug(REQUEST_LOG_TEMPLATE, request); }) .doOnError(e -> { LOG.error(String.format("Error stopping application. appName=%s, error=%s", appName, e.getMessage()), e); LOG.debug(REQUEST_LOG_TEMPLATE, request); })))); } CloudFoundryAppManager(CloudFoundryOperationsUtils operationsUtils); @Override Mono<Void> start(StartApplicationRequest request); @Override Mono<Void> stop(StopApplicationRequest request); @Override Mono<Void> restart(RestartApplicationRequest request); @Override Mono<Void> restage(RestageApplicationRequest request);  }### Answer:
@Test void stopNullApplication() { StepVerifier.create(appManager.stop(null)) .verifyComplete(); then(operationsApplications).shouldHaveNoInteractions(); then(operations).shouldHaveNoMoreInteractions(); }
@Test void stopApplication() { setupStubs(); given(operationsApplications.stop(any(org.cloudfoundry.operations.applications.StopApplicationRequest.class))) .willReturn(Mono.empty()); StopApplicationRequest request = StopApplicationRequest.builder() .name("my-foo-app") .build(); StepVerifier.create(appManager.stop(request)) .verifyComplete(); then(operationsApplications).should().stop(argThat(req -> "my-foo-app".equals(req.getName()))); then(operations).shouldHaveNoMoreInteractions(); }
@Test void stopApplicationWithEmptyName() { given(operationsUtils.getOperations(anyMap())).willReturn(Mono.just(operations)); StopApplicationRequest request = StopApplicationRequest.builder() .build(); StepVerifier.create(appManager.stop(request)) .verifyComplete(); then(operationsApplications).shouldHaveNoInteractions(); then(operations).shouldHaveNoMoreInteractions(); }