com.intellij.mock.MockVirtualFile Java Examples

The following examples show how to use com.intellij.mock.MockVirtualFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SlingResource4IntelliJTest.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasics() {
    SlingProject slingProject = new SlingProject4IntelliJ(module);
    VirtualFile virtualFile = new MockVirtualFile("test");
    SlingResource slingResource = new SlingResource4IntelliJ(slingProject, virtualFile);

    assertThat("Sling Resource Name is wrong", slingResource.getName(), equalTo("test"));
    assertThat("Sling Resource Project is undefined", slingResource.getProject(), notNullValue());
    assertThat("No Modification Stored expected", Util.getModificationStamp(virtualFile), equalTo(-1L));
    assertThat("Resource isn't marked as changed", slingResource.isModified(), is(Boolean.TRUE));
    assertThat("Resource isn't a file", slingResource.isFile(), is(Boolean.TRUE));
    assertThat("Resource is a folder but should be file", slingResource.isFolder(), is(Boolean.FALSE));
    LOGGER.info("Resource Path: '{}'", slingResource.getLocalPath());
    LOGGER.info("Sync Directory: '{}'", slingProject.getSyncDirectory());
    SlingResource slingResourceChild = new SlingResource4IntelliJ(slingProject, "/a/b/c.txt");
    assertThat("Obtained Resource doesn't match", slingResource.getResourceFromPath("/a/b/c.txt"), equalTo(slingResourceChild));
    //AS TODO: Test Load Filter (should be the same as for Sling Project
    SlingResource slingResourceEqual = new SlingResource4IntelliJ(slingProject, virtualFile);
    assertThat("Sling Resource must be equal even if not identical", slingResource, equalTo(slingResourceEqual));
}
 
Example #2
Source File: FileDocumentManagerImplTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
public void _testContentChanged_reloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VFileContentChangeEvent(null, this, oldStamp, getModificationStamp(), true));
    }
  };
  Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  document.insertString(0, "zzz");
  file.setContent(null, "xxx", false);

  myReloadFromDisk = Boolean.TRUE;
  myDocumentManager.saveAllDocuments();
  long fileStamp = file.getModificationStamp();

  assertEquals("xxx", document.getText());
  assertEquals(file.getModificationStamp(), document.getModificationStamp());
  assertEquals(file.getModificationStamp(), fileStamp);
  assertEquals(0, myDocumentManager.getUnsavedDocuments().length);
}
 
Example #3
Source File: BlazeAndroidModelTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
MockJavaPsiFacade(Project project, ImmutableCollection<String> classNames) {
  super(project);
  ImmutableMap.Builder<String, PsiClass> classesBuilder = ImmutableMap.builder();
  ImmutableMap.Builder<String, Long> timestampsBuilder = ImmutableMap.builder();
  for (String className : classNames) {
    VirtualFile virtualFile =
        new MockVirtualFile("/src/" + className.replace('.', '/') + ".java");
    PsiFile psiFile = mock(PsiFile.class);
    when(psiFile.getVirtualFile()).thenReturn(virtualFile);
    PsiClass psiClass = mock(PsiClass.class);
    when(psiClass.getContainingFile()).thenReturn(psiFile);
    classesBuilder.put(className, psiClass);
    timestampsBuilder.put(className, virtualFile.getTimeStamp());
  }
  classes = classesBuilder.build();
  timestamps = timestampsBuilder.build();
}
 
