2222import java .util .regex .Matcher ;
2323import java .util .regex .Pattern ;
2424
25- import org .junit .After ;
26- import org .junit .Assert ;
27- import org .junit .Assume ;
28- import org .junit .Before ;
29- import org .junit .Rule ;
30- import org .junit .Test ;
31- import org .junit .rules .TestWatcher ;
25+ import org .junit .jupiter .api .AfterEach ;
26+ import org .junit .jupiter .api .Assertions ;
27+ import org .junit .jupiter .api .Assumptions ;
28+ import org .junit .jupiter .api .BeforeEach ;
29+ import org .junit .jupiter .api .Test ;
30+
31+ import org .junit .jupiter .api .extension .ExtensionContext ;
32+ import org .junit .jupiter .api .extension .RegisterExtension ;
33+ import org .junit .jupiter .api .extension .TestWatcher ;
3234
3335import org .eclipse .test .Screenshots ;
3436
@@ -76,11 +78,17 @@ public class CodeMiningTest {
7678
7779 private SourceViewer fViewer ;
7880 private Shell fShell ;
81+ private MonoReconciler fReconciler ;
7982
80- @ Rule
81- public TestWatcher screenshotRule = Screenshots .onFailure (() -> fShell );
83+ @ RegisterExtension
84+ public TestWatcher screenshotRule = new TestWatcher () {
85+ @ Override
86+ public void testFailed (ExtensionContext context , Throwable cause ) {
87+ Screenshots .takeScreenshot (CodeMiningTest .class , context .getDisplayName ());
88+ }
89+ };
8290
83- @ Before
91+ @ BeforeEach
8492 public void setUp () {
8593 fShell = new Shell (Display .getDefault ());
8694 fShell .setSize (500 , 200 );
@@ -89,10 +97,12 @@ public void setUp() {
8997 final StyledText textWidget = fViewer .getTextWidget ();
9098 textWidget .setText ("a" );
9199 textWidget .setText ("" );
92- MonoReconciler reconciler = new MonoReconciler (new IReconcilingStrategy () {
100+ fReconciler = new MonoReconciler (new IReconcilingStrategy () {
93101 @ Override
94102 public void setDocument (IDocument document ) {
95- fViewer .updateCodeMinings ();
103+ if (fViewer != null ) {
104+ fViewer .updateCodeMinings ();
105+ }
96106 }
97107
98108 @ Override
@@ -102,10 +112,12 @@ public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
102112
103113 @ Override
104114 public void reconcile (IRegion partition ) {
105- fViewer .updateCodeMinings ();
115+ if (fViewer != null ) {
116+ fViewer .updateCodeMinings ();
117+ }
106118 }
107119 }, false );
108- reconciler .install (fViewer );
120+ fReconciler .install (fViewer );
109121 fViewer .setDocument (new Document (), new AnnotationModel ());
110122 fViewer .setCodeMiningProviders (new ICodeMiningProvider [] { new DelayedEchoCodeMiningProvider () });
111123 AnnotationPainter annotationPainter = new AnnotationPainter (fViewer , null );
@@ -115,7 +127,7 @@ public void reconcile(IRegion partition) {
115127 fViewer .setCodeMiningProviders (new ICodeMiningProvider [] { new DelayedEchoCodeMiningProvider () });
116128 final Display display = textWidget .getDisplay ();
117129 fShell .open ();
118- Assert .assertTrue (new DisplayHelper () {
130+ Assertions .assertTrue (new DisplayHelper () {
119131 @ Override
120132 protected boolean condition () {
121133 return fViewer .getTextWidget ().isVisible ();
@@ -124,15 +136,19 @@ protected boolean condition() {
124136 DisplayHelper .sleep (textWidget .getDisplay (), 1000 );
125137 }
126138
127- @ After
139+ @ AfterEach
128140 public void tearDown () {
141+ if (fReconciler != null ) {
142+ fReconciler .uninstall ();
143+ fReconciler = null ;
144+ }
129145 fViewer = null ;
130146 }
131147
132148 @ Test
133149 public void testCodeMiningFirstLine () {
134150 fViewer .getDocument ().set ("echo" );
135- Assert .assertTrue (new DisplayHelper () {
151+ Assertions .assertTrue (new DisplayHelper () {
136152 @ Override
137153 protected boolean condition () {
138154 return fViewer .getTextWidget ().getLineVerticalIndent (0 ) > 0 ;
@@ -154,7 +170,7 @@ public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextVi
154170 },
155171 new DelayedEchoCodeMiningProvider () });
156172 fViewer .getDocument ().set ("echo" );
157- Assert .assertTrue (new DisplayHelper () {
173+ Assertions .assertTrue (new DisplayHelper () {
158174 @ Override
159175 protected boolean condition () {
160176 return fViewer .getTextWidget ().getLineVerticalIndent (0 ) > 0 ;
@@ -164,10 +180,10 @@ protected boolean condition() {
164180
165181 @ Test
166182 public void testCodeMiningCtrlHome () throws BadLocationException {
167- Assume .assumeFalse ("See bug 541415. For whatever reason, this shortcut doesn't work on Mac" , Util . isMac () );
183+ Assumptions .assumeFalse (Util . isMac (), "See bug 541415. For whatever reason, this shortcut doesn't work on Mac" );
168184 DelayedEchoCodeMiningProvider .DELAY = 500 ;
169185 fViewer .getDocument ().set (TextViewerTest .generate5000Lines ());
170- Assert .assertTrue (new DisplayHelper () {
186+ Assertions .assertTrue (new DisplayHelper () {
171187 @ Override
172188 protected boolean condition () {
173189 return fViewer .getTextWidget ().getText ().length () > 5000 ;
@@ -176,7 +192,7 @@ protected boolean condition() {
176192 TextViewerTest .ctrlEnd (fViewer );
177193 final int lastLine = fViewer .getDocument ().getNumberOfLines () - 1 ;
178194 final int lastLineOffset = fViewer .getDocument ().getLineOffset (lastLine );
179- Assert .assertTrue (new DisplayHelper () {
195+ Assertions .assertTrue (new DisplayHelper () {
180196 @ Override
181197 protected boolean condition () {
182198 return lastLineOffset >= fViewer .getVisibleRegion ().getOffset () && lastLineOffset <= fViewer .getVisibleRegion ().getOffset () + fViewer .getVisibleRegion ().getLength ();
@@ -187,15 +203,15 @@ protected boolean condition() {
187203 fViewer .addViewportListener (offset ->
188204 events .incrementAndGet ());
189205 TextViewerTest .ctrlHome (fViewer );
190- Assert .assertTrue (new DisplayHelper () {
206+ Assertions .assertTrue (new DisplayHelper () {
191207 @ Override
192208 protected boolean condition () {
193209 return events .get () > 0 ;
194210 }
195211 }.waitForCondition (fViewer .getControl ().getDisplay (), 3000 ));
196- Assert .assertEquals (0 , fViewer .getVisibleRegion ().getOffset ());
212+ Assertions .assertEquals (0 , fViewer .getVisibleRegion ().getOffset ());
197213 // wait for codemining to style line
198- Assert .assertTrue (new DisplayHelper () {
214+ Assertions .assertTrue (new DisplayHelper () {
199215 @ Override
200216 protected boolean condition () {
201217 return fViewer .getTextWidget ().getLineVerticalIndent (0 ) > 0 ;
@@ -205,9 +221,9 @@ protected boolean condition() {
205221
206222 @ Test
207223 public void testCodeMiningCtrlEnd () throws BadLocationException {
208- Assume .assumeFalse ("See bug 541415. For whatever reason, this shortcut doesn't work on Mac" , Util . isMac () );
224+ Assumptions .assumeFalse (Util . isMac (), "See bug 541415. For whatever reason, this shortcut doesn't work on Mac" );
209225 fViewer .getDocument ().set (TextViewerTest .generate5000Lines ());
210- Assert .assertTrue (new DisplayHelper () {
226+ Assertions .assertTrue (new DisplayHelper () {
211227 @ Override
212228 protected boolean condition () {
213229 return fViewer .getTextWidget ().getText ().length () > 5000 && fViewer .getTextWidget ().getLineVerticalIndent (0 ) > 0 ;
@@ -217,13 +233,13 @@ protected boolean condition() {
217233 TextViewerTest .ctrlEnd (fViewer );
218234 final int lastLine = fViewer .getDocument ().getNumberOfLines () - 1 ;
219235 final int lastLineOffset = fViewer .getDocument ().getLineOffset (lastLine );
220- Assert .assertTrue (new DisplayHelper () {
236+ Assertions .assertTrue (new DisplayHelper () {
221237 @ Override
222238 protected boolean condition () {
223239 return lastLineOffset >= fViewer .getVisibleRegion ().getOffset () && lastLineOffset <= fViewer .getVisibleRegion ().getOffset () + fViewer .getVisibleRegion ().getLength ();
224240 }
225241 }.waitForCondition (fViewer .getControl ().getDisplay (), 3000 ));
226- Assert .assertTrue (new DisplayHelper () {
242+ Assertions .assertTrue (new DisplayHelper () {
227243 @ Override
228244 protected boolean condition () {
229245 return fViewer .getTextWidget ().getLineVerticalIndent (lastLine ) > 0 ;
@@ -245,7 +261,7 @@ public void dispose() {
245261 }
246262 } });
247263 StyledText widget = fViewer .getTextWidget ();
248- Assert .assertTrue ("Code mining is not visible in 1st empty line after line break character" , new DisplayHelper () {
264+ Assertions .assertTrue (new DisplayHelper () {
249265 @ Override
250266 protected boolean condition () {
251267 try {
@@ -256,7 +272,7 @@ protected boolean condition() {
256272 return false ;
257273 }
258274 }
259- }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 1000 ));
275+ }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 1000 ), "Code mining is not visible in 1st empty line after line break character" );
260276 }
261277
262278 @ Test
@@ -284,7 +300,7 @@ public String getLabel() {
284300 public void dispose () {
285301 }
286302 } });
287- Assert .assertTrue ("Code mining is not visible at end of document" , new DisplayHelper () {
303+ Assertions .assertTrue (new DisplayHelper () {
288304 @ Override
289305 protected boolean condition () {
290306 try {
@@ -294,9 +310,8 @@ protected boolean condition() {
294310 return false ;
295311 }
296312 }
297- }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 10_000 ));
313+ }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 10_000 ), "Code mining is not visible at end of document" );
298314 }
299-
300315 @ Test
301316 public void testDocumentFooterCodeMining () throws Exception {
302317 String source = "first\n second" ;
@@ -318,7 +333,7 @@ public String getLabel() {
318333 public void dispose () {
319334 }
320335 } });
321- Assert .assertTrue ("Code mining is not visible at end of document" , new DisplayHelper () {
336+ Assertions .assertTrue (new DisplayHelper () {
322337 @ Override
323338 protected boolean condition () {
324339 try {
@@ -332,7 +347,7 @@ protected boolean condition() {
332347 return false ;
333348 }
334349 }
335- }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 10_000 ));
350+ }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 10_000 ), "Code mining is not visible at end of document" );
336351 }
337352
338353 @ Test
@@ -356,7 +371,7 @@ public String getLabel() {
356371 public void dispose () {
357372 }
358373 } });
359- Assert .assertTrue ("Code mining is not visible at end of document" , new DisplayHelper () {
374+ Assertions .assertTrue (new DisplayHelper () {
360375 @ Override
361376 protected boolean condition () {
362377 try {
@@ -370,7 +385,7 @@ protected boolean condition() {
370385 return false ;
371386 }
372387 }
373- }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 10_000 ));
388+ }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 10_000 ), "Code mining is not visible at end of document" );
374389 }
375390
376391 @ Test
@@ -387,7 +402,7 @@ public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextVi
387402 public void dispose () {
388403 }
389404 } });
390- Assert .assertTrue ("Code mining is not visible at end of document" , new DisplayHelper () {
405+ Assertions .assertTrue (new DisplayHelper () {
391406 @ Override
392407 protected boolean condition () {
393408 try {
@@ -397,7 +412,7 @@ protected boolean condition() {
397412 return false ;
398413 }
399414 }
400- }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 10_000 ));
415+ }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 10_000 ), "Code mining is not visible at end of document" );
401416 }
402417
403418 @ Test
@@ -414,7 +429,7 @@ public void dispose() {
414429 }
415430 } });
416431 StyledText widget = fViewer .getTextWidget ();
417- Assert .assertTrue ("Code mining is not visible in 1st line after character a before line break character" , new DisplayHelper () {
432+ Assertions .assertTrue (new DisplayHelper () {
418433 @ Override
419434 protected boolean condition () {
420435 try {
@@ -425,7 +440,7 @@ protected boolean condition() {
425440 return false ;
426441 }
427442 }
428- }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 1000 ));
443+ }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 1000 ), "Code mining is not visible in 1st line after character a before line break character" );
429444 }
430445
431446 @ Test
@@ -442,7 +457,7 @@ public void dispose() {
442457 }
443458 } });
444459 StyledText widget = fViewer .getTextWidget ();
445- Assert .assertFalse ("Code mining is visible on 2nd line" , new DisplayHelper () {
460+ Assertions .assertFalse (new DisplayHelper () {
446461 @ Override
447462 protected boolean condition () {
448463 try {
@@ -453,7 +468,7 @@ protected boolean condition() {
453468 return true ;
454469 }
455470 }
456- }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 1000 ));
471+ }.waitForCondition (fViewer .getTextWidget ().getDisplay (), 1000 ), "Code mining is visible on 2nd line" );
457472 }
458473
459474 @ Test
@@ -484,7 +499,7 @@ public void dispose() {
484499 }
485500 } });
486501 StyledText widget = fViewer .getTextWidget ();
487- Assert .assertFalse ("Code mining is unexpectedly rendered below last line" , new DisplayHelper () {
502+ Assertions .assertFalse (new DisplayHelper () {
488503 @ Override
489504 protected boolean condition () {
490505 try {
@@ -494,7 +509,7 @@ protected boolean condition() {
494509 return false ;
495510 }
496511 }
497- }.waitForCondition (widget .getDisplay (), 1000 ));
512+ }.waitForCondition (widget .getDisplay (), 1000 ), "Code mining is unexpectedly rendered below last line" );
498513 }
499514
500515 @ Test
@@ -509,35 +524,35 @@ public void testCodeMiningSwitchingBetweenInLineAndLineHeader() {
509524 fViewer .setCodeMiningProviders (new ICodeMiningProvider [] { new RefTestCodeMiningProvider (useInLineCodeMinings ) });
510525
511526 StyledText widget = fViewer .getTextWidget ();
512- Assert .assertTrue ("Line header code minigs were used. Expected in-line code minings instead." , new DisplayHelper () {
527+ Assertions .assertTrue (new DisplayHelper () {
513528 @ Override
514529 protected boolean condition () {
515530 return widget .getStyleRangeAtOffset (index ) != null
516531 && widget .isVisible () && widget .getLineVerticalIndent (0 ) == 0 ;
517532 }
518- }.waitForCondition (widget .getDisplay (), 1000 ));
533+ }.waitForCondition (widget .getDisplay (), 1000 ), "Line header code minigs were used. Expected in-line code minings instead." );
519534
520535 // switch to line header mode
521536 useInLineCodeMinings .set (false );
522537 fViewer .updateCodeMinings ();
523538
524- Assert .assertTrue ("In-line code minigs were used (or no code minings at all). Expected line header code minings." , new DisplayHelper () {
539+ Assertions .assertTrue (new DisplayHelper () {
525540 @ Override
526541 protected boolean condition () {
527542 return widget .getStyleRangeAtOffset (index ) == null && widget .getLineVerticalIndent (0 ) > 0 ;
528543 }
529- }.waitForCondition (widget .getDisplay (), 1000 ));
544+ }.waitForCondition (widget .getDisplay (), 1000 ), "In-line code minigs were used (or no code minings at all). Expected line header code minings." );
530545
531546 // switch back to in-line mode
532547 useInLineCodeMinings .set (true );
533548 fViewer .updateCodeMinings ();
534549
535- Assert .assertTrue ("Line header code minigs were used. Expected in-line code minings instead." , new DisplayHelper () {
550+ Assertions .assertTrue (new DisplayHelper () {
536551 @ Override
537552 protected boolean condition () {
538553 return widget .getStyleRangeAtOffset (index ) != null && widget .getLineVerticalIndent (0 ) == 0 ;
539554 }
540- }.waitForCondition (widget .getDisplay (), 1000 ));
555+ }.waitForCondition (widget .getDisplay (), 1000 ), "Line header code minigs were used. Expected in-line code minings instead." );
541556 }
542557
543558 private static boolean hasCodeMiningPrintedBelowLine (ITextViewer viewer , int line ) throws BadLocationException {
0 commit comments