From ca02a1a13c97720d209e185e9436fd44e41692dc Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 23 Oct 2024 10:36:35 +0200 Subject: [PATCH] refact: cleanup junit test configuration --- org.eclipse.tm4e.core.tests/.classpath | 3 +-- org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF | 4 ++-- .../.classpath | 2 +- .../META-INF/MANIFEST.MF | 3 +-- .../languageconfiguration/tests/TestComment.java | 3 +-- org.eclipse.tm4e.ui.tests/.classpath | 4 ++-- org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF | 12 +++++------- .../TMPresentationReconcilerTypeScriptTest.java | 14 +++++++++----- .../tests/internal/model/TMDocumentModelTest.java | 5 ++++- .../internal/utils/DocumentInputStreamTest.java | 8 ++++---- .../eclipse/tm4e/ui/tests/support/TestUtils.java | 3 +-- 11 files changed, 31 insertions(+), 30 deletions(-) diff --git a/org.eclipse.tm4e.core.tests/.classpath b/org.eclipse.tm4e.core.tests/.classpath index 33ab3fb38..55bce8855 100644 --- a/org.eclipse.tm4e.core.tests/.classpath +++ b/org.eclipse.tm4e.core.tests/.classpath @@ -12,14 +12,13 @@ - - + diff --git a/org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF index 43eee8013..d37e9c891 100644 --- a/org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core.tests/META-INF/MANIFEST.MF @@ -10,8 +10,8 @@ Require-Bundle: org.apache.batik.css;resolution:=optional, com.google.gson;resolution:=optional, org.eclipse.core.runtime, org.eclipse.tm4e.core -Import-Package: org.junit.runner, - org.junit.jupiter.api,org.junit.jupiter.api.function, +Import-Package: org.junit.jupiter.api, + org.junit.jupiter.api.function, org.w3c.css.sac;resolution:=optional, org.w3c.css.sac.helpers;resolution:=optional Bundle-RequiredExecutionEnvironment: JavaSE-17 diff --git a/org.eclipse.tm4e.languageconfiguration.tests/.classpath b/org.eclipse.tm4e.languageconfiguration.tests/.classpath index e878fffd8..64721289d 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/.classpath +++ b/org.eclipse.tm4e.languageconfiguration.tests/.classpath @@ -2,6 +2,7 @@ + @@ -11,7 +12,6 @@ - diff --git a/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF b/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF index 74d0c1102..0493b72fe 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.languageconfiguration.tests/META-INF/MANIFEST.MF @@ -16,7 +16,6 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.ui.workbench, org.eclipse.ui.workbench.texteditor, org.eclipse.tm4e.languageconfiguration, - org.eclipse.tm4e.ui, - org.junit + org.eclipse.tm4e.ui Bundle-ActivationPolicy: lazy Import-Package: org.junit.jupiter.api diff --git a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java index 23d63fc91..03a87b6b0 100644 --- a/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java +++ b/org.eclipse.tm4e.languageconfiguration.tests/src/main/java/org/eclipse/tm4e/languageconfiguration/tests/TestComment.java @@ -8,8 +8,7 @@ */ package org.eclipse.tm4e.languageconfiguration.tests; -import static org.junit.Assert.*; -import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; diff --git a/org.eclipse.tm4e.ui.tests/.classpath b/org.eclipse.tm4e.ui.tests/.classpath index 6ab27de0b..55bce8855 100644 --- a/org.eclipse.tm4e.ui.tests/.classpath +++ b/org.eclipse.tm4e.ui.tests/.classpath @@ -2,6 +2,7 @@ + @@ -11,14 +12,13 @@ - - + diff --git a/org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF b/org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF index 4fa42e0d5..8aa7200fb 100644 --- a/org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.ui.tests/META-INF/MANIFEST.MF @@ -11,17 +11,15 @@ Require-Bundle: org.eclipse.jface.text, org.eclipse.core.runtime, org.eclipse.ui, org.eclipse.ui.editors, - org.eclipse.ui.genericeditor;resolution:=optional, + org.eclipse.ui.genericeditor, org.eclipse.ui.ide, org.eclipse.ui.tests.harness, org.eclipse.tm4e.core, org.eclipse.tm4e.registry, - org.eclipse.tm4e.ui, - com.google.gson;bundle-version="[2.10.1,3.0.0)", - org.junit, - junit-jupiter-api, - org.opentest4j + org.eclipse.tm4e.ui Bundle-RequiredExecutionEnvironment: JavaSE-17 Bundle-ActivationPolicy: lazy -Import-Package: org.eclipse.core.filebuffers +Import-Package: org.junit.jupiter.api, + org.junit.jupiter.api.condition, + org.opentest4j Automatic-Module-Name: org.eclipse.tm4e.ui.tests diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMPresentationReconcilerTypeScriptTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMPresentationReconcilerTypeScriptTest.java index 19d52010d..6fc816fbb 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMPresentationReconcilerTypeScriptTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/TMPresentationReconcilerTypeScriptTest.java @@ -28,27 +28,31 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIf; +@DisabledIf("org.eclipse.tm4e.ui.tests.TMPresentationReconcilerTypeScriptTest#isDisabled") class TMPresentationReconcilerTypeScriptTest { + static boolean isDisabled() { + // TODO ignore these tests on GitHub Actions Windows runner because they are extremely slow (4-5min) for an unknown reason + return TestUtils.isGitHubActions() && System.getProperty("os.name").toLowerCase().contains("windows"); + } + private IGrammar grammar; private ITokenProvider theme; private TMEditor editor; @BeforeEach void setup() throws Exception { - // TODO ignore these tests on GitHub Actions Windows runner because they are extremely slow (4-5min) for an unknown reason - org.junit.Assume.assumeFalse(TestUtils.isGitHubActions() && System.getProperty("os.name").toLowerCase().contains("windows")); - TestUtils.assertNoTM4EThreadsRunning(); grammar = new Registry().addGrammar(IGrammarSource.fromResource(getClass(), "/grammars/TypeScript.tmLanguage.json")); - theme = TMUIPlugin.getThemeManager().getThemeById(ThemeIdConstants.SolarizedLight); + theme = TMUIPlugin.getThemeManager().getThemeById(ThemeIdConstants.SolarizedLight); } @AfterEach void tearDown() throws InterruptedException { - if(editor != null) + if (editor != null) editor.dispose(); TestUtils.assertNoTM4EThreadsRunning(); diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/model/TMDocumentModelTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/model/TMDocumentModelTest.java index 6224fa6e7..efab7649d 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/model/TMDocumentModelTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/model/TMDocumentModelTest.java @@ -31,7 +31,6 @@ import org.eclipse.tm4e.core.registry.Registry; import org.eclipse.tm4e.ui.internal.model.TMDocumentModel; import org.eclipse.tm4e.ui.tests.support.TestUtils; -import org.junit.function.ThrowingRunnable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; @@ -42,6 +41,10 @@ @TestMethodOrder(MethodOrderer.MethodName.class) class TMDocumentModelTest { + interface ThrowingRunnable { + void run() throws Throwable; + } + private static final String LF = "\n"; private static IGrammar grammar; diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/utils/DocumentInputStreamTest.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/utils/DocumentInputStreamTest.java index 6dcb4400a..0514099fe 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/utils/DocumentInputStreamTest.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/internal/utils/DocumentInputStreamTest.java @@ -12,7 +12,7 @@ package org.eclipse.tm4e.ui.tests.internal.utils; import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -28,8 +28,8 @@ import org.eclipse.ui.editors.text.FileDocumentProvider; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.texteditor.IDocumentProvider; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; class DocumentInputStreamTest { @@ -44,7 +44,7 @@ class DocumentInputStreamTest { private final IDocumentProvider documentProvider = new FileDocumentProvider(); private IDocument document; - @Before + @BeforeEach public void setUp() throws CoreException { final IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis()); p.create(null); diff --git a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/support/TestUtils.java b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/support/TestUtils.java index 2aa9c3bb4..6e5dc33c1 100644 --- a/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/support/TestUtils.java +++ b/org.eclipse.tm4e.ui.tests/src/main/java/org/eclipse/tm4e/ui/tests/support/TestUtils.java @@ -13,7 +13,6 @@ */ package org.eclipse.tm4e.ui.tests.support; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.*; import java.io.File; @@ -131,7 +130,7 @@ protected boolean condition() { } throw new AssertionError(errorMessage, ex.get()); } - assertTrue(errorMessage, isConditionMet); + assertTrue(isConditionMet, errorMessage); } public static boolean waitForCondition(final int timeout_ms, final Condition condition) {