private static StateListener getStateListener(final KafkaStreams streams) {
        try {
            if (streams instanceof KafkaStreamsNamedTopologyWrapper) {
                final Field field = streams.getClass().getSuperclass().getDeclaredField("stateListener");
                field.setAccessible(true);
                return (StateListener) field.get(streams);
            } else {
                final Field field = streams.getClass().getDeclaredField("stateListener");
                field.setAccessible(true);
                return (StateListener) field.get(streams);
            }
        } catch (final IllegalAccessException | NoSuchFieldException e) {
            throw new RuntimeException("Failed to get StateListener through reflection", e);
        }
    }
Waits for the given {@link KafkaStreams} instances to all be in a specific {@link State}.
Prefer {@link #startApplicationAndWaitUntilRunning(List, Duration)} when possible
because this method uses polling, which can be more error prone and slightly slower.

@param streamsList the list of streams instances to run.
@param state the expected state that all the streams to be in within timeout
@param timeout the time to wait for the streams to all be in the specific state.

@throws InterruptedException if the streams doesn't change to the expected state in time.
streams/src/test/java/org/apache/kafka/streams/integration/utils/IntegrationTestUtils.java