### Question:
CompositeReadOnlyKeyValueStore implements ReadOnlyKeyValueStore<K, V> { @Override public V get(final K key) { final List<ReadOnlyKeyValueStore<K, V>> stores = storeProvider.stores(storeName, storeType); for (ReadOnlyKeyValueStore<K, V> store : stores) { try { final V result = store.get(key); if (result != null) { return result; } } catch (InvalidStateStoreException e) { throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; please re-discover its location from the state metadata."); } } return null; } CompositeReadOnlyKeyValueStore(final StateStoreProvider storeProvider,
                                          final QueryableStoreType<ReadOnlyKeyValueStore<K, V>> storeType,
                                          final String storeName); @Override V get(final K key); @Override KeyValueIterator<K, V> range(final K from, final K to); @Override KeyValueIterator<K, V> all(); @Override long approximateNumEntries();  }### Answer:
@Test public void shouldReturnNullIfKeyDoesntExist() throws Exception { assertNull(theStore.get("whatever")); }
@Test public void shouldReturnValueIfExists() throws Exception { stubOneUnderlying.put("key", "value"); assertEquals("value", theStore.get("key")); }
@Test public void shouldNotGetValuesFromOtherStores() throws Exception { otherUnderlyingStore.put("otherKey", "otherValue"); assertNull(theStore.get("otherKey")); }
@SuppressWarnings("unchecked") @Test public void shouldFindValueForKeyWhenMultiStores() throws Exception { final KeyValueStore<String, String> cache = newStoreInstance(); stubProviderTwo.addStore(storeName, cache); cache.put("key-two", "key-two-value"); stubOneUnderlying.put("key-one", "key-one-value"); assertEquals("key-two-value", theStore.get("key-two")); assertEquals("key-one-value", theStore.get("key-one")); }
@Test(expected = InvalidStateStoreException.class) public void shouldThrowInvalidStoreExceptionDuringRebalance() throws Exception { rebalancing().get("anything"); }