KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > model > GlobalModelOtherTest


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.model;
35
36 import java.io.*;
37 import javax.swing.text.BadLocationException JavaDoc;
38 import javax.swing.event.*;
39 import java.util.Vector JavaDoc;
40
41 import edu.rice.cs.drjava.DrJava;
42 import edu.rice.cs.drjava.config.*;
43 import edu.rice.cs.drjava.model.repl.*;
44 import edu.rice.cs.util.Log;
45 import edu.rice.cs.util.UnexpectedException;
46 import edu.rice.cs.util.text.EditDocumentException;
47 import edu.rice.cs.util.swing.Utilities;
48
49 /** A test on the GlobalModel that does deals with everything outside of simple file operations, e.g., compile, quit.
50  * @version $Id: GlobalModelOtherTest.java 4069 2007-01-18 17:11:59Z dlsmith $
51  */

52 public final class GlobalModelOtherTest extends GlobalModelTestCase implements OptionConstants {
53   
54   // _log can be inherited from GlobalModelTestCase
55
Log _log = new Log("GlobalModelOtherTest.txt", false);
56   
57   private static final String JavaDoc FOO_CLASS =
58     "package bar;\n" +
59     "public class Foo {\n" +
60     " public static void main(String[] args) {\n" +
61     " System.out.println(\"Foo\");\n" +
62     " }\n" +
63     "}\n";
64   
65   /** Get the canonical name of a file. If the operation fails, the test will fail. */
66   private File makeCanonical(File f) {
67     try { return f.getCanonicalFile(); }
68     catch (IOException e) { fail("Can't get a canonical path for file " + f); return null; }
69   }
70
71   /** Tests that the undoableEditHappened event is fired if the undo manager is in use. */
72   public void testUndoEventsOccur() throws BadLocationException JavaDoc {
73     final OpenDefinitionsDocument doc = _model.newFile();
74
75     // Have to add an undoable edit listener for Undo to work
76
doc.addUndoableEditListener(new UndoableEditListener() {
77       public void undoableEditHappened(UndoableEditEvent e) { doc.getUndoManager().addEdit(e.getEdit()); }
78     });
79
80     TestListener listener = new TestListener() { public void undoableEditHappened() { undoableEditCount++; } };
81     
82     _model.addListener(listener);
83     changeDocumentText("test", doc);
84     
85     Utilities.clearEventQueue();
86     _model.removeListener(listener);
87     listener.assertUndoableEditCount(1);
88 // Utilities.showDebug("testUndoEvents finished");
89

90 // _log.log("testUndoEventsOccur() completed");
91
}
92
93   /** Checks that System.exit is handled appropriately from interactions pane. */
94   public void testExitInteractions() throws EditDocumentException, InterruptedException JavaDoc{
95     InteractionListener listener = new InteractionListener() {
96
97 // public void consoleReset() { consoleResetCount++; }
98
};
99
100     _model.addListener(listener);
101
102     listener.logInteractionStart();
103     interpretIgnoreResult("System.exit(23);");
104     listener.waitInteractionDone();
105     listener.waitResetDone();
106     Utilities.clearEventQueue();
107       
108     _model.removeListener(listener);
109
110 // listener.assertConsoleResetCount(0);
111
listener.assertInteractionStartCount(1);
112     listener.assertInterpreterResettingCount(1);
113     listener.assertInterpreterReadyCount(1);
114     listener.assertInterpreterExitedCount(1);
115     assertEquals("exit status", 23, listener.getLastExitStatus());
116
117     _log.log("testExitInteractions() completed");
118   }
119
120   /** Checks that the interpreter can be aborted and then work correctly later. Part of what we check here is that
121    * the interactions classpath is correctly reset after aborting interactions. That is, we ensure that the compiled
122    * class is still visible after aborting. This was broken in drjava-20020108-0958 -- or so I thought. I can't
123    * consistently reproduce the problem in the UI (seems to show up using IBM's JDK only), and I can never reproduce
124    * it in the test case. Grr. <p> OK, now I found the explanation: We were in some cases running two new JVMs
125    * on an abort. I fixed the problem in MainJVM#restartInterpreterJVM
126    *
127    * The above method no longer exists... Does anyone remember what this meant? -nrh
128    */

129   public void testInteractionAbort() throws BadLocationException JavaDoc, EditDocumentException, InterruptedException JavaDoc,
130     IOException {
131     
132     doCompile(setupDocument(FOO_TEXT), tempFile());
133     
134     Utilities.clearEventQueue();
135
136     final String JavaDoc beforeAbort = interpret("DrJavaTestFoo.class.getName()"); /* interpret("17"); */
137     
138     _log.log("Completed initial interpret call");
139     
140     assertEquals("\"DrJavaTestFoo\"", beforeAbort);
141     
142     Utilities.clearEventQueue();
143
144     InteractionListener listener = new InteractionListener();
145
146     _model.addListener(listener);
147     listener.logInteractionStart();
148     _log.log("Starting infinite loop");
149     interpretIgnoreResult("while (true) {}");
150     Utilities.clearEventQueue();
151     
152     listener.assertInteractionStartCount(1);
153     
154     _log.log("Resetting interactions");
155     _model.resetInteractions(FileOption.NULL_FILE);
156     listener.waitResetDone();
157     
158     Utilities.clearEventQueue();
159
160     listener.assertInterpreterResettingCount(1);
161     listener.assertInterpreterReadyCount(1);
162     listener.assertInterpreterExitedCount(0);
163     listener.assertConsoleResetCount(0);
164
165     // now make sure it still works!
166
assertEquals("5", interpret("5"));
167     _model.removeListener(listener);
168
169     // make sure we can still see class foo
170
final String JavaDoc afterAbort = interpret("DrJavaTestFoo.class.getName()");
171     Utilities.clearEventQueue();
172     assertEquals("\"DrJavaTestFoo\"", afterAbort);
173     _log.log("testInteractionAbort() completed");
174   }
175
176   /** Checks that reset console works. */
177   public void testResetConsole() throws EditDocumentException, InterruptedException JavaDoc {
178     //System.err.println("Entering testResetConsole");
179
InteractionListener listener = new InteractionListener();
180
181     _model.addListener(listener);
182     
183     listener.logInteractionStart();
184
185     _model.resetConsole();
186     Utilities.clearEventQueue();
187     
188     assertEquals("Length of console text", 0, _model.getConsoleDocument().getLength());
189
190     listener.assertConsoleResetCount(1);
191     
192     listener.logInteractionStart(); // only resets the interactionDone and resetDone flags
193
listener.resetConsoleResetCount(); // resets the resetConsoleCount in the listener
194

195     interpretIgnoreResult("System.out.print(\"a\");");
196     listener.waitInteractionDone();
197     
198     Utilities.clearEventQueue();
199     
200     assertEquals("Length of console text", 1, _model.getConsoleDocument().getLength());
201
202     _model.resetConsole();
203     
204     Utilities.clearEventQueue();
205     assertEquals("Length of console text", 0, _model.getConsoleDocument().getLength());
206
207     listener.assertConsoleResetCount(1);
208     _log.log("testResetConsole() completed");
209   }
210
211   /** Creates a new class, compiles it and then checks that the REPL can see it. Then checks that a compiled class
212    * file in another directory can be both accessed and extended if it is on the "extra.classpath" config option.
213    */

214   public void testInteractionsCanSeeCompiledClasses() throws BadLocationException JavaDoc, EditDocumentException,
215     IOException, InterruptedException JavaDoc {
216     // Compile Foo
217
OpenDefinitionsDocument doc1 = setupDocument(FOO_TEXT);
218     File dir1 = makeCanonical(new File(_tempDir, "dir1"));
219     dir1.mkdir();
220     File file1 = makeCanonical(new File(dir1, "TestFile1.java"));
221     doCompile(doc1, file1);
222
223     assertEquals("interactions result", "\"DrJavaTestFoo\"", interpret("new DrJavaTestFoo().getClass().getName()"));
224
225     // Add directory 1 to extra classpath and close doc1
226
Vector JavaDoc<File> cp = new Vector JavaDoc<File>();
227     cp.add(dir1);
228     DrJava.getConfig().setSetting(EXTRA_CLASSPATH, cp);
229     
230     Utilities.clearEventQueue();
231     _model.closeFile(doc1);
232
233     // Compile Baz which extends Foo in another directory.
234
OpenDefinitionsDocument doc2 = setupDocument(BAZ_TEXT);
235     File dir2 = makeCanonical(new File(_tempDir, "dir2"));
236     dir2.mkdir();
237     File file2 = makeCanonical(new File(dir2, "TestFile1.java"));
238     doCompile(doc2, file2);
239
240     // Ensure that Baz can use the Foo class from extra classpath
241
assertEquals("interactions result", "\"DrJavaTestBaz\"", interpret("new DrJavaTestBaz().getClass().getName()"));
242
243     // Ensure that static fields can be seen
244
assertEquals("result of static field", "3", interpret("DrJavaTestBaz.x"));
245
246     // Also ensure that Foo can be used directly
247
assertEquals("interactions result", "\"DrJavaTestFoo\"", interpret("new DrJavaTestFoo().getClass().getName()"));
248     
249     _log.log("testInteractionsCanSeeCompletedClasses() completed");
250   }
251
252   /** Compiles a new class in the default package with a mixed case name, and ensures that it can be instantiated on a
253    * variable with an identical name (but a lowercase first letter). Catches SF bug #689026 ("DynamicJava can't handle
254    * certain variable names")
255    */

256   public void testInteractionsVariableWithLowercaseClassName() throws BadLocationException JavaDoc, EditDocumentException,
257     IOException, InterruptedException JavaDoc {
258     // Compile a test file
259
OpenDefinitionsDocument doc1 = setupDocument("public class DrJavaTestClass {}");
260     File file1 = makeCanonical(new File(_tempDir, "DrJavaTestClass.java"));
261     doCompile(doc1, file1);
262
263     // This shouldn't cause an error (no output should be displayed)
264
assertEquals("interactions result", "", interpret("drJavaTestClass = new DrJavaTestClass();"));
265     _log.log("testInteractionsVariableWithLowercaseClassName() completed");
266   }
267
268   /** Checks that updating a class and recompiling it is visible from the REPL. */
269   public void testInteractionsCanSeeChangedClass() throws BadLocationException JavaDoc, EditDocumentException,
270     IOException, InterruptedException JavaDoc {
271     final String JavaDoc text_before = "class DrJavaTestFoo { public int m() { return ";
272     final String JavaDoc text_after = "; } }";
273     final int num_iterations = 3;
274     File file;
275     OpenDefinitionsDocument doc;
276
277     for (int i = 0; i < num_iterations; i++) {
278       doc = setupDocument(text_before + i + text_after);
279       file = tempFile(i);
280       doCompile(doc, file);
281
282       assertEquals("interactions result, i=" + i, String.valueOf(i), interpret("new DrJavaTestFoo().m()"));
283     }
284     _log.log("testInteractionsCanSeeChangedClass() completed");
285   }
286
287   /** Checks that an anonymous inner class can be defined in the repl! */
288   public void testInteractionsDefineAnonymousInnerClass() throws BadLocationException JavaDoc, EditDocumentException,
289     IOException, InterruptedException JavaDoc {
290     final String JavaDoc interface_text = "public interface I { int getValue(); }";
291     final File file = createFile("I.java");
292
293     OpenDefinitionsDocument doc;
294
295     doc = setupDocument(interface_text);
296     doCompile(doc, file);
297
298     for (int i = 0; i < 3; i++) {
299       String JavaDoc s = "new I() { public int getValue() { return " + i + "; } }.getValue()";
300
301       assertEquals("interactions result, i=" + i, String.valueOf(i), interpret(s));
302     }
303     _log.log("testInteractionsDefineAnonymousInnerClass() completed");
304   }
305
306   public void testGetSourceRootDefaultPackage() throws BadLocationException JavaDoc, IOException {
307
308     // Get source root (current directory only)
309
File[] roots = _model.getSourceRootSet();
310     assertEquals("number of source roots", 0, roots.length);
311
312      // Create temp directory
313
File baseTempDir = tempDirectory();
314
315     // Now make subdirectory a/b/c
316
File subdir = makeCanonical(new File(baseTempDir, "a"));
317     subdir = makeCanonical(new File(subdir, "b"));
318     subdir = makeCanonical(new File(subdir, "c"));
319     subdir.mkdirs();
320
321     // Save the footext to DrJavaTestFoo.java in the subdirectory
322
File fooFile = makeCanonical(new File(subdir, "DrJavaTestFoo.java"));
323     OpenDefinitionsDocument doc = setupDocument(FOO_TEXT);
324     doc.saveFileAs(new FileSelector(fooFile));
325
326     // No events should fire
327
_model.addListener(new TestListener());
328
329     // Get source roots
330
roots = _model.getSourceRootSet();
331     assertEquals("number of source roots", 1, roots.length);
332     // Get the source root for the new file in directory subdir
333
assertEquals("source root", subdir, roots[0]);
334     
335     _log.log("testGetSourceRootDefaultPackage() completed");
336   }
337
338   public void testGetSourceRootPackageThreeDeepValid() throws BadLocationException JavaDoc, IOException {
339     // Create temp directory
340
File baseTempDir = tempDirectory();
341
342     // Now make subdirectory a/b/c
343
File subdir = makeCanonical(new File(baseTempDir, "a"));
344     subdir = makeCanonical(new File(subdir, "b").getCanonicalFile());
345     subdir = makeCanonical(new File(subdir, "c").getCanonicalFile());
346     subdir.mkdirs();
347
348     // Save the footext to DrJavaTestFoo.java in the subdirectory
349
File fooFile = makeCanonical(new File(subdir, "DrJavaTestFoo.java"));
350     OpenDefinitionsDocument doc = setupDocument("package a.b.c;\n" + FOO_TEXT);
351     doc.saveFileAs(new FileSelector(fooFile));
352 // System.err.println("Package name is: " + _model.getPackageName());
353

354     // No events should fire
355
_model.addListener(new TestListener());
356
357     // Since we had the package statement the source root should be base dir
358
File[] roots = _model.getSourceRootSet();
359     assertEquals("number of source roots", 1, roots.length);
360     assertEquals("source root", baseTempDir.getCanonicalFile(), roots[0].getCanonicalFile());
361     
362     _log.log("testGetSourceRootPackageThreeDeepValid() completed");
363   }
364
365   /** Tests that getSourceRoot works with a relative path when a package name is present. */
366   public void testGetSourceRootPackageThreeDeepValidRelative() throws BadLocationException JavaDoc, IOException {
367     // Create temp directory
368
File baseTempDir = tempDirectory();
369     File subdir = makeCanonical(new File(baseTempDir, "a"));
370     subdir = makeCanonical(new File(subdir, "b"));
371     subdir = makeCanonical(new File(subdir, "c"));
372     subdir.mkdirs();
373
374     // Save the footext to DrJavaTestFoo.java in a relative directory
375
// temp/./a/b/../b/c == temp/a/b/c
376
File relDir = makeCanonical(new File(baseTempDir, "./a/b/../b/c"));
377     File fooFile = makeCanonical(new File(relDir, "DrJavaTestFoo.java"));
378     OpenDefinitionsDocument doc =
379       setupDocument("package a.b.c;\n" + FOO_TEXT);
380     doc.saveFileAs(new FileSelector(fooFile));
381
382     // No events should fire
383
_model.addListener(new TestListener());
384
385     // Since we had the package statement the source root should be base dir
386
File[] roots = _model.getSourceRootSet();
387     assertEquals("number of source roots", 1, roots.length);
388     assertEquals("source root", baseTempDir.getCanonicalFile(), roots[0].getCanonicalFile());
389     
390     _log.log("testGetSourceRootPackageThreeDeepValidRelative() completed");
391   }
392
393   public void testGetSourceRootPackageThreeDeepInvalid() throws BadLocationException JavaDoc, IOException {
394     // Create temp directory
395
File baseTempDir = tempDirectory();
396
397     // Now make subdirectory a/b/d
398
File subdir = makeCanonical(new File(baseTempDir, "a"));
399     subdir = makeCanonical(new File(subdir, "b"));
400     subdir = makeCanonical(new File(subdir, "d"));
401     subdir.mkdirs();
402
403     // Save the footext to DrJavaTestFoo.java in the subdirectory
404
File fooFile = makeCanonical(new File(subdir, "DrJavaTestFoo.java"));
405     OpenDefinitionsDocument doc =
406       setupDocument("package a.b.c;\n" + FOO_TEXT);
407     doc.saveFileAs(new FileSelector(fooFile));
408
409     // No events should fire
410
_model.addListener(new TestListener());
411
412     // The package name is wrong so this should return only currDir
413
File[] roots = _model.getSourceRootSet();
414     assertEquals("number of source roots", 0, roots.length);
415     
416     _log.log("testGetSourceRootPackageThreeDeepInvalid() completed");
417   }
418
419   public void testGetSourceRootPackageOneDeepValid() throws BadLocationException JavaDoc, IOException {
420     // Create temp directory
421
File baseTempDir = tempDirectory();
422
423     // Now make subdirectory a
424
File subdir = makeCanonical(new File(baseTempDir, "a"));
425     subdir.mkdir();
426
427     // Save the footext to DrJavaTestFoo.java in the subdirectory
428
File fooFile = makeCanonical(new File(subdir, "DrJavaTestFoo.java"));
429     OpenDefinitionsDocument doc = setupDocument("package a;\n" + FOO_TEXT);
430     doc.saveFileAs(new FileSelector(fooFile));
431
432     // No events should fire
433
_model.addListener(new TestListener());
434
435     // Since we had the package statement the source root should be base dir
436
File[] roots = _model.getSourceRootSet();
437     assertEquals("number of source roots", 1, roots.length);
438     assertEquals("source root", baseTempDir.getCanonicalFile(), roots[0].getCanonicalFile());
439     
440     _log.log("testGetSourceRootPackageOneDeepValid() completed");
441   }
442
443
444   public void testGetMultipleSourceRootsDefaultPackage() throws BadLocationException JavaDoc, IOException {
445     // Create temp directory
446
File baseTempDir = tempDirectory();
447
448     // Now make subdirectories a, b
449
File subdir1 = makeCanonical(new File(baseTempDir, "a"));
450     subdir1.mkdir();
451     File subdir2 = makeCanonical(new File(baseTempDir, "b"));
452     subdir2.mkdir();
453
454     // Save the footext to DrJavaTestFoo.java in subdirectory 1
455
File file1 = makeCanonical(new File(subdir1, "DrJavaTestFoo.java"));
456     OpenDefinitionsDocument doc1 = setupDocument(FOO_TEXT);
457     doc1.saveFileAs(new FileSelector(file1));
458
459     // Save the bartext to Bar.java in subdirectory 1
460
File file2 = makeCanonical(new File(subdir1, "Bar.java"));
461     OpenDefinitionsDocument doc2 = setupDocument(BAR_TEXT);
462     doc2.saveFileAs(new FileSelector(file2));
463
464     // Save the bartext to Bar.java in subdirectory 2
465
File file3 = makeCanonical(new File(subdir2, "Bar.java"));
466     OpenDefinitionsDocument doc3 = setupDocument(BAR_TEXT);
467     doc3.saveFileAs(new FileSelector(file3));
468     
469     Utilities.clearEventQueue();
470
471     // No events should fire
472
_model.addListener(new TestListener());
473
474     // Get source roots (should be 2: no duplicates)
475
File[] roots = _model.getSourceRootSet();
476     assertEquals("number of source roots", 2, roots.length);
477     File root1 = roots[0];
478     File root2 = roots[1];
479
480     // Make sure both source roots are in set
481
// But we don't care about the order
482
if (!( (root1.equals(subdir1) && root2.equals(subdir2)) || (root1.equals(subdir2) && root2.equals(subdir1)) )) {
483       fail("source roots did not match");
484     }
485     
486     _log.log("testGetMultipleSourceRootsDefaultPackage() completed");
487   }
488
489   /** Creates a new class, compiles it and then checks that the REPL can see it. */
490   public void testInteractionsLiveUpdateClassPath() throws BadLocationException JavaDoc, EditDocumentException,
491     IOException, InterruptedException JavaDoc {
492
493     OpenDefinitionsDocument doc = setupDocument(FOO_TEXT);
494     Utilities.clearEventQueue();
495         
496     File f = tempFile();
497
498     doCompile(doc, f);
499
500     // Rename the directory so it's not on the classpath anymore
501
String JavaDoc tempPath = f.getParent();
502     File tempDir = makeCanonical(new File(tempPath));
503     tempDir.renameTo(makeCanonical(new File(tempPath + "a")));
504
505     String JavaDoc result = interpret("new DrJavaTestFoo().getClass().getName()");
506
507     // Should cause a NoClassDefFound, but we shouldn't check exact syntax.
508
// Instead, make sure it isn't "DrJavaTestFoo", as if the class was found.
509
assertFalse("interactions should have an error, not the correct answer", "\"DrJavaTestFoo\"".equals(result));
510 // System.err.println("Result1 is: " + result);
511

512     // Add new directory to classpath through Config
513
Vector JavaDoc<File> cp = new Vector JavaDoc<File>();
514     cp.add(makeCanonical(new File(tempPath + "a")));
515     DrJava.getConfig().setSetting(EXTRA_CLASSPATH, cp);
516     
517     Utilities.clearEventQueue();
518     _model.resetInteractionsClassPath();
519
520     result = interpret("new DrJavaTestFoo().getClass().getName()");
521
522     // Now it should be on the classpath
523
assertEquals("interactions result", "\"DrJavaTestFoo\"", result);
524
525     // Rename directory back to clean up
526
tempDir = makeCanonical(new File(tempPath + "a"));
527     boolean renamed = tempDir.renameTo(makeCanonical(new File(tempPath)));
528     
529     _log.log("testInteractionsLiveUpdateClasspath() completed");
530   }
531
532   /** Tests that the appropriate event is fired when the model's interpreter changes.*/
533   public void testSwitchInterpreters() {
534     TestListener listener = new TestListener() {
535       public void interpreterChanged(boolean inProgress) {
536         assertTrue("should not be in progress", !inProgress);
537         interpreterChangedCount++;
538       }
539     };
540     _model.addListener(listener);
541
542     DefaultInteractionsModel dim = _model.getInteractionsModel();
543
544     // Create a new Java interpreter, and set it to be active
545
dim.addJavaInterpreter("testInterpreter");
546     
547     dim.setActiveInterpreter("testInterpreter", "myPrompt>");
548     
549     Utilities.clearEventQueue();
550     listener.assertInterpreterChangedCount(1);
551     _model.removeListener(listener);
552     
553     _log.log("testSwitchInterpreters() completed");
554   }
555
556   public void testRunMainMethod() throws Exception JavaDoc {
557     File dir = makeCanonical(new File(_tempDir, "bar"));
558     dir.mkdir();
559     File file = makeCanonical(new File(dir, "Foo.java"));
560     final OpenDefinitionsDocument doc = doCompile(FOO_CLASS, file);
561     Utilities.invokeAndWait(new Runnable JavaDoc() {
562       public void run() {
563         try { doc.runMain(); }
564         catch(Exception JavaDoc e) { throw new UnexpectedException(e); }
565       }
566     });
567     
568 // Utilities.clearEventQueue();
569
assertInteractionsContains(InteractionsModel.BANNER_PREFIX);
570     doc.insertString(doc.getLength(), " ", null);
571     
572     Utilities.invokeAndWait(new Runnable JavaDoc() {
573       public void run() {
574         try { doc.runMain(); }
575         catch(Exception JavaDoc e) { throw new UnexpectedException(e); }
576       }
577     });
578     
579 // Utilities.clearEventQueue();
580
assertInteractionsContains(DefaultGlobalModel.DOCUMENT_OUT_OF_SYNC_MSG);
581     Utilities.clearEventQueue();
582     // Killing time here; Slave JVM may not have released Foo.class so that the file can be deleted on Windows.
583

584     _log.log("testRunMainMethod() completed");
585   }
586 }
587
Popular Tags