### Question:
ChainingStrategy implements EndpointDetectionStrategy { @Override public Mono<Endpoints> detectEndpoints(Instance instance) { Mono<Endpoints> result = Mono.empty(); for (EndpointDetectionStrategy delegate : delegates) { result = result.switchIfEmpty(delegate.detectEndpoints(instance)); } return result.switchIfEmpty(Mono.just(Endpoints.empty())); } ChainingStrategy(EndpointDetectionStrategy... delegates); @Override Mono<Endpoints> detectEndpoints(Instance instance);  }### Answer:
@Test public void should_chain_on_empty() { Instance instance = Instance.create(InstanceId.of("id")); ChainingStrategy strategy = new ChainingStrategy((a) -> Mono.empty(), (a) -> Mono.empty(), (a) -> Mono.just(Endpoints.single("id", "path"))); StepVerifier.create(strategy.detectEndpoints(instance)) .expectNext(Endpoints.single("id", "path")) .verifyComplete(); }
@Test public void should_chain_on_empty() { Instance instance = Instance.create(InstanceId.of("id")); ChainingStrategy strategy = new ChainingStrategy((a) -> Mono.empty(), (a) -> Mono.empty(), (a) -> Mono.just(Endpoints.single("id", "path"))); StepVerifier.create(strategy.detectEndpoints(instance)).expectNext(Endpoints.single("id", "path")) .verifyComplete(); }
@Test public void should_return_empty_endpoints_when_all_empty() { Instance instance = Instance.create(InstanceId.of("id")); ChainingStrategy strategy = new ChainingStrategy((a) -> Mono.empty()); StepVerifier.create(strategy.detectEndpoints(instance)).expectNext(Endpoints.empty()).verifyComplete(); }