@Override
    public void close() {
        RuntimeException firstException = null;
        for (Map.Entry<String, StateStore> entry : stores.entrySet()) {
            final StateStore store = entry.getValue();
            if (log.isDebugEnabled()) {
                log.debug("Closing store {}", store.fqsn());
            }
            try {
                store.close();
            } catch (RuntimeException e) {
                if (firstException == null) {
                    firstException = e;
                }
                log.error("Failed to close state store {}: ", store.fqsn(), e);
            }
        }
        stores.clear();
        if (null != firstException) {
            throw firstException;
        }
    }
@Test
    public void testClose() {
        final String fqsn1 = "t/ns/store-1";
        StateStore store1 = mock(StateStore.class);
        when(store1.fqsn()).thenReturn(fqsn1);
        final String fqsn2 = "t/ns/store-2";
        StateStore store2 = mock(StateStore.class);
        when(store2.fqsn()).thenReturn(fqsn2);

        this.stateManager.registerStore(store1);
        this.stateManager.registerStore(store2);

        this.stateManager.close();

        verify(store1, times(1)).close();
        verify(store2, times(1)).close();
    }