2424import java .util .concurrent .atomic .AtomicBoolean ;
2525import java .util .stream .Collectors ;
2626
27- import org .junit .After ;
2827import org .junit .Assume ;
28+ import org .junit .Before ;
2929import org .junit .Rule ;
3030import org .junit .Test ;
3131import org .junit .rules .TestWatcher ;
7676 */
7777public class TextViewerTest {
7878
79- @ Rule
80- public TestWatcher screenshotRule = Screenshots .onFailure ();
81-
8279 private Shell fShell ;
8380
84- @ After
85- public void tearDown () {
86- if (fShell != null && !fShell .isDisposed ()) {
87- fShell .dispose ();
88- }
89- fShell = null ;
81+ @ Before
82+ public void before () {
83+ fShell = new Shell ();
9084 }
9185
86+ @ Rule
87+ public TestWatcher screenshotRule = Screenshots .onFailure (() -> fShell );
88+
9289 @ Test
9390 public void testSetRedraw_Bug441827 () throws Exception {
94- fShell = new Shell ();
9591 TextViewer textViewer = new TextViewer (fShell , SWT .NONE );
9692 Document document = new Document ("abc" );
9793 textViewer .setDocument (document );
@@ -111,7 +107,6 @@ public void testSetRedraw_Bug441827() throws Exception {
111107
112108 @ Test
113109 public void testCaretMoveChangesSelection () throws Exception {
114- fShell = new Shell ();
115110 TextViewer textViewer = new TextViewer (fShell , SWT .NONE );
116111 Document document = new Document ("abc" );
117112 textViewer .setDocument (document );
@@ -129,7 +124,6 @@ public void testCaretMoveChangesSelection() throws Exception {
129124
130125 @ Test
131126 public void testGetCachedSelection () throws Exception {
132- fShell = new Shell ();
133127 TextViewer textViewer = new TextViewer (fShell , SWT .NONE );
134128 Document document = new Document ("abc" );
135129 textViewer .setDocument (document );
@@ -145,7 +139,6 @@ public void testGetCachedSelection() throws Exception {
145139
146140 @ Test
147141 public void testBlockSelectionAccessors () throws Exception {
148- fShell = new Shell ();
149142 ITextViewer textViewer = new TextViewer (fShell , SWT .NONE );
150143 Document document = new Document ("0123\n 4567\n 89ab\n cdef" );
151144 textViewer .setDocument (document );
@@ -190,7 +183,6 @@ private void checkInAndOutUIThread(Runnable r) throws InterruptedException {
190183 @ Test
191184 public void testCtrlHomeViewportListener () {
192185 Assume .assumeFalse ("See bug 541415. For whatever reason, this shortcut doesn't work on Mac" , Util .isMac ());
193- fShell = new Shell ();
194186 fShell .setLayout (new FillLayout ());
195187 fShell .setSize (500 , 200 );
196188 SourceViewer textViewer = new SourceViewer (fShell , null , SWT .NONE );
@@ -213,7 +205,6 @@ protected boolean condition() {
213205 @ Test
214206 public void testCtrlEndViewportListener () {
215207 Assume .assumeFalse ("See bug 541415. For whatever reason, this shortcut doesn't work on Mac" , Util .isMac ());
216- fShell = new Shell ();
217208 fShell .setLayout (new FillLayout ());
218209 fShell .setSize (500 , 200 );
219210 SourceViewer textViewer = new SourceViewer (fShell , null , SWT .NONE );
@@ -237,7 +228,6 @@ protected boolean condition() {
237228 */
238229 @ Test
239230 public void testDefaultContentImplementation () {
240- fShell = new Shell ();
241231 final StyledTextContent content ;
242232 try {
243233 final TextViewer textViewer = new TextViewer (fShell , SWT .NONE );
@@ -323,7 +313,6 @@ public static String generate5000Lines() {
323313
324314 @ Test
325315 public void testShiftLeft () {
326- fShell = new Shell ();
327316 TextViewer textViewer = new TextViewer (fShell , SWT .NONE );
328317 {
329318 // Normal case, both lines match prefix
@@ -394,7 +383,6 @@ private void checkHyperlink(TextViewer textViewer, int pos, String text, String
394383
395384 @ Test
396385 public void testURLHyperlinkDetector () {
397- fShell = new Shell ();
398386 TextViewer textViewer = new TextViewer (fShell , SWT .NONE );
399387 checkHyperlink (textViewer , 3 , "https://foo " , "[https://foo]" );
400388 checkHyperlink (textViewer , 0 , "" , "[]" );
@@ -417,7 +405,6 @@ public void testURLHyperlinkDetector() {
417405
418406 @ Test
419407 public void testPasteMultiLines () {
420- fShell = new Shell ();
421408 TextViewer textViewer = new TextViewer (fShell , SWT .NONE );
422409 Document document = new Document ();
423410 textViewer .setDocument (document );
@@ -434,15 +421,13 @@ public void testPasteMultiLines() {
434421
435422 @ Test
436423 public void testSetSelectionNoDoc () {
437- fShell = new Shell ();
438424 TextViewer textViewer = new TextViewer (fShell , SWT .NONE );
439425 textViewer .setSelection (TextSelection .emptySelection ());
440426 // assert no exception is thrown
441427 }
442428
443429 @ Test
444430 public void testSelectionFromViewerState () {
445- fShell = new Shell ();
446431 TextViewer textViewer = new TextViewer (fShell , SWT .NONE );
447432 textViewer .setDocument (new Document (
448433 "/**\n "
0 commit comments