Skip to content

Commit 524fc94

Browse files
authored
Merge pull request #1207 from markdomeng/check_core_j5
feat: Migrate cat.ddk.check.core.test to Junit5
2 parents 782c958 + d5328e1 commit 524fc94

File tree

22 files changed

+215
-223
lines changed

22 files changed

+215
-223
lines changed

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Require-Bundle: com.avaloq.tools.ddk.check.core,
2020
org.eclipse.xtend.lib,
2121
org.eclipse.xtext.ui.testing,
2222
org.eclipse.xtext.testing,
23-
org.junit,
2423
org.mockito.mockito-core,
2524
com.avaloq.tools.ddk.check.runtime.core,
2625
org.eclipse.ui.workbench;resolution:=optional,
@@ -31,15 +30,11 @@ Require-Bundle: com.avaloq.tools.ddk.check.core,
3130
org.eclipse.xtext.xbase.testing,
3231
junit-jupiter-api,
3332
junit-jupiter-engine,
34-
junit-vintage-engine
33+
junit-vintage-engine,
34+
junit-platform-suite-api
3535
Export-Package: com.avaloq.tools.ddk.check.core.test,
3636
com.avaloq.tools.ddk.check.core.test.util,
3737
com.avaloq.tools.ddk.check.test.core,
3838
com.avaloq.tools.ddk.check
39-
Import-Package: org.junit.runner;version="4.5.0",
40-
org.junit.runner.manipulation;version="4.5.0",
41-
org.junit.runner.notification;version="4.5.0",
42-
org.junit.runners;version="4.5.0",
43-
org.junit.runners.model;version="4.5.0",
44-
org.hamcrest.core
39+
Import-Package: org.hamcrest.core
4540
Automatic-Module-Name: com.avaloq.tools.ddk.check.core.test

com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/generator/IssueCodeValueTest.xtend

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
package com.avaloq.tools.ddk.check.core.generator
1313

1414
import org.eclipse.xtext.testing.InjectWith
15-
import org.junit.runner.RunWith
1615
import com.avaloq.tools.ddk.check.CheckInjectorProvider
17-
import org.eclipse.xtext.testing.XtextRunner
1816
import com.avaloq.tools.ddk.check.core.test.AbstractCheckGenerationTestCase
19-
import org.junit.Test
2017
import java.util.List
2118
import org.eclipse.xtext.xbase.testing.JavaSource
2219
import java.io.ByteArrayInputStream
20+
import org.junit.jupiter.api.^extension.ExtendWith
21+
import org.eclipse.xtext.testing.extensions.InjectionExtension
22+
import org.junit.jupiter.api.Test
23+
import static org.junit.jupiter.api.Assertions.assertTrue
2324

