ManagementListener implements ResourceEventsListener { boolean shouldProceed(ResourceEvent event) { InternalDistributedSystem.getConnectedInstance(); if (!system.isConnected() && !event.equals(ResourceEvent.CACHE_REMOVE)) { return false; } InternalCache currentCache = system.getCache(); if (currentCache == null) { return false; } return !currentCache.isClosed(); } ManagementListener(InternalDistributedSystem system); @VisibleForTesting  ManagementListener(CancelCriterion cancelCriterion, InternalDistributedSystem system,
      ManagementAdapter adapter,
      ReadWriteLock readWriteLock); @Override void handleEvent(ResourceEvent event, Object resource);  }
@Test public void shouldProceedReturnsTrueIfSystemNotConnectedForCacheRemoveEvent() { when(system.isConnected()).thenReturn(false); assertThat(managementListener.shouldProceed(CACHE_REMOVE)).isTrue(); }
@Test public void shouldProceedReturnsFalseIfSystemNotConnectedForOtherEvents() { when(system.isConnected()).thenReturn(false); for (ResourceEvent resourceEvent : ResourceEvent.values()) { if (resourceEvent != CACHE_REMOVE) { assertThat(managementListener.shouldProceed(CACHE_REMOVE)).isTrue(); } } }
@Test public void shouldProceedReturnsTrueIfSystemIsConnected() { for (ResourceEvent resourceEvent : ResourceEvent.values()) { assertThat(managementListener.shouldProceed(resourceEvent)).isTrue(); } }
@Test public void shouldProceedReturnsFalseIfNoCache() { when(system.getCache()).thenReturn(null); for (ResourceEvent resourceEvent : ResourceEvent.values()) { assertThat(managementListener.shouldProceed(resourceEvent)).isFalse(); } }