Skip to content

Commit 381cb7e

Browse files
authored
Refactor MarkOccurrenceTest to JUnit5 style (#730)
This was completed so I could best investigate #729 (comment)
1 parent 221d346 commit 381cb7e

File tree

1 file changed

+45
-49
lines changed

1 file changed

+45
-49
lines changed

core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/MarkOccurrenceTest.java

+45-49
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2014 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,6 +14,11 @@
1414
*******************************************************************************/
1515
package org.eclipse.cdt.ui.tests.text;
1616

17+
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertTrue;
20+
import static org.junit.jupiter.api.Assertions.fail;
21+
1722
import java.util.Iterator;
1823

1924
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
@@ -27,7 +32,7 @@
2732
import org.eclipse.cdt.ui.PreferenceConstants;
2833
import org.eclipse.cdt.ui.testplugin.DisplayHelper;
2934
import org.eclipse.cdt.ui.testplugin.EditorTestHelper;
30-
import org.eclipse.cdt.ui.tests.BaseUITestCase;
35+
import org.eclipse.cdt.ui.tests.BaseUITestCase5;
3136
import org.eclipse.core.resources.IFile;
3237
import org.eclipse.core.resources.ResourcesPlugin;
3338
import org.eclipse.core.runtime.IPath;
@@ -53,17 +58,16 @@
5358
import org.eclipse.ui.editors.text.EditorsUI;
5459
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
5560
import org.eclipse.ui.texteditor.AnnotationPreference;
56-
57-
import junit.extensions.TestSetup;
58-
import junit.framework.Test;
59-
import junit.framework.TestSuite;
61+
import org.junit.jupiter.api.AfterEach;
62+
import org.junit.jupiter.api.BeforeEach;
63+
import org.junit.jupiter.api.Test;
6064

6165
/**
6266
* Tests the C/C++ Editor's occurrence marking feature.
6367
*
6468
* @since 5.0
6569
*/
66-
public class MarkOccurrenceTest extends BaseUITestCase {
70+
public class MarkOccurrenceTest extends BaseUITestCase5 {
6771
private static final String PROJECT = "MarkOccurrenceTest";
6872

6973
private static final String OCCURRENCE_ANNOTATION = "org.eclipse.cdt.ui.occurrences";
@@ -82,44 +86,11 @@ public class MarkOccurrenceTest extends BaseUITestCase {
8286
private IRegion fMatch;
8387
private StyledText fTextWidget;
8488

85-
private MarkOccurrenceTestSetup fProjectSetup;
86-
87-
protected static class MarkOccurrenceTestSetup extends TestSetup {
88-
private ICProject fCProject;
89-
90-
public MarkOccurrenceTestSetup(Test test) {
91-
super(test);
92-
}
89+
private ICProject fCProject;
9390

94-
@Override
95-
protected void setUp() throws Exception {
96-
super.setUp();
97-
fCProject = EditorTestHelper.createCProject(PROJECT, "resources/ceditor", false, true);
98-
}
99-
100-
@Override
101-
protected void tearDown() throws Exception {
102-
if (fCProject != null)
103-
CProjectHelper.delete(fCProject);
104-
105-
super.tearDown();
106-
}
107-
}
108-
109-
public static Test setUpTest(Test someTest) {
110-
return new MarkOccurrenceTestSetup(someTest);
111-
}
112-
113-
public static Test suite() {
114-
return setUpTest(new TestSuite(MarkOccurrenceTest.class));
115-
}
116-
117-
@Override
118-
protected void setUp() throws Exception {
119-
if (!ResourcesPlugin.getWorkspace().getRoot().exists(new Path(PROJECT))) {
120-
fProjectSetup = new MarkOccurrenceTestSetup(this);
121-
fProjectSetup.setUp();
122-
}
91+
@BeforeEach
92+
protected void setUpMarkOccurenceTest() throws Exception {
93+
fCProject = EditorTestHelper.createCProject(PROJECT, "resources/ceditor", false, true);
12394
assertNotNull(fgHighlightRGB);
12495
assertNotNull(fgWriteHighlightRGB);
12596
final IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
@@ -161,8 +132,8 @@ private synchronized void countOccurrences() {
161132
SelectionListenerWithASTManager.getDefault().addListener(fEditor, fSelWASTListener);
162133
}
163134

164-
@Override
165-
protected void tearDown() throws Exception {
135+
@AfterEach
136+
protected void tearDownMarkOccurenceTest() throws Exception {
166137
final IPreferenceStore store = CUIPlugin.getDefault().getPreferenceStore();
167138
store.setToDefault(PreferenceConstants.EDITOR_MARK_OCCURRENCES);
168139
// TLETODO temporary fix for bug 314635
@@ -171,9 +142,7 @@ protected void tearDown() throws Exception {
171142
+ PreferenceConstants.EDITOR_SEMANTIC_HIGHLIGHTING_ENABLED_SUFFIX);
172143
SelectionListenerWithASTManager.getDefault().removeListener(fEditor, fSelWASTListener);
173144
EditorTestHelper.closeAllEditors();
174-
if (fProjectSetup != null) {
175-
fProjectSetup.tearDown();
176-
}
145+
CProjectHelper.delete(fCProject);
177146
}
178147

179148
private CEditor openCEditor(IPath path) {
@@ -187,6 +156,7 @@ private CEditor openCEditor(IPath path) {
187156
}
188157
}
189158

159+
@Test
190160
public void testMarkTypeOccurrences() {
191161
try {
192162
fMatch = fFindReplaceDocumentAdapter.find(0, "ClassContainer", true, true, true, false);
@@ -201,6 +171,7 @@ public void testMarkTypeOccurrences() {
201171
assertOccurrencesInWidget();
202172
}
203173

174+
@Test
204175
public void testMarkTypeOccurrences2() {
205176
try {
206177
fMatch = fFindReplaceDocumentAdapter.find(0, "Base1", true, true, true, false);
@@ -215,6 +186,7 @@ public void testMarkTypeOccurrences2() {
215186
assertOccurrencesInWidget();
216187
}
217188

189+
@Test
218190
public void testMarkTypeOccurrences3() {
219191
try {
220192
fMatch = fFindReplaceDocumentAdapter.find(0, "Base2", true, true, true, false);
@@ -229,6 +201,7 @@ public void testMarkTypeOccurrences3() {
229201
assertOccurrencesInWidget();
230202
}
231203

204+
@Test
232205
public void testMarkTypedefOccurrences() {
233206
try {
234207
fMatch = fFindReplaceDocumentAdapter.find(0, "size_t", true, true, true, false);
@@ -243,6 +216,7 @@ public void testMarkTypedefOccurrences() {
243216
assertOccurrencesInWidget();
244217
}
245218

219+
@Test
246220
public void testMarkClassTemplateOccurrences() {
247221
try {
248222
fMatch = fFindReplaceDocumentAdapter.find(0, "TemplateClass", true, true, true, false);
@@ -257,6 +231,7 @@ public void testMarkClassTemplateOccurrences() {
257231
assertOccurrencesInWidget();
258232
}
259233

234+
@Test
260235
public void testMarkTemplateParameterOccurrences() {
261236
try {
262237
fMatch = fFindReplaceDocumentAdapter.find(0, "T1", true, true, true, false);
@@ -271,6 +246,7 @@ public void testMarkTemplateParameterOccurrences() {
271246
assertOccurrencesInWidget();
272247
}
273248

249+
@Test
274250
public void testMarkTemplateIdOccurrences() {
275251
try {
276252
fMatch = fFindReplaceDocumentAdapter.find(0, "ConstantTemplate", true, true, true, false);
@@ -285,6 +261,7 @@ public void testMarkTemplateIdOccurrences() {
285261
assertOccurrencesInWidget();
286262
}
287263

264+
@Test
288265
public void testMarkOccurrencesAfterEditorReuse() {
289266
IPreferenceStore store = PlatformUI.getWorkbench().getPreferenceStore();
290267
store.setValue("REUSE_OPEN_EDITORS_BOOLEAN", true);
@@ -317,6 +294,7 @@ public void testMarkOccurrencesAfterEditorReuse() {
317294
store.setValue("REUSE_OPEN_EDITORS", reuseOpenEditors);
318295
}
319296

297+
@Test
320298
public void testMarkMethodOccurrences() {
321299
try {
322300
fMatch = fFindReplaceDocumentAdapter.find(0, "pubMethod", true, true, true, false);
@@ -331,6 +309,7 @@ public void testMarkMethodOccurrences() {
331309
assertOccurrencesInWidget();
332310
}
333311

312+
@Test
334313
public void testMarkMethodOccurrences2() {
335314
try {
336315
fMatch = fFindReplaceDocumentAdapter.find(0, "getNumber", true, true, true, false);
@@ -345,6 +324,7 @@ public void testMarkMethodOccurrences2() {
345324
assertOccurrencesInWidget();
346325
}
347326

327+
@Test
348328
public void testMarkFieldOccurrences() {
349329
try {
350330
fMatch = fFindReplaceDocumentAdapter.find(0, "pubField", true, true, true, false);
@@ -359,6 +339,7 @@ public void testMarkFieldOccurrences() {
359339
assertOccurrencesInWidget();
360340
}
361341

342+
@Test
362343
public void testMarkFieldOccurrences2() {
363344
try {
364345
fMatch = fFindReplaceDocumentAdapter.find(0, "tArg1", true, true, true, false);
@@ -373,6 +354,7 @@ public void testMarkFieldOccurrences2() {
373354
assertOccurrencesInWidget();
374355
}
375356

357+
@Test
376358
public void testMarkConstructorOccurrences() {
377359
try {
378360
fMatch = fFindReplaceDocumentAdapter.find(0, "Base1(", true, true, false, false);
@@ -388,6 +370,7 @@ public void testMarkConstructorOccurrences() {
388370
assertOccurrencesInWidget();
389371
}
390372

373+
@Test
391374
public void testMarkDestructorOccurrences() {
392375
try {
393376
fMatch = fFindReplaceDocumentAdapter.find(0, "~Base1", true, true, false, false);
@@ -403,6 +386,7 @@ public void testMarkDestructorOccurrences() {
403386
assertOccurrencesInWidget();
404387
}
405388

389+
@Test
406390
public void testMarkLocalOccurrences() {
407391
try {
408392
fMatch = fFindReplaceDocumentAdapter.find(0, "localVar", true, true, true, false);
@@ -417,6 +401,7 @@ public void testMarkLocalOccurrences() {
417401
assertOccurrencesInWidget();
418402
}
419403

404+
@Test
420405
public void testMarkMacroOccurrences() {
421406
try {
422407
fMatch = fFindReplaceDocumentAdapter.find(0, "INT", true, true, true, false);
@@ -431,6 +416,7 @@ public void testMarkMacroOccurrences() {
431416
assertOccurrencesInWidget();
432417
}
433418

419+
@Test
434420
public void testMarkEmptyMacroOccurrences() {
435421
try {
436422
fMatch = fFindReplaceDocumentAdapter.find(0, "EMPTY_MACRO", true, true, true, false);
@@ -445,6 +431,7 @@ public void testMarkEmptyMacroOccurrences() {
445431
assertOccurrencesInWidget();
446432
}
447433

434+
@Test
448435
public void testMarkEnumeratorOccurrences() {
449436
try {
450437
fMatch = fFindReplaceDocumentAdapter.find(0, "ONE", true, true, true, false);
@@ -459,6 +446,7 @@ public void testMarkEnumeratorOccurrences() {
459446
assertOccurrencesInWidget();
460447
}
461448

449+
@Test
462450
public void testMarkNamespaceOccurrences() {
463451
try {
464452
fMatch = fFindReplaceDocumentAdapter.find(0, "ns", true, true, true, false);
@@ -473,6 +461,7 @@ public void testMarkNamespaceOccurrences() {
473461
assertOccurrencesInWidget();
474462
}
475463

464+
@Test
476465
public void testMarkNamespaceVariableOccurrences() {
477466
try {
478467
fMatch = fFindReplaceDocumentAdapter.find(0, "namespaceVar", true, true, true, false);
@@ -487,6 +476,7 @@ public void testMarkNamespaceVariableOccurrences() {
487476
assertOccurrencesInWidget();
488477
}
489478

479+
@Test
490480
public void testMarkLabelOccurrences() {
491481
try {
492482
fMatch = fFindReplaceDocumentAdapter.find(0, "label", true, true, true, false);
@@ -501,6 +491,7 @@ public void testMarkLabelOccurrences() {
501491
assertOccurrencesInWidget();
502492
}
503493

494+
@Test
504495
public void testMarkOperatorOccurrences() {
505496
try {
506497
fMatch = fFindReplaceDocumentAdapter.find(0, "operator+", true, true, false, false);
@@ -515,6 +506,7 @@ public void testMarkOperatorOccurrences() {
515506
assertOccurrencesInWidget();
516507
}
517508

509+
@Test
518510
public void testNoOccurrencesIfDisabled() {
519511
CUIPlugin.getDefault().getPreferenceStore().setValue(PreferenceConstants.EDITOR_MARK_OCCURRENCES, false);
520512
fOccurrences = Integer.MAX_VALUE;
@@ -531,6 +523,7 @@ public void testNoOccurrencesIfDisabled() {
531523
assertOccurrencesInWidget();
532524
}
533525

526+
@Test
534527
public void testMarkLabelReference() {
535528
try {
536529
fMatch = fFindReplaceDocumentAdapter.find(0, "labelPointer", true, true, true, false);
@@ -544,6 +537,7 @@ public void testMarkLabelReference() {
544537
assertOccurrencesInWidget();
545538
}
546539

540+
@Test
547541
public void testMarkReferencedLabel() {
548542
try {
549543
fMatch = fFindReplaceDocumentAdapter.find(0, "referencedLabel", true, true, true, false);
@@ -557,6 +551,7 @@ public void testMarkReferencedLabel() {
557551
assertOccurrencesInWidget();
558552
}
559553

554+
@Test
560555
public void testMarkReferencedStructuredBindingDefinition() {
561556
try {
562557
fMatch = fFindReplaceDocumentAdapter.find(0, "decomposedF", true, true, true, false);
@@ -570,6 +565,7 @@ public void testMarkReferencedStructuredBindingDefinition() {
570565
assertOccurrencesInWidget();
571566
}
572567

568+
@Test
573569
public void testMarkReferencedStructuredBindingInitializer() {
574570
try {
575571
fMatch = fFindReplaceDocumentAdapter.find(0, "decompArr", true, true, true, false);

0 commit comments

Comments
 (0)