### Question:
DynamicRegistryImp implements DynamicRegistry { @Override public <T> Mono<Void> listenEvent(String eventName, EventHandler<T> fn, Class<T> eventClass){ resolver.addEventListener(new RegisteredEventListener<>(eventName, fn, eventClass)); final Mono<AMQP.Queue.BindOk> bind = topologyCreator.bind(BindingSpecification.binding(props.getDomainEventsExchangeName(), eventName, props.getEventsQueue())); return bind.then(); }  @Override Mono<Void> listenEvent(String eventName, EventHandler<T> fn, Class<T> eventClass);  }### Answer:
@Test public void registerEventListener() { when(topologyCreator.bind(any())).thenReturn(just(mock(BindOk.class))); registry.listenEvent("event1", message -> Mono.empty(), Long.class); final RegisteredEventListener<Object> listener = resolver.getEventListener("event1"); assertThat(listener).isNotNull(); }
@Test public void declareBindingWhenRegisterEventListener() { ArgumentCaptor<BindingSpecification> captor = ArgumentCaptor.forClass(BindingSpecification.class); when(topologyCreator.bind(any())).thenReturn(just(mock(BindOk.class))); registry.listenEvent("event1", message -> Mono.empty(), Long.class); verify(topologyCreator).bind(captor.capture()); final BindingSpecification binding = captor.getValue(); assertThat(binding.getQueue()).isEqualTo(props.getEventsQueue()); assertThat(binding.getExchange()).isEqualTo(props.getDomainEventsExchangeName()); assertThat(binding.getRoutingKey()).isEqualTo("event1"); }
@Test public void subscribeToResultWhenRegisterEventListener() { PublisherProbe<BindOk> probe = PublisherProbe.of(just(mock(BindOk.class))); when(topologyCreator.bind(any())).thenReturn(probe.mono()); Mono<Void> result = registry.listenEvent("event1", message -> Mono.empty(), Long.class); StepVerifier.create(result).verifyComplete(); probe.assertWasSubscribed(); }