@Override
  public Optional<PersistentQueryMetadata> getPersistentQuery(final QueryId queryId) {
    return Optional.ofNullable(persistentQueries.get(queryId));
  }
@Test
  public void shouldCallListenerOnStateChange() {
    // Given:
    final QueryMetadata.Listener queryListener = givenCreateGetListener(registry, "foo");
    final QueryMetadata query = registry.getPersistentQuery(new QueryId("foo")).get();

    // When:
    queryListener.onStateChange(query, State.CREATED, State.RUNNING);

    // Then:
    verify(listener1).onStateChange(query, State.CREATED, State.RUNNING);
    verify(listener2).onStateChange(query, State.CREATED, State.RUNNING);
  }