AnalysesModel implements TreeModel { public void replace(ModelType type, MCMCPresentation oldPresentation, MCMCPresentation newPresentation) { d_nodes.get(type).remove(oldPresentation); d_nodes.get(type).add(newPresentation); fireNodeReplaced(type, oldPresentation, newPresentation); }  void add(ModelType type, MCMCPresentation model); void replace(ModelType type, MCMCPresentation oldPresentation, MCMCPresentation newPresentation); void clear(); @Override Object getRoot(); @Override Object getChild(Object parent, int index); @Override int getChildCount(Object parent); @Override boolean isLeaf(Object node); @Override int getIndexOfChild(Object parent, Object child); @Override void valueForPathChanged(TreePath path, Object newValue); @Override void addTreeModelListener(TreeModelListener l); @Override void removeTreeModelListener(TreeModelListener l); SortedSet<MCMCPresentation> getModels(ModelType type);  }
@Test public void testReplace() { final AnalysesModel model = new AnalysesModel(); final MCMCPresentation inco1 = new MCMCPresentation(d_wrapper, "inco1"); final MCMCPresentation inco2 = new MCMCPresentation(d_wrapper, "inco2"); model.add(ModelType.Inconsistency, inco1); JUnitUtil.assertAllAndOnly(model.getModels(ModelType.Inconsistency), Collections.singleton(inco1)); TreeModelListener listener = EasyMock.createStrictMock(TreeModelListener.class); TreeModelEvent event1a = new TreeModelEvent(model, new Object[] { model.getRoot(), ModelType.Inconsistency }, new int[] { 0 }, new Object[] { inco2 }); listener.treeNodesChanged(TreeModelEventMatcher.eqTreeModelEvent(event1a)); EasyMock.replay(listener); model.addTreeModelListener(listener); model.replace(ModelType.Inconsistency, inco1, inco2); EasyMock.verify(listener); JUnitUtil.assertAllAndOnly(model.getModels(ModelType.Inconsistency), Collections.singleton(inco2)); }