Skip to content

Commit a411d7f

Browse files
committed
This revision finally fixes the remaining problems with code coverage
in DrJava thanks to a lot of help from Andrew Huie. It also includes a rewrite of the _isJunitTest method in JUnitTestManager to more fully support execution of test methods with JUnit4 style annotations even when they are not embedded in classes extending junit.framework.TestClass. At some point, we may need to migrate completely to JUnit4. Minor typographically changes were added to made to many comments, making this commit look much bigger than it really is. The following files were modified, added or deleted: modified: lib/jacocoant.jar modified: src/edu/rice/cs/drjava/model/AbstractGlobalModel.java modified: src/edu/rice/cs/drjava/model/DefaultGlobalModel.java modified: src/edu/rice/cs/drjava/model/FindReplaceMachine.java modified: src/edu/rice/cs/drjava/model/GlobalModelJUnitTest.java modified: src/edu/rice/cs/drjava/model/GlobalModelTestCase.java modified: src/edu/rice/cs/drjava/model/JarJDKToolsLibrary.java modified: src/edu/rice/cs/drjava/model/compiler/CompilerErrorModel.java modified: src/edu/rice/cs/drjava/model/coverage/JacocoClassLoader.java modified: src/edu/rice/cs/drjava/model/coverage/ReportGenerator.java modified: src/edu/rice/cs/drjava/model/junit/DefaultJUnitModel.java modified: src/edu/rice/cs/drjava/model/junit/JUnitModel.java modified: src/edu/rice/cs/drjava/model/junit/JUnitTestManager.java modified: src/edu/rice/cs/drjava/model/repl/InteractionsModelErrorTest.java modified: src/edu/rice/cs/drjava/model/repl/JavaInterpreterTest.java modified: src/edu/rice/cs/drjava/model/repl/newjvm/ClassPathManager.java modified: src/edu/rice/cs/drjava/model/repl/newjvm/InterpreterJVM.java modified: src/edu/rice/cs/drjava/ui/MainFrame.java modified: src/edu/rice/cs/drjava/ui/coverage/CoverageFrame.java modified: src/edu/rice/cs/drjava/ui/predictive/PredictiveInputFrame.java
1 parent b1b5dd6 commit a411d7f

20 files changed

Lines changed: 405 additions & 395 deletions

drjava/lib/jacocoant.jar

-4.28 KB
Binary file not shown.

drjava/src/edu/rice/cs/drjava/model/AbstractGlobalModel.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,10 @@ public File getWorkingDirectory() {
10021002
return prefWorkDir;
10031003
}
10041004

1005-
// otherwise determine the working directory based on the source root
1005+
// otherwise determine the working directory based on the source root of current document
10061006
File file = FileOps.NULL_FILE;
10071007
try {
1008-
file = getActiveDocument().getSourceRoot(); // source root of the current document
1008+
file = getActiveDocument().getSourceRoot();
10091009
}
10101010
catch(InvalidPackageException ipe) { file = FileOps.NULL_FILE; }
10111011
if ((file != null) && (file != FileOps.NULL_FILE)) {
@@ -3495,11 +3495,10 @@ public boolean checkIfClassFileInSync() {
34953495
}
34963496
}
34973497

3498-
/** Returns the class file for this source document by searching the source
3499-
* roots of open documents, the system classpath, and the
3500-
* "extra.classpath ". Returns NULL_FILE if the class file could not be found.
3501-
* @return the class file for this source document
3502-
*/
3498+
/** Returns the class file for this source document by searching the source roots of open documents, the system
3499+
* classpath, and the "extra.classpath ". Returns NULL_FILE if the class file could not be found.
3500+
* @return the class file for this source document
3501+
*/
35033502
private File _locateClassFile() {
35043503
// TODO: define in terms of GlobalModel.getClassPath()
35053504

drjava/src/edu/rice/cs/drjava/model/DefaultGlobalModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ public void resetInteractionsClassPath() {
893893

894894
// add project source root to projectFilesClassPath. All files in project tree have this root.
895895

896-
_interactionsModel.addProjectFilesClassPath(getProjectRoot()); // is sync advisable here?
896+
_interactionsModel.addProjectFilesClassPath(getProjectRoot());
897897
setClassPathChanged(false); // reset classPathChanged state
898898
}
899899
}

