public void testOpeningProjectWithBrokenRakefile() throws Exception { // #153275 MockServices.setServices(DialogDisplayerImpl.class); RubyProject project = createTestProject(); String rakeContent = "require 'non-sense'\n"; dumpRakefile(rakeContent, project); RakeSupport.refreshTasks(project, false); }
public void testLookupPossibleWhenRepoCreated() { MockServices.setServices(NbRep.class); Repository r1 = Repository.getDefault(); assertSame("The same repository is obtained", r1, FS.my); }
@BeforeClass public static void setUpClass() throws Exception { MockServices.setServices(); DalvikPlatformManager.getDefault().setSdkLocation(SDK_DIR); tempFolder = File.createTempFile("junit", ""); tempFolder.delete(); tempFolder.mkdir(); FileObject scratch = FileUtil.toFileObject(tempFolder); FileObject cacheDir = scratch.createFolder("cache"); CacheFolder.setCacheFolder(cacheDir); FileObject sdkDirFo = FileUtil.toFileObject(new File(SDK_DIR)); projdir = scratch.createFolder("Snake"); FileUtilities.recursiveCopy(sdkDirFo.getFileObject("samples/android-8/Snake"), projdir); FileObject dir = projdir; for (String dirName : Splitter.on('/').split("gen/com/example/android/snake")) { dir = dir.createFolder(dirName); } OutputStream os = dir.createData("R.java").getOutputStream(); FileUtil.copy(ProjectRefResolverTest.class.getResourceAsStream("Snake_R_java.txt"), os); os.close(); pp = ProjectManager.getDefault().findProject(projdir); }
public JavadocForBinaryQueryPlatformImplTest(java.lang.String testName) { super(testName); MockServices.setServices( ArchiveURLMapper.class, JavadocForBinaryQueryPlatformImpl.class, MasterURLMapper.class, JavaPlatformProviderImpl.class); }
// BEGIN: codeinjection.twice @Test public void testDecrementTwoTimesEnough() { MockServices.setServices(DecrementByTwo.class); CountDown counter = create(4); assertFalse("Not down yet", counter.isDown()); counter.down(); assertFalse("Not down yet", counter.isDown()); counter.down(); assertTrue("Two Down is enough", counter.isDown()); }
@Override protected void setUp() throws Exception { super.setUp(); MockServices.setServices(DL.class); fo = FileUtil.createData(FileUtil.createMemoryFileSystem().getRoot(), "data.dat"); obj = DataObject.find(fo); assertEquals("MDO: " + obj, MDO.class, obj.getClass()); node = obj.getNodeDelegate(); }
@Override protected void setUp() throws Exception { dataRootDir = getWorkDir(); dataRootDir.mkdirs(); File userdir = new File(dataRootDir + "userdir"); userdir.mkdirs(); System.setProperty("netbeans.user", userdir.getAbsolutePath()); FileObject fo = FileUtil.toFileObject(getWorkDir()); MockServices.setServices(DeleteCreateTestAnnotationProvider.class); // interceptor init DeleteCreateTestAnnotationProvider.instance.init(); }
@Test public void testDecrementFourTimes() { MockServices.setServices(); CountDown counter = create(4); assertFalse("Not down yet", counter.isDown()); counter.down(); assertFalse("Not down yet", counter.isDown()); counter.down(); assertFalse("Not down yet", counter.isDown()); counter.down(); assertFalse("Not down yet", counter.isDown()); counter.down(); assertTrue("Down now", counter.isDown()); }
/** @throws java.lang.Exception */ @RandomlyFails public void testDocumentModification() throws Exception { // 1) register tasks and parsers MockServices.setServices(MockMimeLookup.class, MyScheduler.class); final CountDownLatch latch1 = new CountDownLatch(1); final CountDownLatch latch2 = new CountDownLatch(2); final CountDownLatch latch3 = new CountDownLatch(3); final int[] fooParser = {1}; final int[] fooParserResult = {1}; final int[] fooEmbeddingProvider = {1}; final int[] fooTask = {1}; final int[] booParser = {1}; final int[] booParserResult = {1}; final int[] booTask = {1}; final TestComparator test = new TestComparator( "1 - reschedule all schedulers\n" + "foo get embeddings 1 (Snapshot 1), \n" + "Snapshot 1: Toto je testovaci file, na kterem se budou delat hnusne pokusy!!!, \n" + "Snapshot 2: stovaci fi, \n" + "foo parse 1 (Snapshot 1, FooParserResultTask 1, SourceModificationEvent -1:-1), \n" + "foo get result 1 (FooParserResultTask 1), \n" + "foo task 1 (FooResult 1 (Snapshot 1), SchedulerEvent 1), \n" + "foo invalidate 1, \n" + "boo parse 1 (Snapshot 2, BooParserResultTask 1, SourceModificationEvent -1:-1), \n" + "boo get result 1 (BooParserResultTask 1), \n" + "boo task 1 (BooResult 1 (Snapshot 2), SchedulerEvent 1), \n" + "boo invalidate 1, \n" + "2 - insert 14 chars on offset 22\n" + "foo get embeddings 1 (Snapshot 3), \n" + "Snapshot 3: Toto je testovaci file (druha verze), na kterem se budou delat hnusne pokusy!!!, \n" + "Snapshot 4: stovaci fi, \n" + "foo parse 1 (Snapshot 3, FooParserResultTask 1, SourceModificationEvent 18:37), \n" + "foo get result 1 (FooParserResultTask 1), \n" + "foo task 1 (FooResult 2 (Snapshot 3), SchedulerEvent 1), \n" + "foo invalidate 2, \n" + "boo parse 1 (Snapshot 4, BooParserResultTask 1, SourceModificationEvent -1:-1), \n" + // !! source unchanged "boo get result 1 (BooParserResultTask 1), \n" + "boo task 1 (BooResult 2 (Snapshot 4), SchedulerEvent 1), \n" + "boo invalidate 2, \n" + "3 - remove 5 chars on offset 44\n" + "foo get embeddings 1 (Snapshot 5), \n" + "Snapshot 5: Toto je testovaci file (druha verze), na ktee budou delat hnusne pokusy!!!, \n" + "Snapshot 6: stovaci fi, \n" + "foo parse 1 (Snapshot 5, FooParserResultTask 1, SourceModificationEvent 41:45), \n" + "foo get result 1 (FooParserResultTask 1), \n" + "foo task 1 (FooResult 3 (Snapshot 5), SchedulerEvent 2), \n" + "foo invalidate 3, \n" + "boo parse 1 (Snapshot 6, BooParserResultTask 1, SourceModificationEvent -1:-1), \n" + // !! source unchanged "boo get result 1 (BooParserResultTask 1), \n" + "boo task 1 (BooResult 3 (Snapshot 6), SchedulerEvent 2), \n" + "boo invalidate 3, \n" + "4 - end\n"); MockMimeLookup.setInstances( MimePath.get("text/foo"), new ParserFactory() { public Parser createParser(Collection<Snapshot> snapshots2) { return new Parser() { private Snapshot last; private int i = fooParser[0]++; public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) throws ParseException { test.check( "foo parse " + i + " (Snapshot " + test.get(snapshot) + ", " + task + ", " + event + "), \n"); last = snapshot; } public Result getResult(Task task) throws ParseException { test.check("foo get result " + i + " (" + task + "), \n"); return new Result(last) { public void invalidate() { test.check("foo invalidate " + i + ", \n"); } private int i = fooParserResult[0]++; @Override public String toString() { return "FooResult " + i + " (Snapshot " + test.get(getSnapshot()) + ")"; } }; } public void cancel() {} public void addChangeListener(ChangeListener changeListener) {} public void removeChangeListener(ChangeListener changeListener) {} }; } }, new TaskFactory() { public Collection<SchedulerTask> create(Snapshot snapshot) { return Arrays.asList( new SchedulerTask[] { new EmbeddingProvider() { private int i = fooEmbeddingProvider[0]++; public List<Embedding> getEmbeddings(Snapshot snapshot) { test.check( "foo get embeddings " + i + " (Snapshot " + test.get(snapshot) + "), \n"); test.check( "Snapshot " + test.get(snapshot) + ": " + snapshot.getText() + ", \n"); Embedding embedding = snapshot.create(10, 10, "text/boo"); test.get(embedding.getSnapshot()); test.check( "Snapshot " + test.get(embedding.getSnapshot()) + ": " + embedding.getSnapshot().getText() + ", \n"); return Arrays.asList(new Embedding[] {embedding}); } public int getPriority() { return 10; } public void cancel() {} }, new ParserResultTask() { public void run(Result result, SchedulerEvent event) { test.check( "foo task " + i + " (" + result + ", SchedulerEvent " + test.get(event) + "), \n"); } public int getPriority() { return 100; } public Class<? extends Scheduler> getSchedulerClass() { return Scheduler.EDITOR_SENSITIVE_TASK_SCHEDULER; } public void cancel() {} private int i = fooTask[0]++; @Override public String toString() { return "FooParserResultTask " + i; } } }); } }); MockMimeLookup.setInstances( MimePath.get("text/boo"), new ParserFactory() { public Parser createParser(Collection<Snapshot> snapshots2) { return new Parser() { private Snapshot last; private int i = booParser[0]++; public void parse(Snapshot snapshot, Task task, SourceModificationEvent event) throws ParseException { test.check( "boo parse " + i + " (Snapshot " + test.get(snapshot) + ", " + task + ", " + event + "), \n"); last = snapshot; } public Result getResult(Task task) throws ParseException { test.check("boo get result " + i + " (" + task + "), \n"); return new Result(last) { public void invalidate() { test.check("boo invalidate " + i + ", \n"); latch1.countDown(); latch2.countDown(); latch3.countDown(); } private int i = booParserResult[0]++; @Override public String toString() { return "BooResult " + i + " (Snapshot " + test.get(getSnapshot()) + ")"; } }; } public void cancel() {} public void addChangeListener(ChangeListener changeListener) {} public void removeChangeListener(ChangeListener changeListener) {} }; } }, new TaskFactory() { public Collection<SchedulerTask> create(Snapshot snapshot) { return Arrays.asList( new SchedulerTask[] { new ParserResultTask() { private int i = booTask[0]++; public void run(Result result, SchedulerEvent event) { test.check( "boo task " + i + " (" + result + ", SchedulerEvent " + test.get(event) + "), \n"); } public int getPriority() { return 150; } public Class<? extends Scheduler> getSchedulerClass() { return Scheduler.EDITOR_SENSITIVE_TASK_SCHEDULER; } public void cancel() {} @Override public String toString() { return "BooParserResultTask " + i; } } }); } }); // 2) create source file clearWorkDir(); FileObject workDir = FileUtil.toFileObject(getWorkDir()); FileObject testFile = FileUtil.createData(workDir, "bla.foo"); FileUtil.setMIMEType("foo", "text/foo"); OutputStream outputStream = testFile.getOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(outputStream); writer.append("Toto je testovaci file, na kterem se budou delat hnusne pokusy!!!"); writer.close(); Source source = Source.create(testFile); Document document = source.getDocument(true); document.putProperty("mimeType", "text/foo"); document.putProperty(Language.class, new ALanguageHierarchy().language()); TokenHierarchy th = TokenHierarchy.get(document); TokenSequence ts = th.tokenSequence(); ts.tokenCount(); test.check("1 - reschedule all schedulers\n"); // 3) shcedulle CurrentDocumentScheduler for (Scheduler scheduler : Schedulers.getSchedulers()) if (scheduler instanceof CurrentDocumentScheduler) ((CurrentDocumentScheduler) scheduler).schedule(source); latch1.await(); test.check("2 - insert 14 chars on offset 22\n"); document.insertString(22, " (druha verze)", null); latch2.await(); test.check("3 - remove 5 chars on offset 44\n"); document.remove(44, 5); latch3.await(); test.check("4 - end\n"); assertEquals("", test.getResult()); }