Skip to content

Commit d80369d

Browse files
author
rcartwright
committed
Added some assertions in CommentTest.java to test for Bug 2959994
(uncomment lines on an empty file generated an internal DrJava error). Narrowed the exception catching types in a few exception handlers and the declared exception type for a few methods, and corrected a few indenting errors. The following files were modified: M src/edu/rice/cs/drjava/model/GlobalModelIOTest.java M src/edu/rice/cs/drjava/model/definitions/CommentTest.java M src/edu/rice/cs/drjava/model/definitions/DefinitionsDocument.java M src/edu/rice/cs/drjava/config/DrJavaPropertySetup.java M src/edu/rice/cs/drjava/ui/MainFrame.java M src/edu/rice/cs/util/FileOps.java git-svn-id: file:///tmp/test-svn/trunk@5185 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 9384fc3 commit d80369d

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

drjava/src/edu/rice/cs/drjava/config/DrJavaPropertySetup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public void update(PropertyMaps pm) {
450450
sb.append(File.pathSeparator);
451451
sb.append(StringOps.escapeFileName(s));
452452
}
453-
catch(Exception e) {
453+
catch(IOException e) {
454454
_value = "(file.rel I/O Error...)";
455455
return;
456456
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public void testOpenNonexistentFile() throws IOException {
275275
fail("Open was unexpectedly canceled!");
276276
}
277277

278-
assertEquals("non-existant file", doc, null);
278+
assertEquals("doc file should be non-existent", doc, null);
279279

280280
_log.log("testOpenNonexistentFile completed");
281281
}
@@ -514,7 +514,7 @@ public void testOpenMultipleFilesError() {
514514
catch (IOException e) { /* As we expected, the file was not found. */ }
515515
catch (Exception e) { fail("Unexpectedly exception caught!"); }
516516

517-
assertTrue("non-existent file", docs == null);
517+
assertEquals("no doc files should be open", null, docs);
518518

519519
_log.log("testOpenMultipleFilesError completed");
520520
}

drjava/src/edu/rice/cs/drjava/model/definitions/CommentTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,17 @@
4444

4545
import javax.swing.text.BadLocationException;
4646

47-
/**
48-
* Test the comment lines / uncomment lines functionality.
49-
* @version $Id$
50-
*/
47+
/** Test the comment lines / uncomment lines functionality.
48+
* @version $Id$
49+
*/
5150
public final class CommentTest extends DrJavaTestCase {
5251
protected DefinitionsDocument doc;
5352
private Integer _indentLevel = Integer.valueOf(2);
5453
private GlobalEventNotifier _notifier;
5554

5655
/** Resents configuration settings and sets up the indent level so that we
57-
* can predict the correct behavior for indenting.
58-
*/
56+
* can predict the correct behavior for indenting.
57+
*/
5958
public void setUp() throws Exception {
6059
super.setUp();
6160
DrJava.getConfig().resetToDefaults();
@@ -64,8 +63,7 @@ public void setUp() throws Exception {
6463
DrJava.getConfig().setSetting(OptionConstants.INDENT_LEVEL,_indentLevel);
6564
}
6665

67-
/** Tests the Comment Out Line(s) command with a single line.
68-
*/
66+
/** Tests the Comment Out Line(s) command with a single line. */
6967
public void testCommentOutSingleLine() throws BadLocationException {
7068
String text =
7169
"Here is some abritrary text that should be commented.\n" +
@@ -83,8 +81,7 @@ public void testCommentOutSingleLine() throws BadLocationException {
8381
_assertContents("Only the second line should be wing-commented!", commented, doc);
8482
}
8583

86-
/** Tests the Comment Out Line(s) command with multiple lines.
87-
*/
84+
/** Tests the Comment Out Line(s) command with multiple lines. */
8885
public void testCommentOutMultipleLines() throws BadLocationException {
8986
String text =
9087
"Here is some abritrary text that should be commented.\n" +
@@ -103,17 +100,22 @@ public void testCommentOutMultipleLines() throws BadLocationException {
103100
}
104101

105102
/** Tests the Uncomment Line(s) command with a single line.
106-
* These sample lines should be ignored by the algorithm.
107-
*/
103+
* These sample lines should be ignored by the algorithm.
104+
*/
108105
public void testUncommentIgnoreSingleLine() throws BadLocationException {
109-
String text =
106+
doc.uncommentLines(0,0);
107+
_assertContents("Uncommenting an empty document should not cause an error", "", doc);
108+
109+
String text =
110110
"Here is some abritrary text that should not be uncommented.\n" +
111111
"/* It is on multiple lines, and contains slashes // and other\n" +
112112
"* various */ obnoxious characters,\n" +
113113
"sometimes // in block comments and sometimes not.";
114114

115115
doc.insertString(0, text, null);
116116
_assertContents("Sample text is inserted improperly.", text, doc);
117+
doc.uncommentLines(0,0);
118+
_assertContents("Uncommenting an uncommented line should not cause an error or modify the text", text, doc);
117119
doc.uncommentLines(70, 75);
118120
_assertContents("These lines should be unchanged by uncomment!", text, doc);
119121
}

drjava/src/edu/rice/cs/drjava/model/definitions/DefinitionsDocument.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ private int _uncommentLine() throws BadLocationException {
478478
// Utilities.show("Preceding char = '" + getText().charAt(_currentLocation - 1) + "'");
479479
// Utilities.show("Line = \n" + getText(_currentLocation, getLineEndPos(_currentLocation) - _currentLocation + 1));
480480
int pos1 = getText().indexOf("//", _currentLocation); // TODO: get text of current line instead of whole document
481-
if (pos1==-1) return NO_COMMENT_OFFSET;
481+
if (pos1 < 0) return NO_COMMENT_OFFSET;
482482
int pos2 = getFirstNonWSCharPos(_currentLocation, true);
483483
// Utilities.show("Pos1 = " + pos1 + " Pos2 = " + pos2);
484484
if (pos1 != pos2) return NO_COMMENT_OFFSET;

drjava/src/edu/rice/cs/drjava/ui/MainFrame.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ public String value(GoToFileListEntry entry) {
12721272
catch(IOException e) { sb.append(entry.doc.getFile()); }
12731273
}
12741274
catch(edu.rice.cs.drjava.model.FileMovedException e) { sb.append(entry + " was moved"); }
1275-
catch(java.lang.IllegalStateException e) { sb.append(entry); }
1275+
// catch(java.lang.IllegalStateException e) { sb.append(entry); }
12761276
catch(InvalidPackageException e) { sb.append(entry); }
12771277
}
12781278
else sb.append(entry);

drjava/src/edu/rice/cs/util/FileOps.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public static File makeRelativeTo(File f, File b) throws IOException, SecurityEx
197197
* @return A new file whose path is relative to the base file while the value of <code>getCanonicalPath()</code>
198198
* for the returned file is the same as the result of <code>getCanonicalPath()</code> for the given file.
199199
*/
200-
public static String stringMakeRelativeTo(File f, File b) throws IOException, SecurityException {
200+
public static String stringMakeRelativeTo(File f, File b) throws IOException /*, SecurityException */ {
201201
try {
202202

203203
File[] roots = File.listRoots();

0 commit comments

Comments
 (0)