drjava/src/edu/rice/cs/drjava/model/FindReplaceMachine.java

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ public class FindReplaceMachine {
5959
/* Visible machine state; manipulated directly or indirectly by FindReplacePanel. */
6060
private volatile OpenDefinitionsDocument _doc; // Current search document
6161
private volatile OpenDefinitionsDocument _firstDoc; // First document where searching started (when searching all documents)
62-
// private Position _current; // Position of the cursor in _doc when machine is stopped
63-
private volatile int _current; // Position of the cursor in _doc when machine is stopped
64-
private MovingDocumentRegion _selectionRegion; // selected text region
65-
// private Position _start; // Position in _doc from which searching started or will start.
62+
private volatile int _current; // Position of the cursor in _doc when machine is stopped
63+
private MovingDocumentRegion _selectionRegion; // selected text region
6664
private volatile String _findWord; // Word to find. */
6765
private volatile String _replaceWord; // Word to replace _findword.
6866
private volatile boolean _matchCase;
@@ -79,13 +77,11 @@ public class FindReplaceMachine {
7977
private volatile Component _frame;
8078

8179
/** Standard Constructor.
82-
* Creates new machine to perform find/replace operations on a particular
83-
* document starting from a given position.
84-
* @param model the model
85-
* @param docIterator an object that allows navigation through open Swing
86-
* documents (it is DefaultGlobalModel)
87-
* @param frame the frame
88-
*/
80+
* Creates new machine to perform find/replace operations on a particular document starting from a given position.
81+
* @param model the model
82+
* @param docIterator an object that allows navigation through open Swing documents (it is DefaultGlobalModel)
83+
* @param frame the frame
84+
*/
8985
public FindReplaceMachine(SingleDisplayModel model, DocumentIterator docIterator, Component frame) {
9086
_skipText = false;
9187
// _checkAllDocsWrapped = false;
@@ -163,9 +159,7 @@ public void setIgnoreTestCases(boolean ignoreTestCases) {
163159
public void setPosition(int pos) { _current = pos; }
164160

165161
/** @return the character offset to which this machine is currently pointing. */
166-
public int getCurrentOffset() { //return _current.getOffset();
167-
return _current;
168-
}
162+
public int getCurrentOffset() { return _current; }
169163

170164
public String getFindWord() { return _findWord; }
171165

@@ -229,9 +223,9 @@ public boolean onMatch() {
229223
}
230224

231225
/** If we're on a match for the find word, replace it with the replace word.
232-
* Only executes in event thread.
233-
* @return true if we're on a match; false otherwise
234-
*/
226+
* Only executes in event thread.
227+
* @return true if we're on a match; false otherwise
228+
*/
235229
public boolean replaceCurrent() {
236230

237231
assert EventQueue.isDispatchThread();
@@ -271,14 +265,16 @@ public boolean replaceCurrent() {
271265
*/
272266
public int replaceAll() { return replaceAll(_searchAllDocuments, _searchSelectionOnly); }
273267

274-
/** Replaces all occurences of the find word with the replace word in the
275-
* current document of in all documents or in the current selection of the
276-
* current document depending the value of the flag searchAll
277-
* @param searchAll true if we should search for occurrences in all documents
278-
* @param searchSelectionOnly true if we should only search in the current selection of documents
279-
* @return the number of replacements
280-
*/
268+
/** Replaces all occurences of the find word with the replace word in the current document of in all documents or in
269+
* the current selection depending the value of the flag searchAll
270+
* @param searchAll true if we should search for occurrences in all documents
271+
* @param searchSelectionOnly true if we should only search in the current selection of documents
272+
* @return the number of replacements
273+
*/
281274
private int replaceAll(boolean searchAll, boolean searchSelectionOnly) {
275+
276+
assert EventQueue.isDispatchThread();
277+
282278
if (searchAll) {
283279
int count = 0; // the number of replacements done so far
284280
int n = _docIterator.getDocumentCount();
@@ -343,14 +339,16 @@ private int _replaceAllInCurrentDoc(boolean searchSelectionOnly) {
343339
return count;
344340
}
345341

346-
/** Processes all occurences of the find word with the replace word in the
347-
* current document or in all documents depending the value of the machine
348-
* register _searchAllDocuments.
349-
* @param findAction action to perform on the occurrences; input is the FindResult, output is ignored
350-
* @param region the selection region
351-
* @return the number of processed occurrences
352-
*/
353-
public int processAll(Runnable1<FindResult> findAction, MovingDocumentRegion region) {
342+
/** Processes all occurences of the find word with the replace word in the current document or in all documents
343+
* depending the value of the machine register _searchAllDocuments.
344+
* @param findAction action to perform on the occurrences; input is the FindResult, output is ignored
345+
* @param region the selection region
346+
* @return the number of processed occurrences
347+
*/
348+
public int processAll(Runnable1<FindResult> findAction, MovingDocumentRegion region) {
349+
350+
assert EventQueue.isDispatchThread();
351+
354352
_selectionRegion = region;
355353
return processAll(findAction, _searchAllDocuments, _searchSelectionOnly);
356354
}
@@ -405,6 +403,9 @@ else if(searchSelectionOnly) {
405403
* @return the number of replacements
406404
*/
407405
private int _processAllInCurrentDoc(Runnable1<FindResult> findAction, boolean searchSelectionOnly) {
406+
407+
assert EventQueue.isDispatchThread();
408+
408409
if(!searchSelectionOnly) {
409410
_selectionRegion = new MovingDocumentRegion(_doc, 0, _doc.getLength(), _doc._getLineStartPos(0),
410411
_doc._getLineEndPos(_doc.getLength()));
@@ -486,6 +487,9 @@ private FindResult findNext(boolean searchAll) {
486487
* @return the next match in the specified document
487488
*/
488489
private FindResult _findNextInDoc(OpenDefinitionsDocument doc, int start, int len, boolean searchAll) {
490+
491+
assert EventQueue.isDispatchThread();
492+
489493
// search from current position to "end" of document ("end" is start if searching backward)
490494
// Utilities.show("_findNextInDoc([" + doc.getText() + "], " + start + ", " + len + ", " + searchAll + ")");
491495
// _log.log("_findNextInDoc([" + doc.getText() + "], " + start + ", " + len + ", " + searchAll + ")");
@@ -506,6 +510,8 @@ private FindResult _findNextInDoc(OpenDefinitionsDocument doc, int start, int le
506510
*/
507511
private FindResult _findWrapped(OpenDefinitionsDocument doc, int start, int len, boolean allWrapped) {
508512

513+
assert EventQueue.isDispatchThread();
514+
509515
final int docLen = doc.getLength();
510516
if (docLen == 0) return new FindResult(doc, -1, true, allWrapped); // failure result
511517

@@ -563,6 +569,9 @@ private FindResult _findNextInDocSegment(final OpenDefinitionsDocument doc, fina
563569
final boolean wrapped, final boolean allWrapped) {
564570
// Utilities.show("called _findNextInDocSegment(" + doc.getText() + ",\n" + start + ", " + len + ", " + wrapped +
565571
// " ...)");
572+
573+
assert EventQueue.isDispatchThread();
574+
566575
boolean inTestCase = false;
567576
for(String ext: OptionConstants.LANGUAGE_LEVEL_EXTENSIONS) {
568577
inTestCase |= doc.getFileName().endsWith("Test"+ext);
@@ -659,6 +668,8 @@ private FindResult _findNextInDocSegment(final OpenDefinitionsDocument doc, fina
659668
*/
660669
private FindResult _findNextInOtherDocs(final OpenDefinitionsDocument startDoc, int start, int len) {
661670

671+
assert EventQueue.isDispatchThread();
672+
662673
// System.err.println("_findNextInOtherDocs(" + startDoc.getText() + ", " + start + ", " + len + ")");
663674

664675
boolean allWrapped = false;
@@ -700,7 +711,9 @@ private FindResult _findNextInOtherDocs(final OpenDefinitionsDocument startDoc,
700711
* @param foundOffset - the position where that instance was found
701712
* @return true if the whole word is found at foundOffset, false otherwise
702713
*/
703-
private boolean wholeWordFoundAtCurrent(OpenDefinitionsDocument doc, int foundOffset) {
714+
private boolean wholeWordFoundAtCurrent(OpenDefinitionsDocument doc, int foundOffset) {
715+
716+
assert EventQueue.isDispatchThread();
704717

705718
char leftOfMatch = 0; // forced initialization
706719
char rightOfMatch = 0; // forced initialization

drjava/src/edu/rice/cs/drjava/model/GlobalModelJUnitTest.java

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import java.io.File;
4040
import java.io.IOException;
41+
import java.util.Arrays;
4142
import java.util.List;
4243

4344
import edu.rice.cs.drjava.model.compiler.CompilerListener;
@@ -51,7 +52,7 @@
5152
*/
5253
public final class GlobalModelJUnitTest extends GlobalModelTestCase {
5354

54-
private static Log _log = new Log("GlobalModelJUnit.txt", false);
55+
private static Log _log = new Log("GlobalModelTest.txt", true);
5556

5657
/** Whether or not to print debugging output. */
5758
static final boolean printMessages = true;
@@ -186,14 +187,9 @@ public final class GlobalModelJUnitTest extends GlobalModelTestCase {
186187
" }";
187188

188189

189-
// /** Creates a test suite for JUnit to run.
190-
// * @return a test suite based on the methods in this class
191-
// */
192-
// public static Test suite() { return new TestSuite(GlobalModelJUnitTest.class); }
193-
194190
/** Tests that a JUnit file with no errors is reported to have no errors.
195-
* @throws Exception if something goes wrong
196-
*/
191+
* @throws Exception if something goes wrong
192+
*/
197193
public void testNoJUnitErrors_NOJOIN() throws Exception {
198194
_log.log("----testNoJUnitErrors-----");
199195
// Utilities.show("Running testNoJUnitErrors");
@@ -324,7 +320,7 @@ public void testNonTestCaseError_NOJOIN() throws Exception {
324320

325321
// Check events fired
326322
listener.assertJUnitStartCount(0); // JUnit is never started
327-
listener.assertJUnitEndCount(0); // JUnit never started and hence never ended
323+
listener.assertJUnitEndCount(0); // JUnit never started and hence never ended
328324
listener.assertNonTestCaseCount(1);
329325
listener.assertJUnitSuiteStartedCount(0);
330326
listener.assertJUnitTestStartedCount(0);
@@ -334,9 +330,9 @@ public void testNonTestCaseError_NOJOIN() throws Exception {
334330
_log.log("testNonTestCaseError completed");
335331
}
336332

337-
/** Tests that the ui is notified to put up an error dialog if JUnit is run on a non-public TestCase.
338-
* @throws Exception if something goes wrong
339-
*/
333+
/** Tests that the UI is notified to put up an error dialog if JUnit is run on a non-public TestCase.
334+
* @throws Exception if something goes wrong
335+
*/
340336
public void testResultOfNonPublicTestCase_NOJOIN() throws Exception {
341337
_log.log("----testResultOfNonPublicTestCase-----");
342338
// Utilities.show("Running testResultOfNonPublicTestCase");
@@ -394,8 +390,8 @@ public void testResultOfNonPublicTestCase_NOJOIN() throws Exception {
394390
// }
395391

396392
/** Tests a document that has no corresponding class file.
397-
* @throws Exception if something goes wrong
398-
*/
393+
* @throws Exception if something goes wrong
394+
*/
399395
public void testNoClassFile() throws Exception {
400396
_log.log("----testNoClassFile-----");
401397
// Utilities.show("Running testNoClassFile");
@@ -779,7 +775,7 @@ public void testCorrectFilesAfterIncorrectChanges_NOJOIN() throws Exception {
779775
final OpenDefinitionsDocument doc1 = setupDocument(MULTI_CLASSES_IN_FILE_TEXT);
780776
final File file = new File(_tempDir, "DJTest.java");
781777
saveFile(doc1, new FileSelector(file));
782-
_log.log("In testCorrectFilesAfterIncorrectChanges_NOJOIN(), DJTest.java = \n" + doc1.getText());
778+
_log.log("In testCorrectFilesAfterIncorrectChanges, DJTest.java = \n" + doc1.getText());
783779

784780
final JUnitNonTestListener listener1 = new JUnitNonTestListener(true);
785781
_model.addListener(listener1);
@@ -814,8 +810,8 @@ public void testCorrectFilesAfterIncorrectChanges_NOJOIN() throws Exception {
814810

815811

816812
/** Tests if a JUnit4 style unit test works.
817-
* @throws Exception if something goes wrong
818-
*/
813+
* @throws Exception if something goes wrong
814+
*/
819815
public void testJUnit4StyleTestWorks_NOJOIN() throws Exception {
820816

821817
_log.log("----testJUnit4StyleTestWorks-----");
@@ -832,18 +828,19 @@ public void testJUnit4StyleTestWorks_NOJOIN() throws Exception {
832828
listener.checkCompileOccurred();
833829

834830
listener.runJUnit(doc);
831+
_log.log("errors: " + Arrays.toString(_model.getJUnitModel().getJUnitErrorModel().getErrors()));
832+
835833
// runJUnit waits until the thread started in DefaultJUnitModel._rawJUnitOpenDefDocs has called notify
836834

837835
listener.assertJUnitStartCount(1);
838836

839-
_log.log("errors: " + _model.getJUnitModel().getJUnitErrorModel());
840-
837+
841838
listener.assertNonTestCaseCount(0);
842839
assertEquals("test case should have no errors reported", 0,
843840
_model.getJUnitModel().getJUnitErrorModel().getNumErrors());
844841

845842
_model.removeListener(listener);
846-
_log.log("testJUnit4StyleTestWorks completed");
843+
_log.log("----testJUnit4StyleTestWorks completed");
847844
}
848845

849846
/** Tests to see if a JUnit4 style test with multiple test cases passes.
@@ -867,9 +864,9 @@ public void testJUnit4MultiTest_NOJOIN() throws Exception {
867864
listener.runJUnit(doc);
868865
// runJUnit waits until the thread started in DefaultJUnitModel._rawJUnitOpenDefDocs has called notify
869866

870-
listener.assertJUnitStartCount(1);
867+
_log.log("errors: " + Arrays.toString(_model.getJUnitModel().getJUnitErrorModel().getErrors()));
871868

872-
_log.log("errors: " + _model.getJUnitModel().getJUnitErrorModel());
869+
listener.assertJUnitStartCount(1);
873870

874871
listener.assertNonTestCaseCount(0);
875872
assertEquals("test case should have no errors reported", 0,
@@ -936,10 +933,9 @@ public void testJUnit4TwoMethod1Test_NOJOIN() throws Exception {
936933
listener.runJUnit(doc);
937934
// runJUnit waits until the thread started in DefaultJUnitModel._rawJUnitOpenDefDocs has called notify
938935

939-
listener.assertJUnitStartCount(1);
940-
941-
_log.log("errors: " + _model.getJUnitModel().getJUnitErrorModel());
936+
_log.log("errors: " + Arrays.toString(_model.getJUnitModel().getJUnitErrorModel().getErrors()));
942937

938+
listener.assertJUnitStartCount(1);
943939
listener.assertNonTestCaseCount(0);
944940
assertEquals("test case should have no errors reported", 0,
945941
_model.getJUnitModel().getJUnitErrorModel().getNumErrors());

0 commit comments

Comments
 (0)