AbstractMetaDataContext parent = new AbstractMetaDataContext(parentLoader);
MutableMetaDataLoader childLoader = createTestMutableMetaDataLoader();
AbstractMetaDataContext child = new AbstractMetaDataContext(parent, childLoader);
AnnotationsItem item = child.retrieveAnnotations();
assertTrue(item.getAnnotations().length == 0);
assertTrue(item.getValue().length == 0);
assertTrue(item.isCachable());
assertTrue(item.isValid());
TestAnnotation1Impl annotation1 = new TestAnnotation1Impl();
parentLoader.addAnnotation(annotation1);
AnnotationItem<? extends Annotation> annotationItem1Parent = parentLoader.retrieveAnnotation(TestAnnotation1.class);
@SuppressWarnings("unchecked")
AnnotationItem[] expectedItems = { annotationItem1Parent };
assertUnorderedArrayEquals(expectedItems, item.getAnnotations());
Annotation[] expected = { annotation1 };
assertUnorderedArrayEquals(expected, item.getValue());
TestAnnotation2Impl annotation2 = new TestAnnotation2Impl();
childLoader.addAnnotation(annotation2);
AnnotationItem<? extends Annotation> annotationItem2Child = childLoader.retrieveAnnotation(TestAnnotation2.class);
expectedItems = new AnnotationItem[] { annotationItem1Parent, annotationItem2Child };
assertUnorderedArrayEquals(expectedItems, item.getAnnotations());
expected = new Annotation[] { annotation1, annotation2 };
assertUnorderedArrayEquals(expected, item.getValue());
TestAnnotation1Impl annotation1Child = new TestAnnotation1Impl();
childLoader.addAnnotation(annotation1Child);
AnnotationItem<? extends Annotation> annotationItem1Child = childLoader.retrieveAnnotation(TestAnnotation1.class);
expectedItems = new AnnotationItem[] { annotationItem1Child, annotationItem2Child };
assertUnorderedArrayEquals(expectedItems, item.getAnnotations());
expected = new Annotation[] { annotation1Child, annotation2 };
assertUnorderedArrayEquals(expected, item.getValue());
childLoader.removeAnnotation(TestAnnotation1.class);
expectedItems = new AnnotationItem[] { annotationItem1Parent, annotationItem2Child };
assertUnorderedArrayEquals(expectedItems, item.getAnnotations());
expected = new Annotation[] { annotation1, annotation2 };
assertUnorderedArrayEquals(expected, item.getValue());
parentLoader.removeAnnotation(TestAnnotation1.class);
expectedItems = new AnnotationItem[] { annotationItem2Child };
assertUnorderedArrayEquals(expectedItems, item.getAnnotations());
expected = new Annotation[] { annotation2 };
assertUnorderedArrayEquals(expected, item.getValue());
childLoader.removeAnnotation(TestAnnotation2.class);
assertTrue(item.getAnnotations().length == 0);
assertTrue(item.getValue().length == 0);
}