Skip to content

Commit 43c8d09

Browse files
authored
Merge pull request #1208 from markdomeng/runtime_core_j5
feat: Migrate cat.ddk.check.runtime.core.test to Junit5
2 parents 524fc94 + 4a8e617 commit 43c8d09

File tree

6 files changed

+70
-66
lines changed

6 files changed

+70
-66
lines changed

com.avaloq.tools.ddk.check.runtime.core.test/META-INF/MANIFEST.MF

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Bundle-RequiredExecutionEnvironment: JavaSE-21
88
Require-Bundle: org.eclipse.ui,
99
org.eclipse.core.runtime,
1010
org.eclipse.xtext,
11-
com.avaloq.tools.ddk.test.ui,
11+
com.avaloq.tools.ddk.test.ui,
1212
com.avaloq.tools.ddk.check.runtime.core,
13-
org.junit,
1413
com.google.guava,
1514
junit-jupiter-api,
1615
junit-jupiter-engine,
17-
junit-vintage-engine
16+
junit-vintage-engine,
17+
junit-platform-suite-api
1818
Export-Package: com.avaloq.tools.ddk.check.runtime.test.core
1919
Import-Package: org.mockito,
2020
org.mockito.stubbing

com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/context/CheckContextTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.check.runtime.context;
1212

13-
import org.eclipse.emf.ecore.EObject;
14-
import org.junit.Assert;
15-
import org.junit.Test;
13+
import static org.junit.jupiter.api.Assertions.assertFalse;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
1615

17-
import junit.framework.TestCase;
16+
import org.eclipse.emf.ecore.EObject;
17+
import org.junit.jupiter.api.Test;
1818

1919

