### Question:
EndpointDetectionTrigger extends AbstractEventHandler<InstanceEvent> { protected Mono<Void> detectEndpoints(InstanceEvent event) { return this.endpointDetector.detectEndpoints(event.getInstance()).onErrorResume((e) -> { log.warn("Unexpected error while detecting endpoints for {}", event.getInstance(), e); return Mono.empty(); }); } EndpointDetectionTrigger(EndpointDetector endpointDetector, Publisher<InstanceEvent> publisher);   }### Answer:
@Test public void should_detect_on_status_changed() { this.events.next( new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown())); verify(this.detector, times(1)).detectEndpoints(this.instance.getId()); }
@Test public void should_detect_on_registration_updated() { this.events.next(new InstanceRegistrationUpdatedEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration())); verify(this.detector, times(1)).detectEndpoints(this.instance.getId()); }
@Test public void should_not_detect_on_non_relevant_event() { this.events.next(new InstanceRegisteredEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration())); verify(this.detector, never()).detectEndpoints(this.instance.getId()); }
@Test public void should_not_detect_on_trigger_stopped() { this.trigger.stop(); clearInvocations(this.detector); this.events.next(new InstanceRegisteredEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration())); verify(this.detector, never()).detectEndpoints(this.instance.getId()); }
@Test public void should_continue_detection_after_error() throws InterruptedException { when(this.detector.detectEndpoints(any())).thenReturn(Mono.error(IllegalStateException::new)) .thenReturn(Mono.empty()); this.events.next( new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown())); this.events.next( new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofUp())); verify(this.detector, times(2)).detectEndpoints(this.instance.getId()); }