1 33 34 package edu.rice.cs.drjava.model; 35 36 import java.io.*; 37 38 import javax.swing.text.BadLocationException ; 39 40 44 public final class GlobalModelCompileIOTest extends GlobalModelTestCase { 45 46 50 public void testClassFileSynchronization() throws BadLocationException , IOException, InterruptedException { 51 final OpenDefinitionsDocument doc = setupDocument(FOO_TEXT); 52 final File file = tempFile(); 53 54 doc.saveFile(new FileSelector(file)); 55 56 CompileShouldSucceedListener listener = new CompileShouldSucceedListener(false); 57 _model.addListener(listener); 58 assertTrue("Class file should not exist before compile", doc.getCachedClassFile() == null); 59 assertTrue("should not be in sync before compile", ! doc.checkIfClassFileInSync()); 60 assertTrue("The state of all open documents should be out of sync", _model.hasOutOfSyncDocuments()); 61 doc.startCompile(); 62 listener.waitCompileDone(); 63 if (_model.getCompilerModel().getNumErrors() > 0) { 64 fail("compile failed: " + getCompilerErrorString()); 65 } 66 _model.removeListener(listener); 67 listener.checkCompileOccurred(); 68 assertTrue("should be in sync after compile", doc.checkIfClassFileInSync()); 69 assertTrue("The state of all open documents should be in sync", ! _model.hasOutOfSyncDocuments()); 71 doc.insertString(0, "hi", null); 72 assertTrue("should not be in sync after modification", ! doc.checkIfClassFileInSync()); 73 74 Thread.sleep(2000); 76 77 doc.saveFile(new FileSelector(file)); 78 assertTrue("should not be in sync after save", ! doc.checkIfClassFileInSync()); 79 80 File compiled = classForJava(file, "DrJavaTestFoo"); 82 assertTrue(" Class file should exist after compile", compiled.exists()); 83 } 84 85 88 public void testClassFileSynchronizationAfterRename() throws BadLocationException , IOException, IllegalStateException , 89 InterruptedException { 90 91 final OpenDefinitionsDocument doc = setupDocument(FOO_TEXT); 92 final File file = tempFile(); 93 final File file2 = tempFile(2); 94 95 doc.saveFile(new FileSelector(file)); 96 97 CompileShouldSucceedListener listener = new CompileShouldSucceedListener(false); 98 _model.addListener(listener); 99 assertTrue("Class file should not exist before compile", 100 doc.getCachedClassFile() == null); 101 assertTrue("should not be in sync before compile", 102 !doc.checkIfClassFileInSync()); 103 doc.startCompile(); 104 listener.waitCompileDone(); 105 if (_model.getCompilerModel().getNumErrors() > 0) { 106 fail("compile failed: " + getCompilerErrorString()); 107 } 108 _model.removeListener(listener); 109 listener.checkCompileOccurred(); 110 assertTrue("should be in sync after compile", 111 doc.checkIfClassFileInSync()); 112 113 Thread.sleep(2000); 115 116 doc.saveFileAs(new FileSelector(file2)); 118 assertTrue("should not be in sync after renaming", ! doc.checkIfClassFileInSync()); 119 } 120 121 122 public void testCompileAfterFileMoved() throws BadLocationException , IOException { 123 OpenDefinitionsDocument doc = setupDocument(FOO_TEXT); 124 final File file = tempFile(); 125 doc.saveFile(new FileSelector(file)); 126 TestListener listener = new TestListener(); 127 _model.addListener(listener); 128 file.delete(); 129 try { 130 doc.startCompile(); 131 fail("Compile should not have begun."); 132 } 133 catch (FileMovedException fme) { 134 } 137 assertCompileErrorsPresent("compile should succeed", false); 138 139 File compiled = classForJava(file, "DrJavaTestFoo"); 141 assertTrue("Class file shouldn't exist after compile", !compiled.exists()); 142 _model.removeListener(listener); 143 } 144 145 } 146 | Popular Tags |