2425
@InjectWith(CheckInjectorProvider)
25-
@RunWith(XtextRunner)
26+
@ExtendWith(InjectionExtension)
2627
class IssueCodeValueTest extends AbstractCheckGenerationTestCase {
2728

2829
static final String PACKAGE_NAME = "mypackage"
@@ -96,7 +97,7 @@ class IssueCodeValueTest extends AbstractCheckGenerationTestCase {
9697

9798
for (issueCode: expectedIssueCodeValues.entrySet) {
9899
val expectedIssueCodeAssignment = '''public static final String «issueCode.key» = "«PACKAGE_NAME».«CATALOG_NAME»«ISSUE_CODES_SUFFIX».«issueCode.value»";'''
99-
assertTrue('''«issueCodesClassName» contains correct initialization of «issueCode.key»''', issueCodesClass.contains(expectedIssueCodeAssignment))
100+
assertTrue(issueCodesClass.contains(expectedIssueCodeAssignment), '''«issueCodesClassName» contains correct initialization of «issueCode.key»''')
100101
}
101102
}
102103

com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckGenerationTestCase.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
package com.avaloq.tools.ddk.check.core.test;
1313

14+
import static org.junit.jupiter.api.Assertions.assertNotNull;
15+
import static org.junit.jupiter.api.Assertions.assertTrue;
16+
import static org.junit.jupiter.api.Assertions.fail;
17+
1418
import java.io.IOException;
1519
import java.io.InputStream;
1620
import java.util.Collections;
@@ -76,7 +80,7 @@ public List<JavaSource> generateAndCompile(final InputStream sourceStream) {
7680
fail("Could not load test resource" + e.getMessage());
7781
}
7882
CheckCatalog root = (CheckCatalog) res.getContents().get(0);
79-
assertNotNull("Resource should contain a CheckCatalog", root);
83+
assertNotNull(root, "Resource should contain a CheckCatalog");
8084
// We also should have some Jvm model here.
8185
JvmType type = null;
8286
for (EObject obj : res.getContents()) {
@@ -85,7 +89,7 @@ public List<JavaSource> generateAndCompile(final InputStream sourceStream) {
8589
break;
8690
}
8791
}
88-
assertNotNull("Should have an inferred Jvm model", type);
92+
assertNotNull(type, "Should have an inferred Jvm model");
8993
// Run the generator using an in-memory file system access
9094
InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
9195
for (OutputConfiguration output : outputConfigurationProvider.getOutputConfigurations()) {
@@ -107,7 +111,7 @@ public List<JavaSource> generateAndCompile(final InputStream sourceStream) {
107111
final InMemoryJavaCompiler.Result result = javaCompiler.compile(sources.toArray(new JavaSource[sources.size()]));
108112
// Due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=541225 we must ignore this warning here
109113
if (result.getCompilationProblems().stream().anyMatch(p -> "Pb(1102) At least one of the problems in category 'nls' is not analysed due to a compiler option being ignored".equals(p.getMessage()))) {
110-
assertTrue("All sources should have been compiled without errors " + result.getCompilationProblems(), result.getCompilationProblems().isEmpty());
114+
assertTrue(result.getCompilationProblems().isEmpty(), "All sources should have been compiled without errors " + result.getCompilationProblems());
111115
}
112116

113117
return sources;

com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
package com.avaloq.tools.ddk.check.core.test;
1212

1313
import static com.google.common.collect.Sets.newHashSet;
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.junit.jupiter.api.Assertions.assertNotNull;
16+
import static org.junit.jupiter.api.Assertions.fail;
1417

1518
import java.io.IOException;
1619
import java.io.InputStream;
@@ -38,9 +41,9 @@
3841
import org.eclipse.xtext.resource.XtextResourceSet;
3942
import org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil;
4043
import org.eclipse.xtext.util.StringInputStream;
41-
import org.junit.AfterClass;
42-
import org.junit.Before;
43-
import org.junit.BeforeClass;
44+
import org.junit.jupiter.api.AfterAll;
45+
import org.junit.jupiter.api.BeforeAll;
46+
import org.junit.jupiter.api.BeforeEach;
4447

4548
import com.avaloq.tools.ddk.check.CheckConstants;
4649
import com.avaloq.tools.ddk.check.ui.internal.CheckActivator;
@@ -54,14 +57,12 @@
5457
import com.google.inject.Injector;
5558
import com.google.inject.Provider;
5659

57-
import junit.framework.TestCase;
58-
5960

6061
/**
6162
* An abstract test class for tests on Check models. Allows creating a project and adding files.
6263
*/
6364
@SuppressWarnings({"PMD.SignatureDeclareThrowsException", "restriction", "nls"})
64-
public abstract class AbstractCheckTestCase extends TestCase {
65+
public abstract class AbstractCheckTestCase {
6566
private static final int TWO_KILO_BYTES = 2048;
6667
protected static final Logger LOGGER = LogManager.getLogger(AbstractCheckTestCase.class);
6768
private static final PluginTestProjectManager PROJECT_MANAGER = new PluginTestProjectManager(CheckActivator.getInstance().getInjector(CheckConstants.GRAMMAR));
@@ -71,8 +72,7 @@ public abstract class AbstractCheckTestCase extends TestCase {
7172
@Inject
7273
private Provider<XtextResourceSet> resourceSetProvider;
7374

74-
@Override
75-
@Before
75+
@BeforeEach
7676
public void setUp() throws Exception {
7777
getInjector().injectMembers(this);
7878
}
@@ -83,7 +83,7 @@ public void setUp() throws Exception {
8383
* @throws Exception
8484
* the exception
8585
*/
86-
@BeforeClass
86+
@BeforeAll
8787
public static void prepareWorkspace() throws Exception {
8888
PROJECT_MANAGER.setup(ImmutableList.<TestSource> of());
8989
}
@@ -117,7 +117,7 @@ public <T> T get(final Class<T> clazz) {
117117
/**
118118
* Clean up after all tests have terminated.
119119
*/
120-
@AfterClass
120+
@AfterAll
121121
public static void cleanUp() {
122122
PROJECT_MANAGER.teardown();
123123
}
@@ -215,7 +215,7 @@ public EObject getModel(final String fileName, final String content) throws Exce
215215
IFile file = createFile(fileName, content);
216216
Resource resource = get(XtextResourceSet.class).createResource(uri(file));
217217
resource.load(new StringInputStream(content), null);
218-
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
218+
assertEquals(0, resource.getErrors().size(), resource.getErrors().toString());
219219
return resource.getContents().get(0);
220220
}
221221

@@ -264,7 +264,7 @@ public EObject getModel(final String fileName) throws Exception { // NOPMD
264264
}
265265
}
266266
}
267-
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
267+
assertEquals(0, resource.getErrors().size(), resource.getErrors().toString());
268268
return resource.getContents().get(0);
269269
}
270270

@@ -293,7 +293,7 @@ public boolean apply(final IFile input) {
293293
*/
294294
protected IProject getOrCreatePluginProject() throws CoreException {
295295
IWorkspaceRoot workspaceRoot = EcorePlugin.getWorkspaceRoot();
296-
assertNotNull("No workspace; project cannot be created or found", workspaceRoot);
296+
assertNotNull(workspaceRoot, "No workspace; project cannot be created or found");
297297
IProject project = workspaceRoot.getProject(PluginTestProjectManager.TEST_PROJECT_NAME);
298298
if (!project.exists()) {
299299
try {
@@ -349,7 +349,7 @@ protected void execute(final IProgressMonitor monitor) throws CoreException, Inv
349349
} catch (InterruptedException e) {
350350
fail("Error adding files to workspace: " + e.getMessage());
351351
}
352-
assertEquals("All files successfully added to workspace", sourceFileNames.size(), getFiles().size());
352+
assertEquals(sourceFileNames.size(), getFiles().size(), "All files successfully added to workspace");
353353
}
354354

355355
/**

com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/BasicModelTest.xtend

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
66
* http://www.eclipse.org/legal/epl-v10.html
7-
*
7+
*
88
* Contributors:
99
* Avaloq Group AG - initial API and implementation
1010
*******************************************************************************/
@@ -19,16 +19,15 @@ import com.avaloq.tools.ddk.check.core.test.util.CheckTestUtil
1919
import com.google.inject.Inject
2020
import org.eclipse.xtext.resource.XtextResource
2121
import org.eclipse.xtext.testing.InjectWith
22-
import org.eclipse.xtext.testing.XtextRunner
2322
import org.eclipse.xtext.testing.util.ParseHelper
24-
import org.junit.Ignore
25-
import org.junit.Test
26-
import org.junit.runner.RunWith
27-
28-
import static org.junit.Assert.*
23+
import org.junit.jupiter.api.Test
24+
import org.eclipse.xtext.testing.extensions.InjectionExtension
25+
import org.junit.jupiter.api.^extension.ExtendWith
26+
import static org.junit.jupiter.api.Assertions.*
27+
import org.junit.jupiter.api.Disabled
2928

3029
@InjectWith(typeof(CheckUiInjectorProvider))
31-
@RunWith(typeof(XtextRunner))
30+
@ExtendWith(typeof(InjectionExtension))
3231
class BasicModelTest {
3332

3433
@Inject
@@ -46,7 +45,7 @@ class BasicModelTest {
4645
@Test
4746
def void testCreateEmptyModelWithPackageReference() {
4847
val model = parser.parse("package p catalog c {}")
49-
assertNotNull("CheckCatalog with EPackage reference successfully created", model);
48+
assertNotNull(model, "CheckCatalog with EPackage reference successfully created")
5049
}
5150

5251
/**
@@ -55,7 +54,7 @@ class BasicModelTest {
5554
@Test
5655
def void testCreateEmptyModelWithGrammarReference() {
5756
val model = parser.parse("package p catalog c for grammar com.avaloq.tools.ddk.check.Check {}")
58-
assertNotNull("CheckCatalog with Grammar reference successfully created", model);
57+
assertNotNull(model, "CheckCatalog with Grammar reference successfully created")
5958
}
6059

6160
/* Tests that an XIssueExpression takes message parameters. */
@@ -74,39 +73,44 @@ class BasicModelTest {
7473

7574
/* Tests that Checks documented with ML_COMMENTs have an inferred description field. */
7675
@Test
77-
@Ignore("Fails because DocumentedImplCustom uses the null resource description provider to get the document provider")
76+
@Disabled("Fails because DocumentedImplCustom uses the null resource description provider to get the document provider")
7877
def void testInferingOfDescription() {
7978
val check = util.getFirstInstanceOf(parser.parse(modelUtil.modelWithCheck), typeof(Check))
80-
assertEquals("No documentation.", check.description)
79+
assertEquals(check.description, "No documentation.")
8180
}
8281

8382
/* Tests that Checks have an implicit name which matches the ID. */
8483
@Test
8584
def void testCheckNameIDIsPresent() {
8685
val id = "CheckID"
8786
val check = util.getFirstInstanceOf(parser.parse(modelUtil.modelWithCheck(id)), typeof(Check))
88-
assertEquals("Check name field matches ID field", check.id, check.name)
89-
assertEquals("Check name field matches supplied ID", id, check.name)
87+
assertEquals(check.id, check.name, "Check name field matches ID field")
88+
assertEquals(id, check.name, "Check name field matches supplied ID")
9089
}
9190

9291
/* Tests that Checks have an implicit name which matches the ID even when the ID is missing. */
9392
@Test
9493
def void testCheckNameIDIsMissing() {
9594
val check = util.getFirstInstanceOf(parser.parse(modelUtil.modelWithCheck("")), typeof(Check))
96-
assertNull("Check name is null", check.name)
95+
assertNull(check.name, "Check name is null")
9796
}
9897

9998
/* Tests that multi- and single-line comments are parsed in a model. */
10099
@Test
101100
def void testCommentsInModelParse() {
102101
val model = parser.parse(modelUtil.modelWithComments)
103-
assertFalse("Syntax errors not expected but occurred", (model.eResource as XtextResource).parseResult.hasSyntaxErrors)
102+
assertFalse((model.eResource as XtextResource).parseResult.hasSyntaxErrors,
103+
"Syntax errors not expected but occurred")
104104
}
105105

106106
/* Tests that t.message is allowed, despite "message" being a keyword. */
107107
@Test
108108
def void testKeywordAsIdentifier() {
109-
val model = parser.parse(modelUtil.modelWithContext + "try { issue bind (\"mp0\", \"mp1\"); } catch (java.lang.Throwable t) { issue bind (t.message, \"foo\"); }" + "}}}}");
110-
assertFalse("Syntax errors not expected but occurred", (model.eResource as XtextResource).parseResult.hasSyntaxErrors);
109+
val model = parser.parse(
110+
modelUtil.modelWithContext +
111+
"try { issue bind (\"mp0\", \"mp1\"); } catch (java.lang.Throwable t) { issue bind (t.message, \"foo\"); }" +
112+
"}}}}");
113+
assertFalse((model.eResource as XtextResource).parseResult.hasSyntaxErrors,
114+
"Syntax errors not expected but occurred")
111115
}
112116
}

com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/BugAig1314.java

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

13-
import static org.junit.Assert.assertEquals;
14-
import static org.junit.Assert.assertFalse;
15-
import static org.junit.Assert.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertFalse;
15+
import static org.junit.jupiter.api.Assertions.assertTrue;
1616

1717
import java.io.InputStream;
1818
import java.net.MalformedURLException;
@@ -25,9 +25,9 @@
2525
import org.eclipse.xtext.resource.XtextResourceSet;
2626
import org.eclipse.xtext.scoping.IScope;
2727
import org.eclipse.xtext.testing.InjectWith;
28-
import org.eclipse.xtext.testing.XtextRunner;
29-
import org.junit.Test;
30-
import org.junit.runner.RunWith;
28+
import org.eclipse.xtext.testing.extensions.InjectionExtension;
29+
import org.junit.jupiter.api.Test;
30+
import org.junit.jupiter.api.extension.ExtendWith;
3131

3232
import com.avaloq.tools.ddk.check.CheckInjectorProvider;
3333
import com.avaloq.tools.ddk.check.runtime.configuration.IModelLocation;
@@ -39,10 +39,10 @@
3939
/**
4040
* Some tests for AIG-1314, testing that the CatalogFromExtensionPointScope does not make the resource set grow more than expected.
4141
*/
42-
@RunWith(XtextRunner.class)
42+
@ExtendWith(InjectionExtension.class)
4343
@InjectWith(CheckInjectorProvider.class)
4444
@SuppressWarnings("nls")
45-
public class BugAig1314 {
45+
class BugAig1314 {
4646

4747
/** Constructor of super class is protected... */
4848
private static class TestScope extends CatalogFromExtensionPointScope {
@@ -86,7 +86,7 @@ public InputStream getCatalogStream() {
8686
* resource set to check.
8787
*/
8888
private void assertResourceSetEmpty(final XtextResourceSet rs) {
89-
assertTrue("ResourceSet should be empty", rs.getURIResourceMap().isEmpty() && rs.getResources().isEmpty());
89+
assertTrue(rs.getURIResourceMap().isEmpty() && rs.getResources().isEmpty(), "ResourceSet should be empty");
9090
}
9191

9292
/**
@@ -100,12 +100,12 @@ private void assertResourceSetEmpty(final XtextResourceSet rs) {
100100
* expected number of resources in the resource map
101101
*/
102102
private void assertResourceSet(final XtextResourceSet rs, final int expected, final int inMap) {
103-
assertTrue("Test wrong: must expect more than zero resources", expected > 0 && inMap > 0);
104-
assertEquals("ResourceSet should not grow", expected, rs.getResources().size());
105-
assertEquals("ResourceSet map size", inMap, rs.getURIResourceMap().size());
103+
assertTrue(expected > 0 && inMap > 0, "Test wrong: must expect more than zero resources");
104+
assertEquals(expected, rs.getResources().size(), "ResourceSet should not grow");
105+
assertEquals(inMap, rs.getURIResourceMap().size(), "ResourceSet map size");
106106
for (Resource r : rs.getResources()) {
107107
URI uri = r.getURI();
108-
assertTrue(uri.toString() + " not found in ResourceSet map", rs.getURIResourceMap().containsKey(uri));
108+
assertTrue(rs.getURIResourceMap().containsKey(uri), uri.toString() + " not found in ResourceSet map");
109109
}
110110
}
111111

@@ -116,14 +116,14 @@ private void assertResourceSet(final XtextResourceSet rs, final int expected, fi
116116
* to check
117117
*/
118118
private void assertIterableNotEmpty(final Iterable<?> iterable) {
119-
assertFalse("Iterable should not be empty", Iterables.isEmpty(iterable));
119+
assertFalse(Iterables.isEmpty(iterable), "Iterable should not be empty");
120120
}
121121

122122
/**
123123
* Tests that querying the same scope twice doesn't make the resource set grow.
124124
*/
125125
@Test
126-
public void testSameScopeUseTwice() throws MalformedURLException, URISyntaxException {
126+
void testSameScopeUseTwice() throws MalformedURLException, URISyntaxException {
127127
XtextResourceSet rs = new XtextResourceSet();
128128
URL url = createURL();
129129
ModelLocation modelLocation = createModelLocation(url);
@@ -142,7 +142,7 @@ public void testSameScopeUseTwice() throws MalformedURLException, URISyntaxExcep
142142
* Tests that querying two different scopes doesn't make the resource set grow. That one was the real cause of bug AIG-1314.
143143
*/
144144
@Test
145-
public void testDifferentScopeUseTwice() throws MalformedURLException, URISyntaxException {
145+
void testDifferentScopeUseTwice() throws MalformedURLException, URISyntaxException {
146146
XtextResourceSet rs = new XtextResourceSet();
147147
URL url = createURL();
148148
ModelLocation modelLocation = createModelLocation(url);

0 commit comments

Comments
 (0)