Example #4
Source File: ORProjectManagerTest.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Test
public void testFindBsConfigurationFiles_sortedByFileDepth() {
    String mockFileName = BsConstants.BS_CONFIG_FILENAME;
    MockVirtualFile mockBsConfigFileParent = new MockVirtualFile(mockFileName);
    MockVirtualFile mockBsConfigFile = new MockVirtualFile(mockFileName);
    MockVirtualFile mockBsConfigFileChild = new MockVirtualFile(mockFileName);
    // set up mock file hierarchy
    mockBsConfigFile.setParent(mockBsConfigFileParent);
    mockBsConfigFileChild.setParent(mockBsConfigFile);

    MockVirtualFile[] mocksUnsorted = { mockBsConfigFile, mockBsConfigFileChild, mockBsConfigFileParent };
    MockVirtualFile[] mocksSorted = { mockBsConfigFileParent, mockBsConfigFile, mockBsConfigFileChild };

    when(FilenameIndex.getVirtualFilesByName(mockProject, mockFileName, mockScope))
            .thenReturn(Arrays.asList(mocksUnsorted));

    LinkedHashSet<VirtualFile> bsConfigurationFiles = ORProjectManager.findBsConfigurationFiles(mockProject);
    assertMocksSorted(bsConfigurationFiles, mocksSorted);
}
 
Example #5
Source File: ORProjectManagerTest.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Test
public void testFindDuneConfigurationFiles_sortedByFileType() {
    MockVirtualFile mockDuneFile = new MockVirtualFile(DuneConstants.DUNE_FILENAME);
    MockVirtualFile mockDuneProjectFile = new MockVirtualFile(DuneConstants.DUNE_PROJECT_FILENAME);
    MockVirtualFile mockJBuilderFile = new MockVirtualFile(DuneConstants.LEGACY_JBUILDER_FILENAME);

    MockVirtualFile[] mocksUnsorted = { mockJBuilderFile, mockDuneFile, mockDuneProjectFile };
    MockVirtualFile[] mocksSorted = { mockDuneProjectFile, mockDuneFile, mockJBuilderFile };

    // test prioritizing of dune file types by registering mocks to be returned out of order
    for (MockVirtualFile mockFile : mocksUnsorted) {
        registerMockFile(mockFile);
    }

    LinkedHashSet<VirtualFile> duneConfigurationFiles = ORProjectManager.findDuneConfigurationFiles(mockProject);
    assertMocksSorted(duneConfigurationFiles, mocksSorted);
}
 
Example #6
Source File: ORProjectManagerTest.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Test
public void testFindDuneConfigurationFiles_sortedByFileDepth() {
    String mockFileName = DuneConstants.DUNE_FILENAME;
    MockVirtualFile mockDuneFileParent = new MockVirtualFile(mockFileName);
    MockVirtualFile mockDuneFile = new MockVirtualFile(mockFileName);
    MockVirtualFile mockDuneFileChild = new MockVirtualFile(mockFileName);
    // set up mock file hierarchy
    mockDuneFile.setParent(mockDuneFileParent);
    mockDuneFileChild.setParent(mockDuneFile);

    MockVirtualFile[] mocksUnsorted = { mockDuneFile, mockDuneFileChild, mockDuneFileParent };
    MockVirtualFile[] mocksSorted = { mockDuneFileParent, mockDuneFile, mockDuneFileChild };

    when(FilenameIndex.getVirtualFilesByName(mockProject, mockFileName, mockScope))
            .thenReturn(Arrays.asList(mocksUnsorted));

    LinkedHashSet<VirtualFile> duneConfigurationFiles = ORProjectManager.findDuneConfigurationFiles(mockProject);
    assertMocksSorted(duneConfigurationFiles, mocksSorted);
}
 
