Skip to content

Commit aa08c09

Browse files
committed
Improve asserts in jface.text.tests
Overall replacing assertTrue/False(a==/!=b) which give suboptimal messages on failure with more specific assertions.
1 parent ace2db2 commit aa08c09

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractPairMatcherTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package org.eclipse.jface.text.tests;
1515

1616
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertFalse;
17+
import static org.junit.Assert.assertNotEquals;
1818
import static org.junit.Assert.assertNotNull;
1919
import static org.junit.Assert.assertNull;
2020
import static org.junit.Assert.assertTrue;
@@ -378,7 +378,7 @@ private void performMatch(final String delims, final String testCase) {
378378
*/
379379
public TestCase createTestCase(String str) {
380380
int pos1= str.indexOf('%');
381-
assertFalse(pos1 == -1);
381+
assertNotEquals(-1, pos1);
382382
int pos2= str.lastIndexOf('%');
383383
boolean selectionTest= pos1 != pos2;
384384

@@ -389,7 +389,7 @@ public TestCase createTestCase(String str) {
389389
// account for the length of marker characters
390390
if (selectionTest) {
391391
if (!enclosingTest) {
392-
assertTrue(pos2 - pos1 == 2);
392+
assertEquals(2, pos2 - pos1);
393393
if (match1 != -1 && match1 < pos1) {
394394
pos1-= 1;
395395
pos2-= 2;

org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/AbstractUndoManagerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import static org.junit.Assert.assertEquals;
1717
import static org.junit.Assert.assertFalse;
18+
import static org.junit.Assert.assertNotEquals;
1819
import static org.junit.Assert.assertTrue;
1920

2021
import org.junit.After;
@@ -438,7 +439,7 @@ public void testDocumentStamp2() throws BadLocationException {
438439
long stamp= document.getModificationStamp();
439440
fUndoManager.undo();
440441
document.replace(0, 0, createRandomString(stringLength));
441-
assertFalse(stamp == document.getModificationStamp());
442+
assertNotEquals(stamp, document.getModificationStamp());
442443

443444
}
444445

org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextHoverPopupTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.jface.text.tests;
1515

16-
import static org.junit.Assert.assertTrue;
16+
import static org.junit.Assert.assertEquals;
1717

1818
import org.junit.Test;
1919

@@ -42,13 +42,13 @@ public void testSearch() {
4242
int[] values= { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
4343
for (int i= 0; i < 10; i++) {
4444
int result= search(values, i);
45-
assertTrue(i == result);
45+
assertEquals(i, result);
4646
}
4747

4848
int[] values2= { 0, 3, 6, 9, 12, 15, 18, 21, 24, 27 };
4949
for (int i= 0; i < 10; i++) {
5050
int result= search(values2, i * 3);
51-
assertTrue(i == result);
51+
assertEquals(i, result);
5252
}
5353
}
5454
}

org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/contentassist/FilteringAsyncContentAssistTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import static java.util.Collections.singletonList;
1414
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertNotNull;
1516
import static org.junit.Assert.assertTrue;
1617

1718
import java.lang.reflect.Field;
@@ -269,7 +270,7 @@ public void testCA_WithFirstDelayedThenImmediateProposals() throws Exception {
269270

270271
List<ICompletionProposal> filteredProposals= getFilteredProposals(ca,
271272
p -> p instanceof IncompleteCompletionProposal);
272-
assertTrue(filteredProposals != null);
273+
assertNotNull(filteredProposals);
273274
assertEquals(1, filteredProposals.size());
274275

275276
filteredProposals.get(0).apply(document);
@@ -350,7 +351,7 @@ public void testProposalValidation() throws Exception {
350351

351352
List<ICompletionProposal> filteredProposals= getFilteredProposals(ca,
352353
p -> p instanceof CompletionProposal);
353-
assertTrue(filteredProposals != null);
354+
assertNotNull(filteredProposals);
354355
assertEquals(1, filteredProposals.size());
355356

356357
filteredProposals.get(0).apply(document);

org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/rules/WordRuleTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.jface.text.tests.rules;
1515

16+
import static org.junit.Assert.assertEquals;
1617
import static org.junit.Assert.assertSame;
1718
import static org.junit.Assert.assertTrue;
1819

@@ -72,7 +73,7 @@ public boolean isWordStart(char c) {
7273
WordRule rule= new WordRule(detector, new Token(this));
7374

7475
RuleBasedScanner scanner= new RuleBasedScanner();
75-
scanner.setRules(new IRule[] { rule });
76+
scanner.setRules(rule);
7677
scanner.setRange(new Document(), 0, 0);
7778

7879
IToken token= null;
@@ -106,25 +107,25 @@ public void testBug144355() throws Exception {
106107
// pre: pass in a normal string ("TestTokenString")
107108
// post: expect the normal token to be returned
108109
RuleBasedScanner scanner= new RuleBasedScanner();
109-
scanner.setRules(new IRule[] {rule});
110+
scanner.setRules(rule);
110111
scanner.setRange(new Document(testTokenStringNormal), 0, testTokenStringNormal.length());
111-
assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
112+
assertEquals(testTokenStringNormal, scanner.nextToken().getData());
112113

113114
// scenario 2
114115
// pre: pass in a normal string but different capitalization ("TestTOKENString")
115116
// post: expect the normal token to be returned
116117
scanner= new RuleBasedScanner();
117-
scanner.setRules(new IRule[] {rule});
118+
scanner.setRules(rule);
118119
scanner.setRange(new Document(testTokenStringDifferentCapitalization), 0, testTokenStringDifferentCapitalization.length());
119-
assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
120+
assertEquals(testTokenStringNormal, scanner.nextToken().getData());
120121

121122
// scenario 3
122123
// pre: pass in a completely different string ("XXX")
123124
// post: expect the default token to be returned because the string can't be matched
124125
scanner= new RuleBasedScanner();
125-
scanner.setRules(new IRule[] {rule});
126+
scanner.setRules(rule);
126127
scanner.setRange(new Document(testTokenStringCompletelyDifferent), 0, testTokenStringCompletelyDifferent.length());
127-
assertTrue(scanner.nextToken().getData().equals(defaultTokenString));
128+
assertEquals(defaultTokenString, scanner.nextToken().getData());
128129

129130
WordRule ruleWithoutIgnoreCase= new WordRule(detector, defaultToken);
130131
ruleWithoutIgnoreCase.addWord(testTokenStringNormal, normalToken);
@@ -133,17 +134,17 @@ public void testBug144355() throws Exception {
133134
// pre: pass in a normal string ("TestTokenString")
134135
// post: expect the normal token to be returned
135136
scanner= new RuleBasedScanner();
136-
scanner.setRules(new IRule[] {ruleWithoutIgnoreCase});
137+
scanner.setRules(ruleWithoutIgnoreCase);
137138
scanner.setRange(new Document(testTokenStringNormal), 0, testTokenStringNormal.length());
138-
assertTrue(scanner.nextToken().getData().equals(testTokenStringNormal));
139+
assertEquals(testTokenStringNormal, scanner.nextToken().getData());
139140

140141
// scenario 5
141142
// pre: pass in a normal string but different capitalization ("TestTOKENString")
142143
// post: expect the default token to be returned
143144
scanner= new RuleBasedScanner();
144-
scanner.setRules(new IRule[] {ruleWithoutIgnoreCase});
145+
scanner.setRules(ruleWithoutIgnoreCase);
145146
scanner.setRange(new Document(testTokenStringDifferentCapitalization), 0, testTokenStringDifferentCapitalization.length());
146-
assertTrue(scanner.nextToken().getData().equals(defaultTokenString));
147+
assertEquals(defaultTokenString, scanner.nextToken().getData());
147148
}
148149

149150
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175712

0 commit comments

Comments
 (0)