2020
/**
2121
* Provides some tests of the reflective {@link AbstractCheckContext} framework.
2222
*/
2323
@SuppressWarnings("nls")
24-
public class CheckContextTest extends TestCase {
24+
class CheckContextTest {
2525

2626
public static final String ENABLED_ISSUE_CODE = "Enabled.Issue.Code";
2727
public static final String DISABLED_ISSUE_CODE = "Disabled.Issue.Code";
@@ -34,13 +34,13 @@ public class CheckContextTest extends TestCase {
3434
* Tests that the {@link DummyCheckContext} properly marks issue codes as enabled and disabled.
3535
*/
3636
@Test
37-
public void testIssuesEnabledDisabled() {
37+
void testIssuesEnabledDisabled() {
3838
ICheckContext checkContext = new DummyCheckContext();
39-
Assert.assertTrue("Check an issue code in annotations but enabled is still enabled", checkContext.isCheckValid(DUMMY_CONTEXT, ENABLED_ISSUE_CODE));
40-
Assert.assertTrue("Check an issue code not in any annotations is still enabled", checkContext.isCheckValid(DUMMY_CONTEXT, NOT_MENTIONED_ISSUE_CODE));
41-
Assert.assertFalse("Check an issue code in annotations is disabled", checkContext.isCheckValid(DUMMY_CONTEXT, DISABLED_ISSUE_CODE));
42-
Assert.assertFalse("Check disabling has priority over enabling", checkContext.isCheckValid(DUMMY_CONTEXT, DISABLED_AND_ENABLED_ISSUE_CODE));
43-
Assert.assertFalse("Check disabling has priority over enabling, using different order", checkContext.isCheckValid(DUMMY_CONTEXT, ENABLED_AND_DISABLED_ISSUE_CODE));
39+
assertTrue(checkContext.isCheckValid(DUMMY_CONTEXT, ENABLED_ISSUE_CODE), "Check an issue code in annotations but enabled is still enabled");
40+
assertTrue(checkContext.isCheckValid(DUMMY_CONTEXT, NOT_MENTIONED_ISSUE_CODE), "Check an issue code not in any annotations is still enabled");
41+
assertFalse(checkContext.isCheckValid(DUMMY_CONTEXT, DISABLED_ISSUE_CODE), "Check an issue code in annotations is disabled");
42+
assertFalse(checkContext.isCheckValid(DUMMY_CONTEXT, DISABLED_AND_ENABLED_ISSUE_CODE), "Check disabling has priority over enabling");
43+
assertFalse(checkContext.isCheckValid(DUMMY_CONTEXT, ENABLED_AND_DISABLED_ISSUE_CODE), "Check disabling has priority over enabling, using different order");
4444

4545
}
4646
}

com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/registry/CheckExtensionPointTests.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,27 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.check.runtime.core.registry;
1212

13+
import static org.junit.jupiter.api.Assertions.assertNotNull;
14+
import static org.junit.jupiter.api.Assertions.assertNull;
15+
import static org.junit.jupiter.api.Assertions.fail;
16+
1317
import java.util.List;
1418
import java.util.NoSuchElementException;
1519

1620
import org.eclipse.core.runtime.IConfigurationElement;
1721
import org.eclipse.core.runtime.IExtensionPoint;
1822
import org.eclipse.core.runtime.Platform;
19-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2024

2125
import com.google.common.collect.Iterables;
2226
import com.google.common.collect.Lists;
2327

24-
import junit.framework.TestCase;
25-
2628

2729
/**
2830
* Provides some test cases for the Check extension point.
2931
*/
3032
@SuppressWarnings("nls")
31-
public class CheckExtensionPointTests extends TestCase {
33+
class CheckExtensionPointTests {
3234

3335
private static final String DUMMY_EXTENSION_ID = "com.avaloq.tools.ddk.check.runtime.core.test";
3436
private static final String CHECK_EXTENSION_ID = "com.avaloq.tools.ddk.check.runtime.core";
@@ -86,7 +88,7 @@ private IConfigurationElement findConfigurationElement(final IConfigurationEleme
8688
* @see Platform#getExtensionRegistry()
8789
*/
8890
@Test
89-
public void testExtensionPointIsRegistered() {
91+
void testExtensionPointIsRegistered() {
9092
try {
9193
findCheckExtensionPoint(findExtensionPoints());
9294
} catch (NoSuchElementException e) {
@@ -99,34 +101,34 @@ public void testExtensionPointIsRegistered() {
99101
* point.
100102
*/
101103
@Test
102-
public void testDummyClientRegistered() {
103-
assertNotNull("Test plugin successfully registered to the check extension point", findCheckExtensionPoint(findExtensionPoints()).getExtension(DUMMY_EXTENSION_ID));
104+
void testDummyClientRegistered() {
105+
assertNotNull(findCheckExtensionPoint(findExtensionPoints()).getExtension(DUMMY_EXTENSION_ID), "Test plugin successfully registered to the check extension point");
104106
}
105107

106108
/**
107109
* Tests that a non-existing client is not registered with the extension
108110
* point registry.
109111
*/
110112
@Test
111-
public void testInvalidClientNotRegistered() {
112-
assertNull("Non-existing client not registered to the check extension point", findCheckExtensionPoint(findExtensionPoints()).getExtension("a.b.c"));
113+
void testInvalidClientNotRegistered() {
114+
assertNull(findCheckExtensionPoint(findExtensionPoints()).getExtension("a.b.c"), "Non-existing client not registered to the check extension point");
113115
}
114116

115117
/**
116118
* Tests that the check extension point has an attribute {@value #TARGET_CLASS_ATTRIBUTE}.
117119
*/
118120
@Test
119-
public void testTargetClassAttributeFound() {
121+
void testTargetClassAttributeFound() {
120122
IExtensionPoint point = findCheckExtensionPoint(findExtensionPoints());
121-
assertNotNull("Found a configuration element with attribute \"targetClass\"", findConfigurationElement(point.getConfigurationElements(), TARGET_CLASS_ATTRIBUTE));
123+
assertNotNull(findConfigurationElement(point.getConfigurationElements(), TARGET_CLASS_ATTRIBUTE), "Found a configuration element with attribute \"targetClass\"");
122124
}
123125

124126
/**
125127
* Tests that the check extension point has an attribute {@value #LANGUAGE_ATTRIBUTE}.
126128
*/
127129
@Test
128-
public void testLanguageAttributeFound() {
130+
void testLanguageAttributeFound() {
129131
IExtensionPoint point = findCheckExtensionPoint(findExtensionPoints());
130-
assertNotNull("Found a configuration element with attribute \"language\"", findConfigurationElement(point.getConfigurationElements(), LANGUAGE_ATTRIBUTE));
132+
assertNotNull(findConfigurationElement(point.getConfigurationElements(), LANGUAGE_ATTRIBUTE), "Found a configuration element with attribute \"language\"");
131133
}
132134
}

com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/core/validation/CheckValidatorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.check.runtime.core.validation;
1212

13-
import static org.junit.Assert.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
1414

15-
import org.junit.Test;
15+
import org.junit.jupiter.api.Test;
1616

1717
import com.avaloq.tools.ddk.check.runtime.issue.ICheckValidatorImpl;
1818
import com.avaloq.tools.ddk.check.runtime.validation.AbstractCheckValidator;
@@ -24,7 +24,7 @@
2424
* Performs some basic validation tests on the {@link AbstractCheckValidator}.
2525
*/
2626
@SuppressWarnings("nls")
27-
public class CheckValidatorTest extends AbstractCheckValidator {
27+
class CheckValidatorTest extends AbstractCheckValidator {
2828
/**
2929
* Represents the dummy language which is also registered in the plugin.xml.
3030
*/
@@ -46,8 +46,8 @@ protected String getHostLanguage() {
4646
* @see {@link com.avaloq.tools.ddk.check.extensionpoint.test.validation.DummyValidator}
4747
*/
4848
@Test
49-
public void testAtLeastOneValidatorFound() {
49+
void testAtLeastOneValidatorFound() {
5050
ICheckValidatorImpl dummyValidator = Iterables.getOnlyElement(getValidators(Maps.newHashMap(), null));
51-
assertEquals("Dummy validator found", "DummyValidator", dummyValidator.getClass().getSimpleName());
51+
assertEquals("DummyValidator", dummyValidator.getClass().getSimpleName(), "Dummy validator found");
5252
}
5353
}

com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProviderTest.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
package com.avaloq.tools.ddk.check.runtime.label;
1212

13-
import static org.junit.Assert.assertEquals;
14-
import static org.junit.Assert.assertNull;
15-
import static org.junit.Assert.assertSame;
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertNull;
15+
import static org.junit.jupiter.api.Assertions.assertSame;
1616
import static org.mockito.Mockito.mock;
1717
import static org.mockito.Mockito.times;
1818
import static org.mockito.Mockito.verify;
@@ -23,9 +23,9 @@
2323
import java.util.Collections;
2424
import java.util.List;
2525

26-
import org.junit.After;
27-
import org.junit.Before;
28-
import org.junit.Test;
26+
import org.junit.jupiter.api.AfterEach;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
2929

3030
import com.avaloq.tools.ddk.check.runtime.issue.ICheckValidatorImpl;
3131
import com.avaloq.tools.ddk.check.runtime.registry.ICheckValidatorRegistry;
@@ -40,7 +40,7 @@
4040
* Unit test for {@link DefaultCheckRuleLabelProvider}.
4141
*/
4242
@SuppressWarnings("nls")
43-
public class CheckRuleLabelProviderTest {
43+
class CheckRuleLabelProviderTest {
4444

4545
// Test data
4646
private static final int NUM_VALIDATORS = 3;
@@ -72,8 +72,8 @@ public class CheckRuleLabelProviderTest {
7272
/**
7373
* Setup done before each test.
7474
*/
75-
@Before
76-
public void setUp() {
75+
@BeforeEach
76+
void setUp() {
7777

7878
// Create mocks
7979
mockCheckValidatorRegistry = mock(ICheckValidatorRegistry.class);
@@ -97,8 +97,8 @@ protected void configure() {
9797
/**
9898
* Teardown done after each test.
9999
*/
100-
@After
101-
public void tearDown() {
100+
@AfterEach
101+
void tearDown() {
102102

103103
mockCheckValidatorRegistry = null;
104104
mockValidators = null;
@@ -127,16 +127,16 @@ private void mockValidatorsWithChecks() {
127127
* Test the default binding.
128128
*/
129129
@Test
130-
public void testBinding() {
130+
void testBinding() {
131131
// ASSERT
132-
assertSame("Binding of label provider incorrect.", CheckRuleLabelProvider.class, checkRuleLabelProvider.getClass());
132+
assertSame(CheckRuleLabelProvider.class, checkRuleLabelProvider.getClass(), "Binding of label provider incorrect.");
133133
}
134134

135135
/**
136136
* Test successfully getting a check label.
137137
*/
138138
@Test
139-
public void testSuccess() {
139+
void testSuccess() {
140140
// ARRANGE
141141
mockValidatorsWithChecks();
142142

@@ -150,7 +150,7 @@ public void testSuccess() {
150150
/**
151151
* Test trying to get the check label for an issue code which is not present.
152152
*/
153-
public void testWhenIssueCodeNotPresent() {
153+
void testWhenIssueCodeNotPresent() {
154154
// ARRANGE
155155
mockValidatorsWithChecks();
156156

@@ -165,7 +165,7 @@ public void testWhenIssueCodeNotPresent() {
165165
* Test trying to get the check label for a null issue code.
166166
*/
167167
@Test
168-
public void testWithNullID() {
168+
void testWithNullID() {
169169
// ARRANGE
170170
mockValidatorsWithChecks();
171171

@@ -180,7 +180,7 @@ public void testWithNullID() {
180180
* Test trying to get a check label when there are no validators.
181181
*/
182182
@Test
183-
public void testWithNoValidators() {
183+
void testWithNoValidators() {
184184
// ARRANGE
185185
when(mockCheckValidatorRegistry.getValidators()).thenReturn(Collections.emptyList());
186186

@@ -195,7 +195,7 @@ public void testWithNoValidators() {
195195
* Test trying to get a check label when there are no checks registered.
196196
*/
197197
@Test
198-
public void testWithNoChecks() {
198+
void testWithNoChecks() {
199199
// ARRANGE
200200
when(mockCheckValidatorRegistry.getValidators()).thenReturn(mockValidators);
201201
for (ICheckValidatorImpl mockValidator : mockValidators) {
@@ -213,7 +213,7 @@ public void testWithNoChecks() {
213213
* Test trying to get the check label for an issue code which is not a check issue code.
214214
*/
215215
@Test
216-
public void testWhenIssueCodeIsNotACheckIssueCode() {
216+
void testWhenIssueCodeIsNotACheckIssueCode() {
217217
// ARRANGE
218218
final String notACheckIssueCode = "package.name.SomeOtherClass.issue.code";
219219

@@ -233,7 +233,7 @@ public void testWhenIssueCodeIsNotACheckIssueCode() {
233233
* Test that check labels are cached.
234234
*/
235235
@Test
236-
public void testCaching() {
236+
void testCaching() {
237237
// ARRANGE
238238
mockValidatorsWithChecks();
239239

@@ -258,7 +258,7 @@ private static final class CheckRuleLabelProviderWithInvalidateCacheExposed exte
258258
/**
259259
* Call protected method {link CheckRuleLabelProvider.invalidateCache}.
260260
*/
261-
public void publicInvalidateCache() {
261+
void publicInvalidateCache() {
262262
super.invalidateCache();
263263
}
264264
}
@@ -267,7 +267,7 @@ public void publicInvalidateCache() {
267267
* Test that the cache can be invalidated by subclasses.
268268
*/
269269
@Test
270-
public void testInvalidatingCache() {
270+
void testInvalidatingCache() {
271271
// ARRANGE
272272
final CheckRuleLabelProviderWithInvalidateCacheExposed checkRuleLabelProviderWithInvalidateCacheExposed = injector.getInstance(CheckRuleLabelProviderWithInvalidateCacheExposed.class);
273273

@@ -291,12 +291,12 @@ public void testInvalidatingCache() {
291291
* Test that the class is bound as a singleton.
292292
*/
293293
@Test
294-
public void testClassIsSingleton() {
294+
void testClassIsSingleton() {
295295
// ACT
296296
final ICheckRuleLabelProvider otherCheckRuleLabelProvider = injector.getInstance(CheckRuleLabelProvider.class);
297297

298298
// ASSERT
299-
assertSame("Only one instance of CheckRuleLabelProvider expected", checkRuleLabelProvider, otherCheckRuleLabelProvider);
299+
assertSame(checkRuleLabelProvider, otherCheckRuleLabelProvider, "Only one instance of CheckRuleLabelProvider expected");
300300
}
301301

302302
}

com.avaloq.tools.ddk.check.runtime.core.test/src/com/avaloq/tools/ddk/check/runtime/test/core/CheckRuntimeTestSuite.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.check.runtime.test.core;
1212

13-
import org.junit.runner.RunWith;
14-
import org.junit.runners.Suite;
15-
16-
import com.avaloq.tools.ddk.check.runtime.context.CheckContextTest;
17-
import com.avaloq.tools.ddk.check.runtime.core.registry.CheckExtensionPointTests;
18-
import com.avaloq.tools.ddk.check.runtime.core.validation.CheckValidatorTest;
19-
import com.avaloq.tools.ddk.check.runtime.label.CheckRuleLabelProviderTest;
13+
import org.junit.platform.suite.api.SelectPackages;
14+
import org.junit.platform.suite.api.Suite;
2015

2116

2217
/**
23-
* The test suite for Check core tests.
18+
* Junit5 version of test suites. does not implement the logic in our DiscerningSuite.
2419
*/
25-
@RunWith(Suite.class)
26-
@Suite.SuiteClasses({CheckExtensionPointTests.class, CheckValidatorTest.class, CheckContextTest.class, CheckRuleLabelProviderTest.class})
20+
@Suite
21+
@SelectPackages({
22+
// @Format-Off
23+
"com.avaloq.tools.ddk.check.runtime.context",
24+
"com.avaloq.tools.ddk.check.runtime.core.registry",
25+
"com.avaloq.tools.ddk.check.runtime.core.validation",
26+
"com.avaloq.tools.ddk.check.runtime.label"
27+
// @Format-On
28+
})
2729
public class CheckRuntimeTestSuite {
2830

2931
}

0 commit comments

Comments
 (0)