Search in sources :

Example 11 with MockVirtualFile

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));
}
Also used : LightVirtualFile(com.intellij.testFramework.LightVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) Document(com.intellij.openapi.editor.Document)

Example 12 with MockVirtualFile

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());
}
Also used : MockVirtualFile(com.intellij.mock.MockVirtualFile) Disposable(com.intellij.openapi.Disposable) MockVirtualFile(com.intellij.mock.MockVirtualFile) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 13 with MockVirtualFile

use of com.intellij.mock.MockVirtualFile in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleFrameworkDetectorTest method createSuitableFilePattern_appYml_withInvalidContent_doesNotMatch.

@Test
public void createSuitableFilePattern_appYml_withInvalidContent_doesNotMatch() {
    MockVirtualFile invalidYamlFile = new MockVirtualFile("app.yml");
    FileContent invalidYamlFileContent = new FileContentImpl(invalidYamlFile, NOT_APP_ENGINE_FLEX_YAML_CONTENT, System.currentTimeMillis());
    assertThat(pattern.accepts(invalidYamlFileContent)).isFalse();
}
Also used : FileContent(com.intellij.util.indexing.FileContent) MockVirtualFile(com.intellij.mock.MockVirtualFile) FileContentImpl(com.intellij.util.indexing.FileContentImpl) Test(org.junit.Test)

Example 14 with MockVirtualFile

use of com.intellij.mock.MockVirtualFile in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleFrameworkDetectorTest method createSuitableFilePattern_appYaml_withInvalidContent_doesNotMatch.

@Test
public void createSuitableFilePattern_appYaml_withInvalidContent_doesNotMatch() {
    MockVirtualFile invalidYamlFile = new MockVirtualFile("app.yaml");
    FileContent invalidYamlFileContent = new FileContentImpl(invalidYamlFile, NOT_APP_ENGINE_FLEX_YAML_CONTENT, System.currentTimeMillis());
    assertThat(pattern.accepts(invalidYamlFileContent)).isFalse();
}
Also used : FileContent(com.intellij.util.indexing.FileContent) MockVirtualFile(com.intellij.mock.MockVirtualFile) FileContentImpl(com.intellij.util.indexing.FileContentImpl) Test(org.junit.Test)

Example 15 with MockVirtualFile

use of com.intellij.mock.MockVirtualFile in project intellij by bazelbuild.

the class BlazeRenderErrorContributorTest method createPsiClassesAndSourceToTargetMap.

private void createPsiClassesAndSourceToTargetMap(Container projectServices) {
    PsiManager psiManager = new MockPsiManager(project);
    VirtualFile independentLibraryView = new MockVirtualFile("src/com/google/example/independent/LibraryView.java");
    VirtualFile independentLibraryView2 = new MockVirtualFile("src/com/google/example/independent/LibraryView2.java");
    VirtualFile independentLibrary2View = new MockVirtualFile("src/com/google/example/independent/Library2View.java");
    VirtualFile dependentLibraryView = new MockVirtualFile("src/com/google/example/dependent/LibraryView.java");
    VirtualFile resourceView = new MockVirtualFile("src/com/google/example/ResourceView.java");
    ImmutableMap<String, PsiClass> classes = ImmutableMap.of("com.google.example.independent.LibraryView", mockPsiClass(independentLibraryView), "com.google.example.independent.LibraryView2", mockPsiClass(independentLibraryView2), "com.google.example.independent.Library2View", mockPsiClass(independentLibrary2View), "com.google.example.dependent.LibraryView", mockPsiClass(dependentLibraryView), "com.google.example.ResourceView", mockPsiClass(resourceView));
    ImmutableMap<File, TargetKey> sourceToTarget = ImmutableMap.of(VfsUtilCore.virtualToIoFile(independentLibraryView), TargetKey.forPlainTarget(Label.create("//com/google/example/independent:library")), VfsUtilCore.virtualToIoFile(independentLibraryView2), TargetKey.forPlainTarget(Label.create("//com/google/example/independent:library")), VfsUtilCore.virtualToIoFile(independentLibrary2View), TargetKey.forPlainTarget(Label.create("//com/google/example/independent:library2")), VfsUtilCore.virtualToIoFile(dependentLibraryView), TargetKey.forPlainTarget(Label.create("//com/google/example/dependent:library")), VfsUtilCore.virtualToIoFile(resourceView), TargetKey.forPlainTarget(Label.create("//com/google/example:resources")));
    projectServices.register(JavaPsiFacade.class, new MockJavaPsiFacade(project, psiManager, classes));
    projectServices.register(SourceToTargetMap.class, new MockSourceToTargetMap(sourceToTarget));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager) MockPsiManager(com.intellij.mock.MockPsiManager) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) MockPsiManager(com.intellij.mock.MockPsiManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) MockPsiFile(com.intellij.mock.MockPsiFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Aggregations

MockVirtualFile (com.intellij.mock.MockVirtualFile)15 Document (com.intellij.openapi.editor.Document)7 FileContent (com.intellij.util.indexing.FileContent)5 FileContentImpl (com.intellij.util.indexing.FileContentImpl)5 Test (org.junit.Test)5 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)4 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)1 MockPsiFile (com.intellij.mock.MockPsiFile)1 MockPsiManager (com.intellij.mock.MockPsiManager)1 MockVirtualLink (com.intellij.mock.MockVirtualLink)1 Disposable (com.intellij.openapi.Disposable)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)1 PsiClass (com.intellij.psi.PsiClass)1 PsiFile (com.intellij.psi.PsiFile)1 PsiManager (com.intellij.psi.PsiManager)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1