private void verifyModifyAndSaveBothSidesOfCompareEditor(String extention) throws InterruptedException, InvocationTargetException, IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException, CoreException { // create files to compare IFile file1 = project.getFile("CompareFile1." + extention); IFile file2 = project.getFile("CompareFile2." + extention); file1.create(new ByteArrayInputStream(fileContents1.getBytes()), true, null); file2.create(new ByteArrayInputStream(fileContents2.getBytes()), true, null); // prepare comparison SaveablesCompareEditorInput input = new SaveablesCompareEditorInput( null, SaveablesCompareEditorInput.createFileElement(file1), SaveablesCompareEditorInput.createFileElement(file2), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()); input.run(null); // open CompareEditor CompareEditor editor = (CompareEditor) PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .openEditor(input, COMPARE_EDITOR, true); CompareViewerSwitchingPane pane = (CompareViewerSwitchingPane) ReflectionUtils.getField(input, "fContentInputPane", true); Viewer viewer = pane.getViewer(); MergeSourceViewer left = (MergeSourceViewer) ReflectionUtils.getField(viewer, "fLeft", true); MergeSourceViewer right = (MergeSourceViewer) ReflectionUtils.getField(viewer, "fRight", true); // modify both sides of CompareEditor StyledText leftText = left.getSourceViewer().getTextWidget(); StyledText rightText = right.getSourceViewer().getTextWidget(); leftText.append(appendFileContents); rightText.append(appendFileContents); // save both sides editor.doSave(null); assertFalse(editor.isDirty()); PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false); // validate if both sides where saved assertTrue( compareContent( new ByteArrayInputStream((fileContents1 + appendFileContents).getBytes()), file1.getContents())); assertTrue( compareContent( new ByteArrayInputStream((fileContents2 + appendFileContents).getBytes()), file2.getContents())); }
private ITypedElement getElementFor(IResource resource) { return SaveablesCompareEditorInput.createFileElement((IFile) resource); }