Example #7
Source File: ORProjectManagerTest.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@Test
public void testFindEsyConfigurationFiles_sortedByFileDepth() {
    String mockFileName = EsyConstants.ESY_CONFIG_FILENAME;
    MockVirtualFile mockEsyConfigFileParent = new MockVirtualFile(mockFileName);
    MockVirtualFile mockEsyConfigFile = new MockVirtualFile(mockFileName);
    MockVirtualFile mockEsyConfigFileChild = new MockVirtualFile(mockFileName);
    // set up mock file hierarchy
    mockEsyConfigFile.setParent(mockEsyConfigFileParent);
    mockEsyConfigFileChild.setParent(mockEsyConfigFile);

    MockVirtualFile[] mocksUnsorted = { mockEsyConfigFile, mockEsyConfigFileChild, mockEsyConfigFileParent };
    MockVirtualFile[] mocksSorted = { mockEsyConfigFileParent, mockEsyConfigFile, mockEsyConfigFileChild };

    when(FilenameIndex.getVirtualFilesByName(mockProject, mockFileName, mockScope))
            .thenReturn(Arrays.asList(mocksUnsorted));

    when(EsyPackageJson.isEsyPackageJson(any())).thenReturn(true);

    LinkedHashSet<VirtualFile> esyConfigurationFiles = ORProjectManager.findEsyConfigurationFiles(mockProject);
    assertMocksSorted(esyConfigurationFiles, mocksSorted);
}
 
Example #8
Source File: VirtualFileRepoCacheImplTest.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Test
void getRepoForDirShouldReturnSameRepositoryForDirInRootIfCalledMoreThanOnce() {
  setupRepo();

  MockVirtualFile dirInRoot = createDir(repositoryRoot, "dirInRoot");
  GitRepository repo1 = cache.getRepoForDir(dirInRoot);
  GitRepository repo2 = cache.getRepoForDir(dirInRoot);
  assertThat(repo1).isEqualTo(repo2);
}
 
Example #9
Source File: VirtualFileVisitorTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void link(@NonNls @Nonnull String targetPath, @Nonnull @NonNls String linkPath) {
  final VirtualFile target = myRoot.findFileByRelativePath(targetPath);
  assertNotNull(targetPath, target);
  final int pos = linkPath.lastIndexOf('/');
  final VirtualFile linkParent = myRoot.findFileByRelativePath(linkPath.substring(0, pos));
  assertNotNull(linkPath, linkParent);
  ((MockVirtualFile)linkParent).addChild(new MockVirtualLink(linkPath.substring(pos + 1), target));
}
 
Example #10
Source File: VirtualFileRepoCacheImplTest.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Test
void getRepoForDirShouldReturnRepositoryForDirInDirInRootBottomUp() {
  setupRepo();

  MockVirtualFile dirInRoot = createDir(repositoryRoot, "dirInRoot");
  MockVirtualFile dirInDirInRoot = createDir(dirInRoot, "dirInDirInRoot");
  assertThat(cache.getRepoForDir(dirInDirInRoot)).isEqualTo(repositoryMock);
}
 
Example #11
Source File: VirtualFileRepoCacheImplTest.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Test
void getRepoForDirShouldReturnRepositoryForDirInDirInRootTopDown() {
  setupRepo();

  MockVirtualFile dirInRoot = createDir(repositoryRoot, "dirInRoot");
  MockVirtualFile dirInDirInRoot = createDir(dirInRoot, "dirInDirInRoot");
  assertSoftly(softly -> {
    softly.assertThat(cache.getRepoForDir(dirInRoot))
        .isEqualTo(repositoryMock);
    softly.assertThat(cache.getRepoForDir(dirInDirInRoot))
        .isEqualTo(repositoryMock);
  });

}
 
Example #12
Source File: VirtualFileRepoCacheImplTest.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Test
void isUnderGitRootShouldReturnTrueForDirUnderRoot() {
  setupRepo();

  MockVirtualFile dirInRoot = createDir(repositoryRoot, "dirInRoot");
  assertSoftly(softly -> {
    softly.assertThat(cache.isUnderGitRoot(dirInRoot))
        .isTrue();
  });
}
 
Example #13
Source File: VirtualFileRepoCacheImplTest.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Test
void isUnderGitRootShouldReturnFalseForDirNotUnderRoot() {
  setupRepo();

  MockVirtualFile dirInRoot = createDir("dirInRoot");
  assertSoftly(softly -> {
    softly.assertThat(cache.isUnderGitRoot(dirInRoot))
        .isFalse();
  });
}
 
