@Test
  public void testCacheListeners() {
    RegionAttributes ra;
    CacheListener cl1 = new MyCacheListener();
    CacheListener cl2 = new MyCacheListener();
    assertFalse(cl1.equals(cl2));
    assertFalse((Arrays.asList(cl1, cl2))
        .equals(Arrays.asList(cl2, cl1)));

    AttributesFactory factory = new AttributesFactory();
    try {
      factory.addCacheListener(null);
      fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    try {
      factory.initCacheListeners(new CacheListener[] {null});
      fail("expected IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }

    ra = factory.create();
    assertEquals(null, ra.getCacheListener());
    assertEquals(Arrays.asList(), Arrays.asList(ra.getCacheListeners()));

    factory.setCacheListener(cl1);
    ra = factory.create();
    assertEquals(cl1, ra.getCacheListener());
    assertEquals(Arrays.asList(cl1), Arrays.asList(ra.getCacheListeners()));

    factory.setCacheListener(cl2);
    ra = factory.create();
    assertEquals(cl2, ra.getCacheListener());
    assertEquals(Arrays.asList(cl2), Arrays.asList(ra.getCacheListeners()));

    factory.setCacheListener(null);
    ra = factory.create();
    assertEquals(null, ra.getCacheListener());
    assertEquals(Arrays.asList(), Arrays.asList(ra.getCacheListeners()));

    factory.setCacheListener(cl1);
    factory.initCacheListeners(new CacheListener[] {cl1, cl2});
    ra = factory.create();
    try {
      ra.getCacheListener();
      fail("expected IllegalStateException");
    } catch (IllegalStateException expected) {
    }
    assertEquals(Arrays.asList(cl1, cl2),
        Arrays.asList(ra.getCacheListeners()));

    factory.initCacheListeners(null);
    ra = factory.create();
    assertEquals(Arrays.asList(), Arrays.asList(ra.getCacheListeners()));

    factory.initCacheListeners(new CacheListener[0]);
    ra = factory.create();
    assertEquals(Arrays.asList(), Arrays.asList(ra.getCacheListeners()));

    factory.addCacheListener(cl1);
    ra = factory.create();
    assertEquals(Arrays.asList(cl1), Arrays.asList(ra.getCacheListeners()));
    factory.addCacheListener(cl2);
    ra = factory.create();
    assertEquals(Arrays.asList(cl1, cl2),
        Arrays.asList(ra.getCacheListeners()));
    factory.initCacheListeners(new CacheListener[] {cl2});
    ra = factory.create();
    assertEquals(Arrays.asList(cl2), Arrays.asList(ra.getCacheListeners()));
  }
Tests the cacheListener functionality

@since GemFire 5.0
geode-core/src/test/java/org/apache/geode/cache/AttributesFactoryJUnitTest.java