### Question:
BackingAppManagementService { public Mono<Void> restart(String serviceInstanceId) { return fetchServiceDetailsAndInvoke(serviceInstanceId, this::restart); } BackingAppManagementService(ManagementClient managementClient, AppDeployer appDeployer,
		BrokeredServices brokeredServices, TargetService targetService); Mono<Void> stop(String serviceInstanceId); Mono<Void> stop(String serviceInstanceId, String serviceName, String planName); Mono<Void> start(String serviceInstanceId); Mono<Void> start(String serviceInstanceId, String serviceName, String planName); Mono<Void> restart(String serviceInstanceId); Mono<Void> restart(String serviceInstanceId, String serviceName, String planName); Mono<Void> restage(String serviceInstanceId); Mono<Void> restage(String serviceInstanceId, String serviceName, String planName); Mono<BackingApplications> getDeployedBackingApplications(String serviceInstanceId); Mono<BackingApplications> getDeployedBackingApplications(String serviceInstanceId, String serviceName, String planName); Mono<BackingApplications> getBackingApplicationsForService(String serviceInstanceId, String serviceName,
		String planName);  }### Answer:
@Test void restartApplications() { given(appDeployer.getServiceInstance(any(GetServiceInstanceRequest.class))) .willReturn(Mono.just(GetServiceInstanceResponse.builder() .name("foo-service") .plan("plan1") .service("service1") .build())); given(targetService.addToBackingApplications(eq(backingApps), any(), eq("foo-service-id"))) .willReturn(Mono.just(backingApps)); doReturn(Mono.empty()).when(managementClient).restart(backingApps.get(0)); doReturn(Mono.empty()).when(managementClient).restart(backingApps.get(1)); StepVerifier.create(backingAppManagementService.restart("foo-service-id")) .expectNext() .expectNext() .verifyComplete(); verify(appDeployer).getServiceInstance(any(GetServiceInstanceRequest.class)); verify(targetService).addToBackingApplications(eq(backingApps), any(), eq("foo-service-id")); verify(managementClient, times(2)).restart(any(BackingApplication.class)); verifyNoMoreInteractions(appDeployer, targetService, managementClient); }
@Test void restartApplicationsServiceNotFound() { given(appDeployer.getServiceInstance(any(GetServiceInstanceRequest.class))) .willReturn(Mono.just(GetServiceInstanceResponse.builder() .build())); StepVerifier.create(backingAppManagementService.restart("unknown-service-id")) .verifyComplete(); verifyNoMoreInteractions(appDeployer, targetService, managementClient); }
@Test void restartApplicationsWithEmptyApplications() { BackingApplications emptyBackingApps = BackingApplications.builder().build(); BrokeredServices brokeredServicesNoApps = BrokeredServices .builder() .service(BrokeredService .builder() .serviceName("service1") .planName("plan1") .apps(emptyBackingApps) .build()) .build(); this.backingAppManagementService = new BackingAppManagementService(managementClient, appDeployer, brokeredServicesNoApps, targetService); given(appDeployer.getServiceInstance(any(GetServiceInstanceRequest.class))) .willReturn(Mono.just(GetServiceInstanceResponse.builder() .name("foo-service") .plan("plan1") .service("service1") .build())); given(targetService.addToBackingApplications(eq(emptyBackingApps), any(), eq("foo-service-id"))) .willReturn(Mono.just(emptyBackingApps)); StepVerifier.create(backingAppManagementService.restart("foo-service-id")) .verifyComplete(); verify(appDeployer).getServiceInstance(any(GetServiceInstanceRequest.class)); verify(targetService).addToBackingApplications(eq(emptyBackingApps), any(), eq("foo-service-id")); verifyNoInteractions(managementClient); verifyNoMoreInteractions(appDeployer, targetService, managementClient); }