private IFile makeIFile(String path) { IPath ipath = new Path(path); IFile ifile = mock(IFile.class); when(ifile.getRawLocation()).thenReturn(ipath); when(ifile.toString()).thenReturn(path); when(ifile.getName()).thenReturn(path); return ifile; }
protected void fireActivity(TextEditActivity activity) { expectedActivities.add(activity); List<ITextOperation> textOps = activity.toOperation().getTextOperations(); IFile file = ((EclipseFileImpl) currentActiveEditor.getFile()).getDelegate(); FileEditorInput input = new FileEditorInput(file); IDocumentProvider provider = EditorManager.getDocumentProvider(input); try { provider.connect(input); } catch (CoreException e) { log.error("Could not connect to a document provider on file '" + file.toString() + "':", e); return; } try { IDocument doc = provider.getDocument(input); if (doc == null) { log.error( "Could not connect to a document provider on file '" + file.toString() + "':", new StackTrace()); return; } for (ITextOperation textOp : textOps) { try { if (textOp instanceof DeleteOperation) doc.replace(textOp.getPosition(), textOp.getTextLength(), ""); if (textOp instanceof InsertOperation) doc.replace(textOp.getPosition(), 0, textOp.getText()); } catch (BadLocationException e) { log.error("Invalid location for " + textOp); } } } finally { provider.disconnect(input); } }