Example #14
Source File: VirtualFileRepoCacheImplTest.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Test
void isUnderGitRootShouldReturnTrueForFileUnderRoot() {
  setupRepo();

  MockVirtualFile fileInRoot = createFile(repositoryRoot, "fileInRoot.txt");
  assertSoftly(softly -> {
    softly.assertThat(cache.isUnderGitRoot(fileInRoot))
        .isTrue();
  });
}
 
Example #15
Source File: VirtualFileRepoCacheImplTest.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Test
void isUnderGitRootShouldReturnFalseForFileNotUnderRoot() {
  setupRepo();

  MockVirtualFile fileInRoot = createFile("fileInRoot.txt");
  assertSoftly(softly -> {
    softly.assertThat(cache.isUnderGitRoot(fileInRoot))
        .isFalse();
  });
}
 
Example #16
Source File: FileDocumentManagerImplTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testGetUnsavedDocuments_afterSaveDocumentWithProblems() throws Exception {
  try {
    final VirtualFile file = new MockVirtualFile("test.txt", "test") {
      @Override
      @Nonnull
      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(), new Runnable() {
      @Override
      public void run() {
        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]);
    assertTrue(Arrays.equals("test".getBytes("UTF-8"), file.contentsToByteArray()));
  }
  finally {
    myDocumentManager.dropAllUnsavedDocuments();
  }
}
 
Example #17
Source File: FileDocumentManagerImplTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
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, new Runnable() {
    @Override
    public void run() {
      document.insertString(0, "xxx ");
    }
  });

  myDocumentManager.saveAllDocuments();
  assertTrue(Arrays.equals("xxx test\rtest".getBytes("UTF-8"), file.contentsToByteArray()));
}
 
Example #18
Source File: FileDocumentManagerImplTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testContentChanged_ignoreEventsFromSelfOnSave() throws Exception {
  final VirtualFile file = new MockVirtualFile("test.txt", "test\rtest") {
    @Nonnull
    @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 VFileContentChangeEvent(requestor, self, oldStamp, getModificationStamp(), false));
        }
      };
    }
  };
  final Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
    @Override
    public void run() {
      document.insertString(0, "xxx");
    }
  });

  final long stamp = document.getModificationStamp();

  myDocumentManager.saveAllDocuments();
  assertEquals(stamp, document.getModificationStamp());
}
 
Example #19
Source File: FileDocumentManagerImplTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testContentChanged_doNotReloadChangedDocumentOnSave() throws Exception {
  final MockVirtualFile file = new MockVirtualFile("test.txt", "test") {
    @Override
    public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
      long oldStamp = getModificationStamp();
      setModificationStamp(LocalTimeCounter.currentTime());
      myDocumentManager.contentsChanged(new VFileContentChangeEvent(null, this, oldStamp, getModificationStamp(), true));
    }
  };

  myReloadFromDisk = Boolean.FALSE;
  final Document document = myDocumentManager.getDocument(file);
  assertNotNull(file.toString(), document);
  WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
    @Override
    public void run() {
      document.insertString(0, "old ");
    }
  });

  long documentStamp = document.getModificationStamp();

  file.setContent(null, "xxx", false);

  myDocumentManager.saveAllDocuments();

  assertEquals("old test", document.getText());
  assertEquals(file.getModificationStamp(), document.getModificationStamp());
  assertTrue(Arrays.equals("old test".getBytes("UTF-8"), file.contentsToByteArray()));
  assertEquals(documentStamp, document.getModificationStamp());
}
 
Example #20
Source File: VirtualFileVisitorTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static MockVirtualFile dir(@NonNls @Nonnull String name, MockVirtualFile... children) {
  final MockVirtualFile root = new MockVirtualFile(true, name);
  for (MockVirtualFile child : children) {
    root.addChild(child);
  }
  return root;
}
 
