@Test
public void testAddContextListener() {

    System.out.println("addContextListener");
    TestContextListener<Foo> fooContextListener = new TestContextListener<>();
    context.addContextListener(Foo.class, fooContextListener);
    TestContextListener<MyCustomFoo> myCustomFooContextListener = new TestContextListener<>();
    TestContextListener<AbstractFoo> abstractFooContextListener = new TestContextListener<>();
    TestContextListener<Object> objectContextListener = new TestContextListener<>();
    TestContextListener<Date> dateContextListener = new TestContextListener<>();
    SimpleContextContent content1 = new SimpleContextContent();
    SimpleContext context1 = new SimpleContext(content1);
    context.addContext(context1);
    context.addContextListener(MyCustomFoo.class, myCustomFooContextListener);
    context.addContextListener(AbstractFoo.class, abstractFooContextListener);
    context.addContextListener(Object.class, objectContextListener);
    context.addContextListener(Date.class, dateContextListener);
    assertFalse(fooContextListener.isContextChanged());
    assertFalse(myCustomFooContextListener.isContextChanged());
    assertFalse(abstractFooContextListener.isContextChanged());
    assertFalse(objectContextListener.isContextChanged());
    assertFalse(dateContextListener.isContextChanged());
    Foo foo1 = new MyCustomFoo();
    content1.add(foo1);
    assertTrue(fooContextListener.isContextChanged());
    assertTrue(myCustomFooContextListener.isContextChanged());
    assertTrue(abstractFooContextListener.isContextChanged());
    assertTrue(objectContextListener.isContextChanged());
    assertFalse(dateContextListener.isContextChanged());
    fooContextListener.reset();
    myCustomFooContextListener.reset();
    abstractFooContextListener.reset();
    objectContextListener.reset();
    assertFalse(fooContextListener.isContextChanged());
    assertFalse(myCustomFooContextListener.isContextChanged());
    assertFalse(abstractFooContextListener.isContextChanged());
    assertFalse(objectContextListener.isContextChanged());
    assertFalse(dateContextListener.isContextChanged());
    context.removeContext(context1);
    assertTrue(fooContextListener.isContextChanged());
    assertTrue(myCustomFooContextListener.isContextChanged());
    assertTrue(abstractFooContextListener.isContextChanged());
    assertTrue(objectContextListener.isContextChanged());
    assertFalse(dateContextListener.isContextChanged());
    fooContextListener.reset();
    myCustomFooContextListener.reset();
    abstractFooContextListener.reset();
    objectContextListener.reset();
    assertFalse(fooContextListener.isContextChanged());
    assertFalse(myCustomFooContextListener.isContextChanged());
    assertFalse(abstractFooContextListener.isContextChanged());
    assertFalse(objectContextListener.isContextChanged());
    assertFalse(dateContextListener.isContextChanged());
    context.addContext(context1);
    assertTrue(fooContextListener.isContextChanged());
    assertTrue(myCustomFooContextListener.isContextChanged());
    assertTrue(abstractFooContextListener.isContextChanged());
    assertTrue(objectContextListener.isContextChanged());
    assertFalse(dateContextListener.isContextChanged());
    fooContextListener.reset();
    myCustomFooContextListener.reset();
    abstractFooContextListener.reset();
    objectContextListener.reset();
    assertFalse(fooContextListener.isContextChanged());
    assertFalse(myCustomFooContextListener.isContextChanged());
    assertFalse(abstractFooContextListener.isContextChanged());
    assertFalse(objectContextListener.isContextChanged());
    assertFalse(dateContextListener.isContextChanged());
    content1.remove(foo1);
    assertTrue(fooContextListener.isContextChanged());
    assertTrue(myCustomFooContextListener.isContextChanged());
    assertTrue(abstractFooContextListener.isContextChanged());
    assertTrue(objectContextListener.isContextChanged());
    assertFalse(dateContextListener.isContextChanged());
}