DockableDataModifiedManager implements AutoCloseable { @Override public void close() { dockingAreaContainer.removeDockableSetChangeListener(dockablesListener); for (Iterator<Map.Entry<D, ContextListener<Savable>>> iterator = savableListeners.entrySet().iterator(); iterator.hasNext();) { Map.Entry<D, ContextListener<Savable>> entry = iterator.next(); removeContextListener(entry.getKey(), entry.getValue()); iterator.remove(); } } DockableDataModifiedManager(DockingAreaContainer<D, DATA, E> dockingAreaContainer); @Override void close();  }
@Test public void testClose() { doAnswer((Answer<Void>) (InvocationOnMock invocation) -> { Object[] args = invocation.getArguments(); listener = (SetChangeListener<DockableEntry<Object, DockableData>>) args[0]; return null; }).when(dockingAreaContainer).addDockableSetChangeListener(any()); try (DockableDataModifiedManager testee = new DockableDataModifiedManager(dockingAreaContainer)) { listener.elementAdded(new SetChangeEvent<>(dockables, dockableEntry)); assertFalse(dockableData.isModified()); testDockable.modify(); assertTrue(dockableData.isModified()); testDockable.save(); assertFalse(dockableData.isModified()); } verify(dockingAreaContainer).removeDockableSetChangeListener(listener); assertFalse(dockableData.isModified()); testDockable.modify(); assertFalse(dockableData.isModified()); testDockable.save(); assertFalse(dockableData.isModified()); }