Example #21
Source File: SlingResource4IntelliJTest.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    String artifactId = "myArtifact";
    String groupId = "myGroupId";
    ServerConfiguration serverConfiguration = new ServerConfiguration();
    module = new ServerConfiguration.Module( serverConfiguration, groupId + "." + artifactId, true, 0 );
    VirtualFile syncFolder = new MockVirtualFile(true, "baseDir");
    Project mockProject = new MockProject()
        .setBaseDir(syncFolder);
    UnifiedModule mockUnifiedModule = new MockUnifiedModule()
        .setSymbolicName(groupId + "." + artifactId)
        .setContentDirectoryPaths(Arrays.asList("/baseDir/" + JCR_ROOT_FOLDER_NAME));
    module.rebind(mockProject, mockUnifiedModule);
}
 
Example #22
Source File: VirtualFileRepoCacheImplTest.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@Test
void getRepoForDirShouldReturnRepositoryForDirInRoot() {
  setupRepo();

  MockVirtualFile dirInRoot = createDir(repositoryRoot, "dirInRoot");
  assertThat(cache.getRepoForDir(dirInRoot)).isEqualTo(repositoryMock);
}
 
Example #23
Source File: BsPlatformTest.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Test
public void testFindBsPlatformDirectory() {
    MockVirtualFile mockBsConfigFile = MockVirtualFile.file(BS_CONFIG_FILENAME);
    MockVirtualFile mockBsPlatformDirectory = MockVirtualFile.dir(BS_PLATFORM_DIRECTORY_NAME);
    MockVirtualFile mockNodeModulesDirectory = MockVirtualFile.dir("node_modules", mockBsPlatformDirectory);
    MockVirtualFile mockSourceFile = MockVirtualFile.dir(MOCK_ROOT, mockBsConfigFile, mockNodeModulesDirectory);
    Optional<VirtualFile> bsPlatformDirectory = BsPlatform.findBsPlatformDirectory(mockProject, mockSourceFile);
    assertTrue(bsPlatformDirectory.isPresent());
    assertEquals(mockBsPlatformDirectory, bsPlatformDirectory.get());
}
 
Example #24
Source File: ORProjectManagerTest.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Test
public void testIsDuneProject_allDuneFileTypes() {
    MockVirtualFile mockDuneFile = new MockVirtualFile(DuneConstants.DUNE_FILENAME);
    MockVirtualFile mockDuneProjectFile = new MockVirtualFile(DuneConstants.DUNE_PROJECT_FILENAME);
    MockVirtualFile mockJBuilderFile = new MockVirtualFile(DuneConstants.LEGACY_JBUILDER_FILENAME);
    registerMockFile(mockDuneFile);
    assertTrue(ORProjectManager.isDuneProject(mockProject));
    registerMockFile(mockDuneProjectFile);
    assertTrue(ORProjectManager.isDuneProject(mockProject));
    registerMockFile(mockJBuilderFile);
    assertTrue(ORProjectManager.isDuneProject(mockProject));
}
 
Example #25
Source File: ORProjectManagerTest.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Test
public void testIsEsyProject() {
    MockVirtualFile mockEsyConfig = new MockVirtualFile(EsyPackageJsonFileType.getDefaultFilename());
    registerMockFile(mockEsyConfig);

    OngoingStubbing<Boolean> whenIsEsyPackageJson = when(EsyPackageJson.isEsyPackageJson(mockEsyConfig));

    whenIsEsyPackageJson.thenReturn(false);
    assertFalse("File not recognized as esy package.json.", ORProjectManager.isEsyProject(mockProject));

    whenIsEsyPackageJson.thenReturn(true);
    assertTrue(ORProjectManager.isEsyProject(mockProject));
}
 
