use of com.intellij.mock.MockVirtualFile in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testContentChanged_ignoreEventsFromSelfOnSave.
public void testContentChanged_ignoreEventsFromSelfOnSave() throws Exception {
final VirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
@NotNull
@Override
public OutputStream getOutputStream(final Object requestor, final long newModificationStamp, long newTimeStamp) throws IOException {
final VirtualFile self = this;
return new ByteArrayOutputStream() {
@Override
public void close() throws IOException {
super.close();
long oldStamp = getModificationStamp();
setModificationStamp(newModificationStamp);
setText(toString());
myDocumentManager.contentsChanged(new VirtualFileEvent(requestor, self, null, oldStamp, getModificationStamp()));
}
};
}
};
final Document document = myDocumentManager.getDocument(file);
assertNotNull(file.toString(), document);
WriteCommandAction.runWriteCommandAction(myProject, () -> document.insertString(0, "xxx"));
final long stamp = document.getModificationStamp();
myDocumentManager.saveAllDocuments();
assertEquals(stamp, document.getModificationStamp());
}
use of com.intellij.mock.MockVirtualFile in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testGetUnsavedDocuments_afterSaveDocumentWithProblems.
public void testGetUnsavedDocuments_afterSaveDocumentWithProblems() throws Exception {
try {
final VirtualFile file = new MockVirtualFile("test.txt", "test") {
@Override
@NotNull
public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException {
throw new IOException("");
}
};
final Document document = myDocumentManager.getDocument(file);
assertNotNull(file.toString(), document);
WriteCommandAction.runWriteCommandAction(getProject(), () -> document.insertString(0, "xxx"));
try {
myDocumentManager.saveDocument(document);
fail("must throw IOException");
} catch (RuntimeException e) {
assertTrue(e.getCause() instanceof IOException);
}
final Document[] unsavedDocuments = myDocumentManager.getUnsavedDocuments();
assertEquals(1, unsavedDocuments.length);
assertSame(document, unsavedDocuments[0]);
assertEquals("test", new String(file.contentsToByteArray(), CharsetToolkit.UTF8_CHARSET));
} finally {
ApplicationManager.getApplication().runWriteAction(() -> myDocumentManager.dropAllUnsavedDocuments());
}
}
use of com.intellij.mock.MockVirtualFile in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testRememberSeparators.
public void testRememberSeparators() throws Exception {
final VirtualFile file = new MockVirtualFile("test.txt", "test\rtest");
final Document document = myDocumentManager.getDocument(file);
assertNotNull(file.toString(), document);
WriteCommandAction.runWriteCommandAction(myProject, () -> document.insertString(0, "xxx "));
myDocumentManager.saveAllDocuments();
assertEquals("xxx test\rtest", new String(file.contentsToByteArray(), CharsetToolkit.UTF8_CHARSET));
}
use of com.intellij.mock.MockVirtualFile in project intellij-community by JetBrains.
the class VirtualFilePointerTest method testAlienVirtualFileSystemPointerRemovedFromUrlToIdentityCacheOnDispose.
public void testAlienVirtualFileSystemPointerRemovedFromUrlToIdentityCacheOnDispose() throws IOException {
VirtualFile mockVirtualFile = new MockVirtualFile("test_name", "test_text");
Disposable disposable1 = Disposer.newDisposable();
final VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(mockVirtualFile, disposable1, null);
assertInstanceOf(pointer, IdentityVirtualFilePointer.class);
assertTrue(pointer.isValid());
VirtualFile virtualFileWithSameUrl = new MockVirtualFile("test_name", "test_text");
VirtualFilePointer updatedPointer = VirtualFilePointerManager.getInstance().create(virtualFileWithSameUrl, disposable1, null);
assertInstanceOf(updatedPointer, IdentityVirtualFilePointer.class);
assertEquals(1, ((VirtualFilePointerManagerImpl) VirtualFilePointerManager.getInstance()).numberOfCachedUrlToIdentity());
Disposer.dispose(disposable1);
assertEquals(0, ((VirtualFilePointerManagerImpl) VirtualFilePointerManager.getInstance()).numberOfCachedUrlToIdentity());
}
Aggregations