Source:
public void testDialectEditorCloserOnDRepresentationContainerAdditionUndo() { TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); CommandStack commandStack = domain.getCommandStack(); DAnalysis dAnalysis = new AirDResouceQuery((AirdResource) session.getSessionResource()).getDAnalysis().get(); URI designViewpointURI = URI.createURI("viewpoint:/org.eclipse.sirius.sample.ecore.design/Design"); Viewpoint viewpoint = ViewpointRegistry.getInstance().getViewpoint(designViewpointURI); viewpoint = (Viewpoint) session.getTransactionalEditingDomain().getResourceSet().getEObject(EcoreUtil.getURI(viewpoint), true); DRepresentationContainer dRepresentationContainer = ViewpointFactory.eINSTANCE.createDRepresentationContainer(); DTree dTree = TreeFactory.eINSTANCE.createDTree(); dTree.setTarget(target); dRepresentationContainer.getOwnedRepresentations().add(dTree); dRepresentationContainer.setViewpoint(viewpoint); Command cmd = AddCommand.create(domain, dAnalysis, ViewpointPackage.Literals.DANALYSIS__OWNED_VIEWS, dRepresentationContainer); commandStack.execute(cmd); IEditorPart openedEditor = DialectUIManager.INSTANCE.openEditor(session, dTree, new NullProgressMonitor()); assertTrue(openedEditor instanceof DialectEditor); DialectEditor dialectEditor = (DialectEditor) openedEditor; dialectEditor.setDialogFactory(new DummyDialectEditorDialogFactory()); TestsUtil.synchronizationWithUIThread(); commandStack.undo(); TestsUtil.synchronizationWithUIThread(); IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences(); assertEquals("The dialect editor should be closed by DialectEditorCloser since DRepresentation addition has been undone", 0, editorReferences.length); }

Target:
public void testDialectEditorCloserOnDRepresentationContainerAdditionUndo() { DAnalysis dAnalysis = new AirDResouceQuery((AirdResource) session.getSessionResource()).getDAnalysis().get(); URI designViewpointURI = URI.createURI("viewpoint:/org.eclipse.sirius.sample.ecore.design/Design"); Viewpoint viewpoint = ViewpointRegistry.getInstance().getViewpoint(designViewpointURI); viewpoint = (Viewpoint) domain.getResourceSet().getEObject(EcoreUtil.getURI(viewpoint), true); DRepresentationContainer dRepresentationContainer = ViewpointFactory.eINSTANCE.createDRepresentationContainer(); DTree dTree = TreeFactory.eINSTANCE.createDTree(); dTree.setTarget(target); dRepresentationContainer.getOwnedRepresentations().add(dTree); dRepresentationContainer.setViewpoint(viewpoint); Command cmd = AddCommand.create(domain, dAnalysis, ViewpointPackage.Literals.DANALYSIS__OWNED_VIEWS, dRepresentationContainer); commandStack.execute(cmd); IEditorPart openedEditor = DialectUIManager.INSTANCE.openEditor(session, dTree, new NullProgressMonitor()); assertTrue(openedEditor instanceof DialectEditor); DialectEditor dialectEditor = (DialectEditor) openedEditor; dialectEditor.setDialogFactory(new DummyDialectEditorDialogFactory()); TestsUtil.synchronizationWithUIThread(); commandStack.undo(); TestsUtil.synchronizationWithUIThread(); IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences(); assertEquals("The dialect editor should be closed by DialectEditorCloser since DRepresentation addition has been undone", 0, editorReferences.length); }