1616 *******************************************************************************/
1717package org .eclipse .jface .text .tests ;
1818
19- import static org .junit .Assert .assertEquals ;
20- import static org .junit .Assert .assertTrue ;
21- import static org .junit .Assert .fail ;
22- import static org .junit .Assume .assumeNotNull ;
19+ import static org .junit .jupiter .api .Assertions .assertEquals ;
20+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
21+ import static org .junit .jupiter .api .Assertions .assertTrue ;
22+ import static org .junit .jupiter .api .Assertions .fail ;
23+ import static org .junit .jupiter .api .Assumptions .assumeFalse ;
2324
2425import java .util .Arrays ;
2526import java .util .concurrent .atomic .AtomicBoolean ;
2627import java .util .stream .Collectors ;
2728
28- import org .junit .Assume ;
29- import org .junit .Before ;
30- import org .junit .Rule ;
31- import org .junit .Test ;
32- import org .junit .rules .TestWatcher ;
29+ import org .junit .jupiter . api . BeforeEach ;
30+ import org .junit .jupiter . api . Test ;
31+ import org .junit .jupiter . api . extension . ExtensionContext ;
32+ import org .junit .jupiter . api . extension . RegisterExtension ;
33+ import org .junit .jupiter . api . extension .TestWatcher ;
3334
3435import org .eclipse .test .Screenshots ;
3536
@@ -81,13 +82,18 @@ public class TextViewerTest {
8182
8283 private Shell fShell ;
8384
84- @ Before
85+ @ BeforeEach
8586 public void before () {
8687 fShell = new Shell ();
8788 }
8889
89- @ Rule
90- public TestWatcher screenshotRule = Screenshots .onFailure (() -> fShell );
90+ @ RegisterExtension
91+ public TestWatcher screenshotRule = new TestWatcher () {
92+ @ Override
93+ public void testFailed (ExtensionContext context , Throwable cause ) {
94+ Screenshots .takeScreenshot (TextViewerTest .class , context .getDisplayName ());
95+ }
96+ };
9197
9298 @ Test
9399 public void testSetRedraw_Bug441827 () throws Exception {
@@ -185,7 +191,7 @@ private void checkInAndOutUIThread(Runnable r) throws InterruptedException {
185191
186192 @ Test
187193 public void testCtrlHomeViewportListener () {
188- Assume . assumeFalse ("See bug 541415. For whatever reason, this shortcut doesn't work on Mac" , Util . isMac () );
194+ assumeFalse (Util . isMac (), "See bug 541415. For whatever reason, this shortcut doesn't work on Mac" );
189195 fShell .setLayout (new FillLayout ());
190196 fShell .setSize (500 , 200 );
191197 SourceViewer textViewer = new SourceViewer (fShell , null , SWT .NONE );
@@ -207,7 +213,7 @@ protected boolean condition() {
207213
208214 @ Test
209215 public void testCtrlEndViewportListener () {
210- Assume . assumeFalse ("See bug 541415. For whatever reason, this shortcut doesn't work on Mac" , Util . isMac () );
216+ assumeFalse (Util . isMac (), "See bug 541415. For whatever reason, this shortcut doesn't work on Mac" );
211217 fShell .setLayout (new FillLayout ());
212218 fShell .setSize (500 , 200 );
213219 SourceViewer textViewer = new SourceViewer (fShell , null , SWT .NONE );
@@ -240,43 +246,43 @@ public void testDefaultContentImplementation() {
240246 fail ("Failed to obtain default instance of TextViewers document adapter. " + ex .getMessage ());
241247 return ;
242248 }
243- assumeNotNull (content );
249+ assertNotNull (content );
244250
245251 final String line0 = "Hello " ;
246252 final String line1 = "" ;
247253 final String line2 = "World!" ;
248254 final String text = line0 + "\n " + line1 + "\r \n " + line2 ;
249255 content .setText (text );
250- assertEquals ("Get text range failed." , " H" , content .getTextRange (0 , 1 ));
251- assertEquals ("Get text range failed." , " ll" , content .getTextRange (2 , 2 ));
252- assertEquals ("Adapter content length wrong." , text .length (), content .getCharCount ());
253- assertEquals ("Adapter returned wrong content." , line0 , content . getLine ( 0 ) );
254- assertEquals ("Adapter returned wrong content." , line1 , content . getLine ( 1 ) );
255- assertEquals ("Adapter returned wrong content." , line2 , content . getLine ( 2 ) );
256+ assertEquals ("H" , content .getTextRange (0 , 1 ), "Get text range failed." );
257+ assertEquals ("ll" , content .getTextRange (2 , 2 ), "Get text range failed." );
258+ assertEquals (text .length (), content .getCharCount (), "Adapter content length wrong." );
259+ assertEquals (line0 , content . getLine ( 0 ), "Adapter returned wrong content." );
260+ assertEquals (line1 , content . getLine ( 1 ), "Adapter returned wrong content." );
261+ assertEquals (line2 , content . getLine ( 2 ), "Adapter returned wrong content." );
256262
257263 content .setText ("\r \n \r \n " );
258- assertEquals ("Wrong line for offset." , 0 , content . getLineAtOffset ( 0 ) );
259- assertEquals ("Wrong line for offset." , 0 , content . getLineAtOffset ( 1 ) );
260- assertEquals ("Wrong line for offset." , 1 , content . getLineAtOffset ( 2 ) );
261- assertEquals ("Wrong line for offset." , 1 , content . getLineAtOffset ( 3 ) );
262- assertEquals ("Wrong line for offset." , 2 , content . getLineAtOffset ( 4 ) );
263- assertEquals ("Wrong line for offset." , content .getLineCount () - 1 , content .getLineAtOffset (content .getCharCount ()));
264+ assertEquals (0 , content . getLineAtOffset ( 0 ), "Wrong line for offset." );
265+ assertEquals (0 , content . getLineAtOffset ( 1 ), "Wrong line for offset." );
266+ assertEquals (1 , content . getLineAtOffset ( 2 ), "Wrong line for offset." );
267+ assertEquals (1 , content . getLineAtOffset ( 3 ), "Wrong line for offset." );
268+ assertEquals (2 , content . getLineAtOffset ( 4 ), "Wrong line for offset." );
269+ assertEquals (content .getLineCount () - 1 , content .getLineAtOffset (content .getCharCount ()), "Wrong line for offset." );
264270
265271 content .setText (null );
266- assertEquals ("Adapter returned wrong line count." , 1 , content . getLineCount () );
272+ assertEquals (1 , content . getLineCount (), "Adapter returned wrong line count." );
267273 content .setText ("" );
268- assertEquals ("Adapter returned wrong line count." , 1 , content . getLineCount () );
274+ assertEquals (1 , content . getLineCount (), "Adapter returned wrong line count." );
269275 content .setText ("a\n " );
270- assertEquals ("Adapter returned wrong line count." , 2 , content . getLineCount () );
276+ assertEquals (2 , content . getLineCount (), "Adapter returned wrong line count." );
271277 content .setText ("\n \n " );
272- assertEquals ("Adapter returned wrong line count." , 3 , content . getLineCount () );
278+ assertEquals (3 , content . getLineCount (), "Adapter returned wrong line count." );
273279
274280 content .setText ("\r \n test\r \n " );
275- assertEquals ("Wrong offset for line." , 0 , content . getOffsetAtLine ( 0 ) );
276- assertEquals ("Wrong offset for line." , 2 , content . getOffsetAtLine ( 1 ) );
277- assertEquals ("Wrong offset for line." , 8 , content . getOffsetAtLine ( 2 ) );
281+ assertEquals (0 , content . getOffsetAtLine ( 0 ), "Wrong offset for line." );
282+ assertEquals (2 , content . getOffsetAtLine ( 1 ), "Wrong offset for line." );
283+ assertEquals (8 , content . getOffsetAtLine ( 2 ), "Wrong offset for line." );
278284 content .setText ("" );
279- assertEquals ("Wrong offset for line." , 0 , content . getOffsetAtLine ( 0 ) );
285+ assertEquals (0 , content . getOffsetAtLine ( 0 ), "Wrong offset for line." );
280286 }
281287
282288 public static void ctrlEnd (ITextViewer viewer ) {
0 commit comments