### Question:
WorkflowServiceInstanceService implements ServiceInstanceService { @Override public Mono<DeleteServiceInstanceResponse> deleteServiceInstance(DeleteServiceInstanceRequest request) { return invokeDeleteResponseBuilders(request) .publishOn(Schedulers.parallel()) .doOnNext(response -> delete(request, response) .subscribe()); } WorkflowServiceInstanceService(ServiceInstanceStateRepository serviceInstanceStateRepository,
		List<CreateServiceInstanceWorkflow> createServiceInstanceWorkflows,
		List<DeleteServiceInstanceWorkflow> deleteServiceInstanceWorkflows,
		List<UpdateServiceInstanceWorkflow> updateServiceInstanceWorkflows); @Override Mono<CreateServiceInstanceResponse> createServiceInstance(CreateServiceInstanceRequest request); @Override Mono<DeleteServiceInstanceResponse> deleteServiceInstance(DeleteServiceInstanceRequest request); @Override Mono<UpdateServiceInstanceResponse> updateServiceInstance(UpdateServiceInstanceRequest request); @Override Mono<GetLastServiceOperationResponse> getLastOperation(GetLastServiceOperationRequest request); @Override Mono<GetServiceInstanceResponse> getServiceInstance(GetServiceInstanceRequest request);  }### Answer:
@Test void deleteServiceInstance() { given(serviceInstanceStateRepository.saveState(anyString(), any(OperationState.class), anyString())) .willReturn( Mono.just( new ServiceInstanceState(OperationState.IN_PROGRESS, "delete service instance started", new Timestamp(Instant.now().minusSeconds(60).toEpochMilli())))) .willReturn( Mono.just( new ServiceInstanceState(OperationState.SUCCEEDED, "delete service instance completed", new Timestamp(Instant.now().minusSeconds(30).toEpochMilli())))); DeleteServiceInstanceRequest request = DeleteServiceInstanceRequest.builder() .serviceInstanceId("foo") .build(); DeleteServiceInstanceResponseBuilder responseBuilder = DeleteServiceInstanceResponse.builder(); DeleteServiceInstanceResponse builtResponse = DeleteServiceInstanceResponse.builder() .async(true) .operation("working2") .build(); TestPublisher<Void> lowerOrderFlow = TestPublisher.create(); TestPublisher<Void> higherOrderFlow = TestPublisher.create(); given(deleteServiceInstanceWorkflow1.accept(request)) .willReturn(Mono.just(true)); given( deleteServiceInstanceWorkflow1 .buildResponse(eq(request), any(DeleteServiceInstanceResponseBuilder.class))) .willReturn(Mono.just(responseBuilder .async(true) .operation("working1"))); given(deleteServiceInstanceWorkflow1.delete(eq(request), eq(builtResponse))) .willReturn(lowerOrderFlow.mono()); given(deleteServiceInstanceWorkflow2.accept(request)) .willReturn(Mono.just(true)); given( deleteServiceInstanceWorkflow2 .buildResponse(eq(request), any(DeleteServiceInstanceResponseBuilder.class))) .willReturn(Mono.just(responseBuilder .operation("working2"))); given(deleteServiceInstanceWorkflow2.delete(eq(request), eq(builtResponse))) .willReturn(higherOrderFlow.mono()); StepVerifier.create(workflowServiceInstanceService.deleteServiceInstance(request)) .assertNext(response -> { InOrder repoOrder = inOrder(serviceInstanceStateRepository); repoOrder.verify(serviceInstanceStateRepository) .saveState(eq("foo"), eq(OperationState.IN_PROGRESS), eq("delete service instance started")); repoOrder.verify(serviceInstanceStateRepository) .saveState(eq("foo"), eq(OperationState.SUCCEEDED), eq("delete service instance completed")); repoOrder.verifyNoMoreInteractions(); lowerOrderFlow.complete(); lowerOrderFlow.assertWasNotRequested(); higherOrderFlow.complete(); lowerOrderFlow.assertWasRequested(); InOrder deleteOrder = inOrder(deleteServiceInstanceWorkflow1, deleteServiceInstanceWorkflow2); deleteOrder.verify(deleteServiceInstanceWorkflow2).buildResponse(eq(request), any(DeleteServiceInstanceResponseBuilder.class)); deleteOrder.verify(deleteServiceInstanceWorkflow1).buildResponse(eq(request), any(DeleteServiceInstanceResponseBuilder.class)); deleteOrder.verify(deleteServiceInstanceWorkflow2).delete(request, responseBuilder.build()); deleteOrder.verify(deleteServiceInstanceWorkflow1).delete(request, responseBuilder.build()); deleteOrder.verifyNoMoreInteractions(); assertThat(response).isNotNull(); assertThat(response.isAsync()).isTrue(); assertThat(response.getOperation()).isEqualTo("working2"); }) .verifyComplete(); }