Example #26
Source File: BsPlatformTest.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Test
public void testFindBsbExecutable_platformSpecificBinary() {
    MockVirtualFile mockBsConfigFile = MockVirtualFile.file(BS_CONFIG_FILENAME);
    MockVirtualFile mockBsbExecutable = MockVirtualFile.file(BSB_EXECUTABLE_NAME + ".exe");
    MockVirtualFile mockPlatformDirectory = MockVirtualFile.dir(getOsBsPrefix(), mockBsbExecutable);
    MockVirtualFile mockBsPlatformDirectory = MockVirtualFile.dir(BS_PLATFORM_DIRECTORY_NAME, mockPlatformDirectory);
    MockVirtualFile mockNodeModulesDirectory = MockVirtualFile.dir("node_modules", mockBsPlatformDirectory);
    MockVirtualFile mockSourceFile = MockVirtualFile.dir(MOCK_ROOT, mockBsConfigFile, mockNodeModulesDirectory);
    Optional<VirtualFile> bsbExecutable = BsPlatform.findBsbExecutable(mockProject, mockSourceFile);
    assertTrue(bsbExecutable.isPresent());
    assertEquals(mockBsbExecutable, bsbExecutable.get());
}
 
Example #27
Source File: BsPlatformTest.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Test
public void testFindBsbExecutable_platformAgnosticWrapper() {
    String bsbWrapperFilename = BSB_EXECUTABLE_NAME + BsPlatform.getOsBinaryWrapperExtension();
    MockVirtualFile mockBsConfigFile = MockVirtualFile.file(BS_CONFIG_FILENAME);
    MockVirtualFile mockBsbExecutableWrapper = MockVirtualFile.file(bsbWrapperFilename);
    MockVirtualFile mockBsPlatformDirectory = MockVirtualFile.dir(BS_PLATFORM_DIRECTORY_NAME, mockBsbExecutableWrapper);
    MockVirtualFile mockNodeModulesDirectory = MockVirtualFile.dir("node_modules", mockBsPlatformDirectory);
    MockVirtualFile mockSourceFile = MockVirtualFile.dir(MOCK_ROOT, mockBsConfigFile, mockNodeModulesDirectory);
    Optional<VirtualFile> bsbExecutableWrapper = BsPlatform.findBsbExecutable(mockProject, mockSourceFile);
    assertTrue(bsbExecutableWrapper.isPresent());
    assertEquals(mockBsbExecutableWrapper, bsbExecutableWrapper.get());
}
 
Example #28
Source File: EsyPackageJsonTest.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
public void testIsEsyPackageJson() throws IOException {
    String packageJsonFilename = EsyPackageJsonFileType.getDefaultFilename();
    String mockJson = loadJson(packageJsonFilename);
    MockVirtualFile mockVirtualFile = MockVirtualFile.file(packageJsonFilename);
    mockVirtualFile.setText(mockJson);
    assertTrue(EsyPackageJson.isEsyPackageJson(mockVirtualFile));
    mockVirtualFile.setText("{}");
    assertFalse(EsyPackageJson.isEsyPackageJson(mockVirtualFile));
}
 
Example #29
Source File: ORFileUtilsTest.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@Test
public void testFindAncestorRecursive_targetFound() {
    VirtualFile mockTarget = new MockVirtualFile("mock-target");
    String targetName = mockTarget.getName();
    VirtualFile mockStart = spy(VirtualFile.class);
    when(mockStart.isDirectory()).thenReturn(true);
    when(mockStart.findChild(targetName)).thenReturn(mockTarget);
    Optional<VirtualFile> ancestor = ORFileUtils.findAncestorRecursive(mockProject, targetName, mockStart);
    assertTrue(ancestor.isPresent());
    assertEquals(mockTarget, ancestor.get());
}
 
Example #30
Source File: BsConfigJsonTest.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
public void testIsBsConfig() {
    String bsConfigFileName = BsConfigJsonFileType.getDefaultFilename();
    MockVirtualFile mockBsConfig = MockVirtualFile.file(bsConfigFileName);
    assertTrue(BsConfigJson.isBsConfigJson(mockBsConfig));
    assertFalse(BsConfigJson.isBsConfigJson(MockVirtualFile.file("package.json")));
}