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

    TestCacheLifecycleListener listener =
        new TestCacheLifecycleListener(cacheCreatedCallbacks, cacheClosedCallbacks);
    try {
      GemFireCacheImpl.addCacheLifecycleListener(listener);
      GemFireCacheImpl.removeCacheLifecycleListener(listener);

      // 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 {
        // assert no create callback
        assertTrue(cacheCreatedCallbacks.isEmpty());
        // assert no close callback
        assertTrue(cacheClosedCallbacks.isEmpty());
      } finally {
        cache.close();
      }

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