@Test
  public void testAddAfterCreate() throws Exception {
    List<CacheLifecycleCallback> cacheCreatedCallbacks = new ArrayList<>();
    List<CacheLifecycleCallback> cacheClosedCallbacks = new ArrayList<>();

    TestCacheLifecycleListener listener =
        new TestCacheLifecycleListener(cacheCreatedCallbacks, cacheClosedCallbacks);
    // assert no create callback
    assertTrue(cacheCreatedCallbacks.isEmpty());
    // assert no close callback
    assertTrue(cacheClosedCallbacks.isEmpty());

    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");

    InternalCache cache = (InternalCache) new CacheFactory(props).create();
    try {
      try {
        // assert no create callback
        assertTrue(cacheCreatedCallbacks.isEmpty());
        // assert no close callback
        assertTrue(cacheClosedCallbacks.isEmpty());

        GemFireCacheImpl.addCacheLifecycleListener(listener);
      } finally {
        cache.close();
      }

      // assert no create callback
      assertTrue(cacheCreatedCallbacks.isEmpty());
      // assert one close callback
      assertFalse(cacheClosedCallbacks.isEmpty());
      assertEquals(1, cacheClosedCallbacks.size());
      assertEquals(cache, cacheClosedCallbacks.get(0).getCache());
    } finally {
      GemFireCacheImpl.removeCacheLifecycleListener(listener);
    }
  }
Tests notifications of CacheLifecycleListener from GemFireCacheImpl.
geode-core/src/integrationTest/java/org/apache/geode/internal/cache/CacheLifecycleListenerJUnitTest.java