IdeaGateway { public void registerUnsavedDocuments(LocalVcs vcs) { vcs.beginChangeSet(); for (Document d : getUnsavedDocuments()) { VirtualFile f = getFile(d); if (shouldNotRegister(f)) continue; registerDocumentContents(vcs, f, d); } vcs.endChangeSet(null); } IdeaGateway(Project p); Project getProject(); FileFilter getFileFilter(); String getBaseDir(); List<VirtualFile> getContentRoots(); boolean askForProceeding(String s); void showError(String s); void showMessage(String s, String title); void performCommandInsideWriteAction(final String name, final Runnable r); boolean ensureFilesAreWritable(List<VirtualFile> ff); VirtualFile findVirtualFile(String path); VirtualFile findOrCreateFileSafely(String path, boolean isDirectory); VirtualFile findOrCreateFileSafely(Object requestor, String path, boolean isDirectory); List<VirtualFile> getAllFilesFrom(String path); void registerUnsavedDocuments(LocalVcs vcs); void registerUnsavedDocuments(LocalVcs vcs, VirtualFile f); String stringFromBytes(byte[] bytes, String path); void saveAllUnsavedDocuments(); Document getDocument(String path); FileType getFileType(String fileName);  }
@Test public void testRegisteringUnsavedDocuments() throws Exception { vcs.createDirectory("root"); long timestamp = -1; vcs.createFile("root/f1", null, timestamp, false); long timestamp1 = -1; vcs.createFile("root/f2", null, timestamp1, false); gw.addUnsavedDocument("root/f1", "one"); gw.addUnsavedDocument("root/f2", "two"); assertEquals(3, vcs.getRevisionsFor("root").size()); assertEquals(1, vcs.getRevisionsFor("root/f1").size()); assertEquals(1, vcs.getRevisionsFor("root/f2").size()); Clock.setCurrentTimestamp(123); gw.registerUnsavedDocuments(vcs); List<Revision> rr1 = vcs.getRevisionsFor("root/f1"); List<Revision> rr2 = vcs.getRevisionsFor("root/f2"); assertEquals(2, rr1.size()); assertEquals(c("one"), rr1.get(0).getEntry().getContent()); assertEquals(123, rr1.get(0).getEntry().getTimestamp()); assertEquals(2, rr2.size()); assertEquals(c("two"), rr2.get(0).getEntry().getContent()); assertEquals(123, rr2.get(0).getEntry().getTimestamp()); assertEquals(4, vcs.getRevisionsFor("root").size()); }
@Test public void testFilteringDocumentsWithoutFiles() { long timestamp = -1; vcs.createFile("f", cf("file"), timestamp, false); gw.addUnsavedDocumentWithoutFile("f", "doc"); gw.registerUnsavedDocuments(vcs); assertEquals(c("file"), vcs.getEntry("f").getContent()); }
@Test public void testFilteringDocumentsForDeletedFiles() { long timestamp = -1; vcs.createFile("f", cf("file"), timestamp, false); gw.addUnsavedDocumentForDeletedFile("f", "doc"); gw.registerUnsavedDocuments(vcs); assertEquals(c("file"), vcs.getEntry("f").getContent()); }