From 4a8e6178e0cd000a11583e25e3bdf7f14ce65725 Mon Sep 17 00:00:00 2001 From: U004458 Date: Tue, 28 Oct 2025 21:45:29 +0800 Subject: [PATCH] feat: Migrate cat.ddk.check.runtime.core.test to Junit5 removed junit4 dependencies removed dependency to DiscerningSuite --- .../META-INF/MANIFEST.MF | 6 +-- .../runtime/context/CheckContextTest.java | 22 ++++----- .../registry/CheckExtensionPointTests.java | 28 ++++++----- .../core/validation/CheckValidatorTest.java | 10 ++-- .../label/CheckRuleLabelProviderTest.java | 48 +++++++++---------- .../test/core/CheckRuntimeTestSuite.java | 22 +++++---- 6 files changed, 70 insertions(+), 66 deletions(-) diff --git a/com.avaloq.tools.ddk.check.runtime.core.test/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.check.runtime.core.test/META-INF/MANIFEST.MF index 5d2219d319..4d2ee84266 100644 --- a/com.avaloq.tools.ddk.check.runtime.core.test/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.check.runtime.core.test/META-INF/MANIFEST.MF @@ -8,13 +8,13 @@ Bundle-RequiredExecutionEnvironment: JavaSE-21 Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.xtext, - com.avaloq.tools.ddk.test.ui, + com.avaloq.tools.ddk.test.ui, com.avaloq.tools.ddk.check.runtime.core, - org.junit, com.google.guava, junit-jupiter-api, junit-jupiter-engine, - junit-vintage-engine + junit-vintage-engine, + junit-platform-suite-api Export-Package: com.avaloq.tools.ddk.check.runtime.test.core Import-Package: org.mockito, org.mockito.stubbing diff --git a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/context/CheckContextTest.java b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/context/CheckContextTest.java index 6bb93ee4c3..5a427fc88b 100644 --- a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/context/CheckContextTest.java +++ b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/context/CheckContextTest.java @@ -10,18 +10,18 @@ *******************************************************************************/ package com.avaloq.tools.ddk.check.runtime.context; -import org.eclipse.emf.ecore.EObject; -import org.junit.Assert; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import junit.framework.TestCase; +import org.eclipse.emf.ecore.EObject; +import org.junit.jupiter.api.Test; /** * Provides some tests of the reflective {@link AbstractCheckContext} framework. */ @SuppressWarnings("nls") -public class CheckContextTest extends TestCase { +class CheckContextTest { public static final String ENABLED_ISSUE_CODE = "Enabled.Issue.Code"; public static final String DISABLED_ISSUE_CODE = "Disabled.Issue.Code"; @@ -34,13 +34,13 @@ public class CheckContextTest extends TestCase { * Tests that the {@link DummyCheckContext} properly marks issue codes as enabled and disabled. */ @Test - public void testIssuesEnabledDisabled() { + void testIssuesEnabledDisabled() { ICheckContext checkContext = new DummyCheckContext(); - Assert.assertTrue("Check an issue code in annotations but enabled is still enabled", checkContext.isCheckValid(DUMMY_CONTEXT, ENABLED_ISSUE_CODE)); - Assert.assertTrue("Check an issue code not in any annotations is still enabled", checkContext.isCheckValid(DUMMY_CONTEXT, NOT_MENTIONED_ISSUE_CODE)); - Assert.assertFalse("Check an issue code in annotations is disabled", checkContext.isCheckValid(DUMMY_CONTEXT, DISABLED_ISSUE_CODE)); - Assert.assertFalse("Check disabling has priority over enabling", checkContext.isCheckValid(DUMMY_CONTEXT, DISABLED_AND_ENABLED_ISSUE_CODE)); - Assert.assertFalse("Check disabling has priority over enabling, using different order", checkContext.isCheckValid(DUMMY_CONTEXT, ENABLED_AND_DISABLED_ISSUE_CODE)); + assertTrue(checkContext.isCheckValid(DUMMY_CONTEXT, ENABLED_ISSUE_CODE), "Check an issue code in annotations but enabled is still enabled"); + assertTrue(checkContext.isCheckValid(DUMMY_CONTEXT, NOT_MENTIONED_ISSUE_CODE), "Check an issue code not in any annotations is still enabled"); + assertFalse(checkContext.isCheckValid(DUMMY_CONTEXT, DISABLED_ISSUE_CODE), "Check an issue code in annotations is disabled"); + assertFalse(checkContext.isCheckValid(DUMMY_CONTEXT, DISABLED_AND_ENABLED_ISSUE_CODE), "Check disabling has priority over enabling"); + assertFalse(checkContext.isCheckValid(DUMMY_CONTEXT, ENABLED_AND_DISABLED_ISSUE_CODE), "Check disabling has priority over enabling, using different order"); } } diff --git a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/registry/CheckExtensionPointTests.java b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/registry/CheckExtensionPointTests.java index 892d66848e..109474d0ab 100644 --- a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/registry/CheckExtensionPointTests.java +++ b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/registry/CheckExtensionPointTests.java @@ -10,25 +10,27 @@ *******************************************************************************/ package com.avaloq.tools.ddk.check.runtime.core.registry; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; + import java.util.List; import java.util.NoSuchElementException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.Platform; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import junit.framework.TestCase; - /** * Provides some test cases for the Check extension point. */ @SuppressWarnings("nls") -public class CheckExtensionPointTests extends TestCase { +class CheckExtensionPointTests { private static final String DUMMY_EXTENSION_ID = "com.avaloq.tools.ddk.check.runtime.core.test"; private static final String CHECK_EXTENSION_ID = "com.avaloq.tools.ddk.check.runtime.core"; @@ -86,7 +88,7 @@ private IConfigurationElement findConfigurationElement(final IConfigurationEleme * @see Platform#getExtensionRegistry() */ @Test - public void testExtensionPointIsRegistered() { + void testExtensionPointIsRegistered() { try { findCheckExtensionPoint(findExtensionPoints()); } catch (NoSuchElementException e) { @@ -99,8 +101,8 @@ public void testExtensionPointIsRegistered() { * point. */ @Test - public void testDummyClientRegistered() { - assertNotNull("Test plugin successfully registered to the check extension point", findCheckExtensionPoint(findExtensionPoints()).getExtension(DUMMY_EXTENSION_ID)); + void testDummyClientRegistered() { + assertNotNull(findCheckExtensionPoint(findExtensionPoints()).getExtension(DUMMY_EXTENSION_ID), "Test plugin successfully registered to the check extension point"); } /** @@ -108,25 +110,25 @@ public void testDummyClientRegistered() { * point registry. */ @Test - public void testInvalidClientNotRegistered() { - assertNull("Non-existing client not registered to the check extension point", findCheckExtensionPoint(findExtensionPoints()).getExtension("a.b.c")); + void testInvalidClientNotRegistered() { + assertNull(findCheckExtensionPoint(findExtensionPoints()).getExtension("a.b.c"), "Non-existing client not registered to the check extension point"); } /** * Tests that the check extension point has an attribute {@value #TARGET_CLASS_ATTRIBUTE}. */ @Test - public void testTargetClassAttributeFound() { + void testTargetClassAttributeFound() { IExtensionPoint point = findCheckExtensionPoint(findExtensionPoints()); - assertNotNull("Found a configuration element with attribute \"targetClass\"", findConfigurationElement(point.getConfigurationElements(), TARGET_CLASS_ATTRIBUTE)); + assertNotNull(findConfigurationElement(point.getConfigurationElements(), TARGET_CLASS_ATTRIBUTE), "Found a configuration element with attribute \"targetClass\""); } /** * Tests that the check extension point has an attribute {@value #LANGUAGE_ATTRIBUTE}. */ @Test - public void testLanguageAttributeFound() { + void testLanguageAttributeFound() { IExtensionPoint point = findCheckExtensionPoint(findExtensionPoints()); - assertNotNull("Found a configuration element with attribute \"language\"", findConfigurationElement(point.getConfigurationElements(), LANGUAGE_ATTRIBUTE)); + assertNotNull(findConfigurationElement(point.getConfigurationElements(), LANGUAGE_ATTRIBUTE), "Found a configuration element with attribute \"language\""); } } diff --git a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/validation/CheckValidatorTest.java b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/validation/CheckValidatorTest.java index ef03b79eef..a8e64e841b 100644 --- a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/validation/CheckValidatorTest.java +++ b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/validation/CheckValidatorTest.java @@ -10,9 +10,9 @@ *******************************************************************************/ package com.avaloq.tools.ddk.check.runtime.core.validation; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.avaloq.tools.ddk.check.runtime.issue.ICheckValidatorImpl; import com.avaloq.tools.ddk.check.runtime.validation.AbstractCheckValidator; @@ -24,7 +24,7 @@ * Performs some basic validation tests on the {@link AbstractCheckValidator}. */ @SuppressWarnings("nls") -public class CheckValidatorTest extends AbstractCheckValidator { +class CheckValidatorTest extends AbstractCheckValidator { /** * Represents the dummy language which is also registered in the plugin.xml. */ @@ -46,8 +46,8 @@ protected String getHostLanguage() { * @see {@link com.avaloq.tools.ddk.check.extensionpoint.test.validation.DummyValidator} */ @Test - public void testAtLeastOneValidatorFound() { + void testAtLeastOneValidatorFound() { ICheckValidatorImpl dummyValidator = Iterables.getOnlyElement(getValidators(Maps.newHashMap(), null)); - assertEquals("Dummy validator found", "DummyValidator", dummyValidator.getClass().getSimpleName()); + assertEquals("DummyValidator", dummyValidator.getClass().getSimpleName(), "Dummy validator found"); } } diff --git a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProviderTest.java b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProviderTest.java index 64c3898bc4..ad6c313734 100644 --- a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProviderTest.java +++ b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProviderTest.java @@ -10,9 +10,9 @@ package com.avaloq.tools.ddk.check.runtime.label; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -23,9 +23,9 @@ import java.util.Collections; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.avaloq.tools.ddk.check.runtime.issue.ICheckValidatorImpl; import com.avaloq.tools.ddk.check.runtime.registry.ICheckValidatorRegistry; @@ -40,7 +40,7 @@ * Unit test for {@link DefaultCheckRuleLabelProvider}. */ @SuppressWarnings("nls") -public class CheckRuleLabelProviderTest { +class CheckRuleLabelProviderTest { // Test data private static final int NUM_VALIDATORS = 3; @@ -72,8 +72,8 @@ public class CheckRuleLabelProviderTest { /** * Setup done before each test. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { // Create mocks mockCheckValidatorRegistry = mock(ICheckValidatorRegistry.class); @@ -97,8 +97,8 @@ protected void configure() { /** * Teardown done after each test. */ - @After - public void tearDown() { + @AfterEach + void tearDown() { mockCheckValidatorRegistry = null; mockValidators = null; @@ -127,16 +127,16 @@ private void mockValidatorsWithChecks() { * Test the default binding. */ @Test - public void testBinding() { + void testBinding() { // ASSERT - assertSame("Binding of label provider incorrect.", CheckRuleLabelProvider.class, checkRuleLabelProvider.getClass()); + assertSame(CheckRuleLabelProvider.class, checkRuleLabelProvider.getClass(), "Binding of label provider incorrect."); } /** * Test successfully getting a check label. */ @Test - public void testSuccess() { + void testSuccess() { // ARRANGE mockValidatorsWithChecks(); @@ -150,7 +150,7 @@ public void testSuccess() { /** * Test trying to get the check label for an issue code which is not present. */ - public void testWhenIssueCodeNotPresent() { + void testWhenIssueCodeNotPresent() { // ARRANGE mockValidatorsWithChecks(); @@ -165,7 +165,7 @@ public void testWhenIssueCodeNotPresent() { * Test trying to get the check label for a null issue code. */ @Test - public void testWithNullID() { + void testWithNullID() { // ARRANGE mockValidatorsWithChecks(); @@ -180,7 +180,7 @@ public void testWithNullID() { * Test trying to get a check label when there are no validators. */ @Test - public void testWithNoValidators() { + void testWithNoValidators() { // ARRANGE when(mockCheckValidatorRegistry.getValidators()).thenReturn(Collections.emptyList()); @@ -195,7 +195,7 @@ public void testWithNoValidators() { * Test trying to get a check label when there are no checks registered. */ @Test - public void testWithNoChecks() { + void testWithNoChecks() { // ARRANGE when(mockCheckValidatorRegistry.getValidators()).thenReturn(mockValidators); for (ICheckValidatorImpl mockValidator : mockValidators) { @@ -213,7 +213,7 @@ public void testWithNoChecks() { * Test trying to get the check label for an issue code which is not a check issue code. */ @Test - public void testWhenIssueCodeIsNotACheckIssueCode() { + void testWhenIssueCodeIsNotACheckIssueCode() { // ARRANGE final String notACheckIssueCode = "package.name.SomeOtherClass.issue.code"; @@ -233,7 +233,7 @@ public void testWhenIssueCodeIsNotACheckIssueCode() { * Test that check labels are cached. */ @Test - public void testCaching() { + void testCaching() { // ARRANGE mockValidatorsWithChecks(); @@ -258,7 +258,7 @@ private static final class CheckRuleLabelProviderWithInvalidateCacheExposed exte /** * Call protected method {link CheckRuleLabelProvider.invalidateCache}. */ - public void publicInvalidateCache() { + void publicInvalidateCache() { super.invalidateCache(); } } @@ -267,7 +267,7 @@ public void publicInvalidateCache() { * Test that the cache can be invalidated by subclasses. */ @Test - public void testInvalidatingCache() { + void testInvalidatingCache() { // ARRANGE final CheckRuleLabelProviderWithInvalidateCacheExposed checkRuleLabelProviderWithInvalidateCacheExposed = injector.getInstance(CheckRuleLabelProviderWithInvalidateCacheExposed.class); @@ -291,12 +291,12 @@ public void testInvalidatingCache() { * Test that the class is bound as a singleton. */ @Test - public void testClassIsSingleton() { + void testClassIsSingleton() { // ACT final ICheckRuleLabelProvider otherCheckRuleLabelProvider = injector.getInstance(CheckRuleLabelProvider.class); // ASSERT - assertSame("Only one instance of CheckRuleLabelProvider expected", checkRuleLabelProvider, otherCheckRuleLabelProvider); + assertSame(checkRuleLabelProvider, otherCheckRuleLabelProvider, "Only one instance of CheckRuleLabelProvider expected"); } } diff --git a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/test/core/CheckRuntimeTestSuite.java b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/test/core/CheckRuntimeTestSuite.java index 01bb65c881..5bfc0fe7e7 100644 --- a/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/test/core/CheckRuntimeTestSuite.java +++ b/com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/test/core/CheckRuntimeTestSuite.java @@ -10,20 +10,22 @@ *******************************************************************************/ package com.avaloq.tools.ddk.check.runtime.test.core; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -import com.avaloq.tools.ddk.check.runtime.context.CheckContextTest; -import com.avaloq.tools.ddk.check.runtime.core.registry.CheckExtensionPointTests; -import com.avaloq.tools.ddk.check.runtime.core.validation.CheckValidatorTest; -import com.avaloq.tools.ddk.check.runtime.label.CheckRuleLabelProviderTest; +import org.junit.platform.suite.api.SelectPackages; +import org.junit.platform.suite.api.Suite; /** - * The test suite for Check core tests. + * Junit5 version of test suites. does not implement the logic in our DiscerningSuite. */ -@RunWith(Suite.class) -@Suite.SuiteClasses({CheckExtensionPointTests.class, CheckValidatorTest.class, CheckContextTest.class, CheckRuleLabelProviderTest.class}) +@Suite +@SelectPackages({ +// @Format-Off + "com.avaloq.tools.ddk.check.runtime.context", + "com.avaloq.tools.ddk.check.runtime.core.registry", + "com.avaloq.tools.ddk.check.runtime.core.validation", + "com.avaloq.tools.ddk.check.runtime.label" + // @Format-On +}) public class CheckRuntimeTestSuite { }