AbstractMetaDataContext parent = new AbstractMetaDataContext(parentLoader);
MutableMetaDataLoader childLoader = createTestMutableMetaDataLoader();
AbstractMetaDataContext child = new AbstractMetaDataContext(parent, childLoader);
MetaDatasItem item = child.retrieveMetaData();
assertTrue(item.getMetaDatas().length == 0);
assertTrue(item.getValue().length == 0);
assertTrue(item.isCachable());
assertTrue(item.isValid());
Object object1 = new Object();
parentLoader.addMetaData("Object", object1, Object.class);
MetaDataItem<?> metaDataItem1Parent = parentLoader.retrieveMetaData("Object");
MetaDataItem<?>[] expectedItems = { metaDataItem1Parent };
assertUnorderedArrayEquals(expectedItems, item.getMetaDatas());
Object[] expected = { object1 };
assertUnorderedArrayEquals(expected, item.getValue());
String object2 = "Hello";
childLoader.addMetaData("String", object2, String.class);
MetaDataItem<?> metaDataItem2Child = childLoader.retrieveMetaData("String");
expectedItems = new MetaDataItem[] { metaDataItem1Parent, metaDataItem2Child };
assertUnorderedArrayEquals(expectedItems, item.getMetaDatas());
expected = new Object[] { object1, object2 };
assertUnorderedArrayEquals(expected, item.getValue());
Object object1Child = new Object();
childLoader.addMetaData("Object", object1Child, Object.class);
MetaDataItem<?> metaDataItem1Child = childLoader.retrieveMetaData("Object");
expectedItems = new MetaDataItem[] { metaDataItem1Child, metaDataItem2Child };
assertUnorderedArrayEquals(expectedItems, item.getMetaDatas());
expected = new Object[] { object1Child, object2 };
assertUnorderedArrayEquals(expected, item.getValue());
childLoader.removeMetaData("Object", Object.class);
expectedItems = new MetaDataItem[] { metaDataItem1Parent, metaDataItem2Child };
assertUnorderedArrayEquals(expectedItems, item.getMetaDatas());
expected = new Object[] { object1, object2 };
assertUnorderedArrayEquals(expected, item.getValue());
parentLoader.removeMetaData("Object", Object.class);
expectedItems = new MetaDataItem[] { metaDataItem2Child };
assertUnorderedArrayEquals(expectedItems, item.getMetaDatas());
expected = new Object[] { object2 };
assertUnorderedArrayEquals(expected, item.getValue());
childLoader.removeMetaData("String", String.class);
assertTrue(item.getMetaDatas().length == 0);
assertTrue(item.getValue().length == 0);
}