From 66bc2bcdb84bbbfb263c8898b5470c1374b01680 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Fri, 11 Oct 2024 13:56:30 +0200 Subject: [PATCH] tests: take screenshot before dispose https://github.com/eclipse-platform/eclipse.platform.swt/issues/1518 --- .../workbench/PartRenderingEngineTests.java | 2 +- .../jface/text/tests/TextViewerTest.java | 29 +++++-------------- .../text/tests/codemining/CodeMiningTest.java | 3 +- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java index 50d211751ce..f6ba9816001 100644 --- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java +++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java @@ -2974,7 +2974,7 @@ public void testBug371100() { } @Rule - public TestWatcher screenshotRule = Screenshots.onFailure(); + public TestWatcher screenshotRule = Screenshots.onFailure(null); @Test public void testBug372226() { diff --git a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java index f0ecf7e0182..9fe54f86b56 100644 --- a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java +++ b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/TextViewerTest.java @@ -24,8 +24,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import org.junit.After; import org.junit.Assume; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestWatcher; @@ -76,22 +76,18 @@ */ public class TextViewerTest { - @Rule - public TestWatcher screenshotRule= Screenshots.onFailure(); - private Shell fShell; - @After - public void tearDown() { - if (fShell != null && !fShell.isDisposed()) { - fShell.dispose(); - } - fShell= null; + @Before + public void before() { + fShell= new Shell(); } + @Rule + public TestWatcher screenshotRule= Screenshots.onFailure(() -> fShell); + @Test public void testSetRedraw_Bug441827() throws Exception { - fShell= new Shell(); TextViewer textViewer= new TextViewer(fShell, SWT.NONE); Document document= new Document("abc"); textViewer.setDocument(document); @@ -111,7 +107,6 @@ public void testSetRedraw_Bug441827() throws Exception { @Test public void testCaretMoveChangesSelection() throws Exception { - fShell= new Shell(); TextViewer textViewer= new TextViewer(fShell, SWT.NONE); Document document= new Document("abc"); textViewer.setDocument(document); @@ -129,7 +124,6 @@ public void testCaretMoveChangesSelection() throws Exception { @Test public void testGetCachedSelection() throws Exception { - fShell= new Shell(); TextViewer textViewer= new TextViewer(fShell, SWT.NONE); Document document= new Document("abc"); textViewer.setDocument(document); @@ -145,7 +139,6 @@ public void testGetCachedSelection() throws Exception { @Test public void testBlockSelectionAccessors() throws Exception { - fShell= new Shell(); ITextViewer textViewer= new TextViewer(fShell, SWT.NONE); Document document= new Document("0123\n4567\n89ab\ncdef"); textViewer.setDocument(document); @@ -190,7 +183,6 @@ private void checkInAndOutUIThread(Runnable r) throws InterruptedException { @Test public void testCtrlHomeViewportListener() { Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac()); - fShell= new Shell(); fShell.setLayout(new FillLayout()); fShell.setSize(500, 200); SourceViewer textViewer= new SourceViewer(fShell, null, SWT.NONE); @@ -213,7 +205,6 @@ protected boolean condition() { @Test public void testCtrlEndViewportListener() { Assume.assumeFalse("See bug 541415. For whatever reason, this shortcut doesn't work on Mac", Util.isMac()); - fShell= new Shell(); fShell.setLayout(new FillLayout()); fShell.setSize(500, 200); SourceViewer textViewer= new SourceViewer(fShell, null, SWT.NONE); @@ -237,7 +228,6 @@ protected boolean condition() { */ @Test public void testDefaultContentImplementation() { - fShell= new Shell(); final StyledTextContent content; try { final TextViewer textViewer= new TextViewer(fShell, SWT.NONE); @@ -323,7 +313,6 @@ public static String generate5000Lines() { @Test public void testShiftLeft() { - fShell= new Shell(); TextViewer textViewer= new TextViewer(fShell, SWT.NONE); { // Normal case, both lines match prefix @@ -394,7 +383,6 @@ private void checkHyperlink(TextViewer textViewer, int pos, String text, String @Test public void testURLHyperlinkDetector() { - fShell= new Shell(); TextViewer textViewer= new TextViewer(fShell, SWT.NONE); checkHyperlink(textViewer, 3, "https://foo ", "[https://foo]"); checkHyperlink(textViewer, 0, "", "[]"); @@ -417,7 +405,6 @@ public void testURLHyperlinkDetector() { @Test public void testPasteMultiLines() { - fShell= new Shell(); TextViewer textViewer= new TextViewer(fShell, SWT.NONE); Document document= new Document(); textViewer.setDocument(document); @@ -434,7 +421,6 @@ public void testPasteMultiLines() { @Test public void testSetSelectionNoDoc() { - fShell= new Shell(); TextViewer textViewer= new TextViewer(fShell, SWT.NONE); textViewer.setSelection(TextSelection.emptySelection()); // assert no exception is thrown @@ -442,7 +428,6 @@ public void testSetSelectionNoDoc() { @Test public void testSelectionFromViewerState() { - fShell= new Shell(); TextViewer textViewer= new TextViewer(fShell, SWT.NONE); textViewer.setDocument(new Document( "/**\n" diff --git a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java index 4775458d4b5..b5558b2ff6e 100644 --- a/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java +++ b/tests/org.eclipse.jface.text.tests/src/org/eclipse/jface/text/tests/codemining/CodeMiningTest.java @@ -69,7 +69,7 @@ public class CodeMiningTest { private Shell fShell; @Rule - public TestWatcher screenshotRule= Screenshots.onFailure(); + public TestWatcher screenshotRule= Screenshots.onFailure(() -> fShell); @Before public void setUp() { @@ -117,7 +117,6 @@ protected boolean condition() { @After public void tearDown() { - fShell.dispose(); fViewer = null; }