Skip to content

Commit

Permalink
Test parent lookup support in ExtensionContext.Store
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jan 19, 2016
1 parent a873323 commit 0c71627
Showing 1 changed file with 19 additions and 12 deletions.
Expand Up @@ -93,18 +93,25 @@ public void usingStore() {
MethodBasedTestExtensionContext childContext = new MethodBasedTestExtensionContext(parentContext, null,
methodTestDescriptor, new OuterClass());

ExtensionContext.Store store = childContext.getStore();

store.put("a key", "a value");
assertEquals("a value", store.get("a key"));

assertEquals("other value", store.getOrComputeIfAbsent("other key", key -> "other value"));

assertEquals("a value", store.remove("a key"));
assertNull(store.get("a key"));

store.put("parent key", "parent value");
assertEquals("parent value", store.get("parent key"));
ExtensionContext.Store childStore = childContext.getStore();
ExtensionContext.Store parentStore = parentContext.getStore();

final Object key1 = "key 1";
final String value1 = "a value";
childStore.put(key1, value1);
assertEquals(value1, childStore.get(key1));
assertEquals(value1, childStore.remove(key1));
assertNull(childStore.get(key1));

final Object key2 = "key 2";
final String value2 = "other value";
assertEquals(value2, childStore.getOrComputeIfAbsent(key2, key -> value2));
assertEquals(value2, childStore.get(key2));

final Object parentKey = "parent key";
final String parentValue = "parent value";
parentStore.put(parentKey, parentValue);
assertEquals(parentValue, childStore.get(parentKey));
}

private ClassTestDescriptor nestedClassDescriptor() {
Expand Down

0 comments on commit 0c71627

Please sign in to comment.