### Question:
WorkflowServiceInstanceService implements ServiceInstanceService { @Override public Mono<UpdateServiceInstanceResponse> updateServiceInstance(UpdateServiceInstanceRequest request) { return invokeUpdateResponseBuilders(request) .publishOn(Schedulers.parallel()) .doOnNext(response -> update(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 updateServiceInstance() { given(serviceInstanceStateRepository.saveState(anyString(), any(OperationState.class), anyString())) .willReturn( Mono.just( new ServiceInstanceState(OperationState.IN_PROGRESS, "update service instance started", new Timestamp(Instant.now().minusSeconds(60).toEpochMilli())))) .willReturn( Mono.just( new ServiceInstanceState(OperationState.SUCCEEDED, "update service instance completed", new Timestamp(Instant.now().minusSeconds(30).toEpochMilli())))); UpdateServiceInstanceRequest request = UpdateServiceInstanceRequest.builder() .serviceInstanceId("foo") .build(); UpdateServiceInstanceResponseBuilder responseBuilder = UpdateServiceInstanceResponse.builder(); UpdateServiceInstanceResponse builtResponse = UpdateServiceInstanceResponse.builder() .async(true) .dashboardUrl("https: .operation("working2") .build(); TestPublisher<Void> lowerOrderFlow = TestPublisher.create(); TestPublisher<Void> higherOrderFlow = TestPublisher.create(); given(updateServiceInstanceWorkflow1.accept(request)) .willReturn(Mono.just(true)); given( updateServiceInstanceWorkflow1 .buildResponse(eq(request), any(UpdateServiceInstanceResponseBuilder.class))) .willReturn(Mono.just(responseBuilder .async(true) .operation("working1"))); given(updateServiceInstanceWorkflow1.update(eq(request), eq(builtResponse))) .willReturn(lowerOrderFlow.mono()); given(updateServiceInstanceWorkflow2.accept(request)) .willReturn(Mono.just(true)); given( updateServiceInstanceWorkflow2 .buildResponse(eq(request), any(UpdateServiceInstanceResponseBuilder.class))) .willReturn(Mono.just(responseBuilder .dashboardUrl("https: .operation("working2"))); given(updateServiceInstanceWorkflow2.update(eq(request), eq(builtResponse))) .willReturn(higherOrderFlow.mono()); StepVerifier.create(workflowServiceInstanceService.updateServiceInstance(request)) .assertNext(response -> { InOrder repoOrder = inOrder(serviceInstanceStateRepository); repoOrder.verify(serviceInstanceStateRepository) .saveState(eq("foo"), eq(OperationState.IN_PROGRESS), eq("update service instance started")); repoOrder.verify(serviceInstanceStateRepository) .saveState(eq("foo"), eq(OperationState.SUCCEEDED), eq("update service instance completed")); repoOrder.verifyNoMoreInteractions(); lowerOrderFlow.complete(); lowerOrderFlow.assertWasNotRequested(); higherOrderFlow.complete(); lowerOrderFlow.assertWasRequested(); InOrder updateOrder = inOrder(updateServiceInstanceWorkflow1, updateServiceInstanceWorkflow2); updateOrder.verify(updateServiceInstanceWorkflow2).buildResponse(eq(request), any(UpdateServiceInstanceResponseBuilder.class)); updateOrder.verify(updateServiceInstanceWorkflow1).buildResponse(eq(request), any(UpdateServiceInstanceResponseBuilder.class)); updateOrder.verify(updateServiceInstanceWorkflow2).update(request, builtResponse); updateOrder.verify(updateServiceInstanceWorkflow1).update(request, builtResponse); updateOrder.verifyNoMoreInteractions(); assertThat(response).isNotNull(); assertThat(response.isAsync()).isTrue(); assertThat(response.getDashboardUrl()).isEqualTo("https: assertThat(response.getOperation()).isEqualTo("working2"); }) .verifyComplete(); }