Skip to content

Commit d8271e3

Browse files
feat: Migrate com.avaloq.tools.ddk.xtext.generator.test to Junit5
1 parent 03eb331 commit d8271e3

10 files changed

Lines changed: 80 additions & 81 deletions

File tree

com.avaloq.tools.ddk.xtext.generator.test/META-INF/MANIFEST.MF

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Require-Bundle: com.avaloq.tools.ddk.test.core,
1313
org.eclipse.xtend,
1414
org.eclipse.xtend.typesystem.emf,
1515
org.eclipse.xtext,
16-
org.junit,
1716
org.mockito.mockito-core,
1817
com.avaloq.tools.ddk.xtext.ui,
1918
org.eclipse.xtext.xtext.generator,
2019
junit-jupiter-api,
2120
junit-jupiter-engine,
22-
junit-vintage-engine
21+
junit-vintage-engine,
22+
junit-platform-suite-api
2323
Export-Package: com.avaloq.tools.ddk.xtext.generator.test.generator
2424
Import-Package: org.eclipse.xtext.ui.resource
2525
Automatic-Module-Name: com.avaloq.tools.ddk.xtext.generator.test

com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/expression/CodeGenerationXTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.xtext.generator.expression;
1212

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

1515
import java.io.IOException;
1616

1717
import org.eclipse.xtend.expression.ExecutionContextImpl;
1818
import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel;
1919
import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel;
20-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2121

2222
import com.avaloq.tools.ddk.xtext.expression.expression.Expression;
2323
import com.avaloq.tools.ddk.xtext.expression.generator.CompilationContext;
@@ -30,8 +30,8 @@
3030
/**
3131
* Tests the code generation as implemented by CodeGenerationX wrapped by {@link CompilerX}.
3232
*/
33-
@SuppressWarnings("nls")
34-
public class CodeGenerationXTest extends AbstractXtextTest {
33+
@SuppressWarnings({"nls", "PMD.SignatureDeclareThrowsException"})
34+
class CodeGenerationXTest extends AbstractXtextTest {
3535

3636
private CompilerX getCompiler() {
3737
return (CompilerX) getTestInformation().getTestObject(CompilerX.class);
@@ -61,7 +61,7 @@ protected String getTestSourceFileName() {
6161
}
6262

6363
@Test
64-
public void testliterals() throws Exception {
64+
void testliterals() throws Exception {
6565
// CHECKSTYLE:CONSTANTS-OFF
6666
assertEquals("42", compile("42")); // NOPMD
6767
assertEquals("4.2", compile("4.2")); // NOPMD
@@ -73,19 +73,19 @@ public void testliterals() throws Exception {
7373
}
7474

7575
@Test
76-
public void testListLiterals() throws Exception {
76+
void testListLiterals() throws Exception {
7777
assertEquals("java.util.Collections.<org.eclipse.emf.ecore.EObject> emptyList()", compile("{}")); // NOPMD
7878
assertEquals("java.util.Collections.singletonList(1)", compile("{1}")); // NOPMD
7979
assertEquals("com.google.common.collect.Lists.newArrayList(1, 2, 3)", compile("{1,2,3}")); // NOPMD
8080
}
8181

8282
@Test
83-
public void testIdentifiers() throws Exception {
83+
void testIdentifiers() throws Exception {
8484
assertEquals("obj.getTrue()", compile("^true")); // NOPMD
8585
}
8686

8787
@Test
88-
public void testBracketing() throws Exception {
88+
void testBracketing() throws Exception {
8989
// CHECKSTYLE:CONSTANTS-OFF
9090
assertEquals("(4 + 2) * 3", compile("(4 + 2) * 3")); // NOPMD
9191
assertEquals("(4 + 2) * 3 * 4", compile("(4 + 2) * 3 * 4")); // NOPMD
@@ -97,7 +97,7 @@ public void testBracketing() throws Exception {
9797
}
9898

9999
@Test
100-
public void testBooleanLogic() throws Exception {
100+
void testBooleanLogic() throws Exception {
101101
// CHECKSTYLE:CONSTANTS-OFF
102102
assertEquals("true", compile("true")); // NOPMD
103103
assertEquals("false", compile("false")); // NOPMD
@@ -116,7 +116,7 @@ public void testBooleanLogic() throws Exception {
116116
}
117117

118118
@Test
119-
public void testArithmetics() throws Exception {
119+
void testArithmetics() throws Exception {
120120
// CHECKSTYLE:CONSTANTS-OFF
121121
assertEquals("4 + 2", compile("4 + 2")); // NOPMD
122122
assertEquals("4 - 2", compile("4 - 2")); // NOPMD
@@ -127,7 +127,7 @@ public void testArithmetics() throws Exception {
127127
}
128128

129129
@Test
130-
public void testPrefixExpressions() throws Exception {
130+
void testPrefixExpressions() throws Exception {
131131
// CHECKSTYLE:CONSTANTS-OFF
132132
assertEquals("-(4 * 2)", compile("-(4 * 2)")); // NOPMD
133133
assertEquals("-(-42)", compile("-(-42)")); // NOPMD
@@ -141,7 +141,7 @@ public void testPrefixExpressions() throws Exception {
141141
}
142142

143143
@Test
144-
public void testInfixExpressions() throws Exception {
144+
void testInfixExpressions() throws Exception {
145145
// CHECKSTYLE:CONSTANTS-OFF
146146
assertEquals("(true ? 1 : 2) + 3", compile("(true ? 1 : 2) + 3")); // NOPMD
147147
assertEquals("!(true ? true : false)", compile("!(true ? true : false)")); // NOPMD
@@ -150,50 +150,50 @@ public void testInfixExpressions() throws Exception {
150150
}
151151

152152
@Test
153-
public void testImplicitVariable() throws Exception {
153+
void testImplicitVariable() throws Exception {
154154
assertEquals("obj", compile("this")); // NOPMD
155155
}
156156

157157
@Test
158-
public void testCasting() throws Exception {
158+
void testCasting() throws Exception {
159159
assertEquals("((org.eclipse.emf.ecore.EObject) obj)", compile("(ecore::EObject) this")); // NOPMD
160160
}
161161

162162
@Test
163-
public void testTypes() throws Exception {
163+
void testTypes() throws Exception {
164164
assertEquals("org.eclipse.emf.ecore.EObject", compile("ecore::EObject")); // NOPMD
165165
assertEquals("String", compile("java::lang::String")); // NOPMD
166166
}
167167

168168
@Test
169-
public void testIsInstance() throws Exception {
169+
void testIsInstance() throws Exception {
170170
assertEquals("obj instanceof org.eclipse.emf.ecore.EObject", compile("ecore::EObject.isInstance(this)")); // NOPMD
171171
}
172172

173173
@Test
174-
public void testEContainerNavigation() throws Exception {
174+
void testEContainerNavigation() throws Exception {
175175
// CHECKSTYLE:CONSTANTS-OFF
176176
assertEquals("obj.eContainer()", compile("this.eContainer")); // NOPMD
177177
assertEquals("obj.eContainer()", compile("this.eContainer()")); // NOPMD
178178
// CHECKSTYLE:CONSTANTS-ON
179179
}
180180

181181
@Test
182-
public void testTypeSelect() throws Exception {
182+
void testTypeSelect() throws Exception {
183183
assertEquals(// NOPMD
184184
"com.google.common.collect.Iterables.filter(obj.getFoos(), org.eclipse.emf.ecore.EObject.class)", compile("this.foos.typeSelect(ecore::EObject)"));
185185
assertEquals(// NOPMD
186186
"com.google.common.collect.Iterables.filter(java.util.Collections.singletonList(obj), org.eclipse.emf.ecore.EObject.class)", compile("{this}.typeSelect(ecore::EObject)"));
187187
}
188188

189189
@Test
190-
public void testCollectionExpression() throws Exception {
190+
void testCollectionExpression() throws Exception {
191191
assertEquals(// NOPMD
192192
"com.google.common.collect.Iterables.filter(java.util.Collections.singletonList(obj), new com.google.common.base.Predicate<Object>() { public boolean apply(Object e) {return true;} })", compile("{this}.select(e|true)"));
193193
}
194194

195195
@Test
196-
public void testMultipleNavigations() throws Exception {
196+
void testMultipleNavigations() throws Exception {
197197
assertEquals(// NOPMD
198198
"/* NOT COMPILABLE: Complex expressions like \"this.eContainer.eContainer\" cannot be translated to Java. Consider rewriting the expression or using a JAVA extension. */", compile("this.eContainer.eContainer"));
199199
assertEquals(// NOPMD

com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/expression/CompilationContextTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.xtext.generator.expression;
1212

13-
import static org.junit.Assert.assertSame;
14-
import static org.junit.Assert.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.assertSame;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
1515

1616
import java.io.InputStreamReader;
1717
import java.nio.charset.StandardCharsets;
@@ -21,41 +21,41 @@
2121
import org.eclipse.xtend.expression.ExecutionContextImpl;
2222
import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel;
2323
import org.eclipse.xtend.typesystem.Type;
24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
import com.avaloq.tools.ddk.xtext.expression.generator.CompilationContext;
2727

2828

29-
@SuppressWarnings("nls")
30-
public class CompilationContextTest {
29+
@SuppressWarnings({"nls", "PMD.SignatureDeclareThrowsException"})
30+
class CompilationContextTest {
3131

3232
@Test
33-
public void isExtension() {
33+
void isExtension() {
3434
ExecutionContextImpl executionContext = new ExecutionContextImpl();
3535
executionContext.registerMetaModel(new JavaBeansMetaModel());
3636
ExtensionFile extensionFile = ParseFacade.file(new InputStreamReader(getClass().getResourceAsStream("/com/avaloq/tools/ddk/xtext/generator/expression/TestExtensions.ext"), StandardCharsets.UTF_8), "TestExtensions.ext");
3737
executionContext = (ExecutionContextImpl) executionContext.cloneWithResource(extensionFile);
3838
final CompilationContext context = new CompilationContext(executionContext, null);
3939

40-
assertTrue("test extension not identified", context.isExtension("test"));
40+
assertTrue(context.isExtension("test"), "test extension not identified");
4141
}
4242

4343
@Test
44-
public void analyze() {
44+
void analyze() {
4545
ExecutionContextImpl executionContext = new ExecutionContextImpl();
4646
executionContext.registerMetaModel(new JavaBeansMetaModel());
4747
final CompilationContext context = new CompilationContext(executionContext, null);
4848

4949
Type expectedType = executionContext.getTypeForName("Integer");
50-
assertSame("Cannot analyze Integer", expectedType, context.analyze("1 + 3"));
50+
assertSame(expectedType, context.analyze("1 + 3"), "Cannot analyze Integer");
5151

5252
expectedType = executionContext.getTypeForName("Real");
53-
assertSame("Cannot analyze Real", expectedType, context.analyze("1 + 3.33"));
53+
assertSame(expectedType, context.analyze("1 + 3.33"), "Cannot analyze Real");
5454

5555
expectedType = executionContext.getTypeForName("String");
56-
assertSame("Cannot analyse String 'foo'", expectedType, context.analyze("\'foo\'"));
57-
assertSame("Cannot analyse String \"foo \" ", expectedType, context.analyze("\"foo\""));
58-
assertSame("Cannot analyse String \"foo\" + \'bar\'", expectedType, context.analyze("\"foo\" + \'bar\'"));
56+
assertSame(expectedType, context.analyze("\'foo\'"), "Cannot analyse String 'foo'");
57+
assertSame(expectedType, context.analyze("\"foo\""), "Cannot analyse String \"foo \" ");
58+
assertSame(expectedType, context.analyze("\"foo\" + \'bar\'"), "Cannot analyse String \"foo\" + \'bar\'");
5959
}
6060

6161
}

com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/expression/ExpressionsExtentionsTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.xtext.generator.expression;
1212

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

1515
import java.io.IOException;
1616

17-
import org.junit.Test;
17+
import org.junit.jupiter.api.Test;
1818

1919
import com.avaloq.tools.ddk.xtext.expression.expression.Expression;
2020
import com.avaloq.tools.ddk.xtext.expression.generator.ExpressionExtensions;
@@ -23,7 +23,7 @@
2323

2424

2525
@SuppressWarnings("nls")
26-
public class ExpressionsExtentionsTest extends AbstractXtextTest {
26+
class ExpressionsExtentionsTest extends AbstractXtextTest {
2727

2828
@Override
2929
protected GeneratorTestUtil getXtextTestUtil() {
@@ -39,7 +39,8 @@ protected String getTestSourceFileName() {
3939
}
4040

4141
@Test
42-
public final void serialize() throws IOException {
42+
@SuppressWarnings({"PMD.SignatureDeclareThrowsException"})
43+
void serialize() throws IOException {
4344
Expression e = (Expression) getXtextTestUtil().getModel("test.expression." + getXtextTestUtil().getFileExtension(), "let x = 1 : 0");
4445
assertEquals("Simple serialization works", "let x = 1 : 0", ExpressionExtensions.serialize(e));
4546
}

com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/test/generator/GeneratorTestSuite.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,21 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.xtext.generator.test.generator;
1212

13-
import org.junit.runner.RunWith;
14-
import org.junit.runners.Suite;
15-
16-
import com.avaloq.tools.ddk.xtext.generator.expression.CodeGenerationXTest;
17-
import com.avaloq.tools.ddk.xtext.generator.expression.CompilationContextTest;
18-
import com.avaloq.tools.ddk.xtext.generator.expression.ExpressionsExtentionsTest;
19-
import com.avaloq.tools.ddk.xtext.generator.test.util.EClassComparatorTest;
20-
import com.avaloq.tools.ddk.xtext.generator.test.util.GraphTest;
13+
import org.junit.platform.suite.api.SelectPackages;
14+
import org.junit.platform.suite.api.Suite;
2115

2216

2317
/**
24-
* Empty class serving only as holder for JUnit4 annotations.
18+
* Junit5 version of test suites. does not implement the logic in our DiscerningSuite.
2519
*/
26-
@RunWith(Suite.class)
27-
@Suite.SuiteClasses({
20+
@Suite
21+
@SelectPackages({
2822
// @Format-Off
29-
GraphTest.class,
30-
EClassComparatorTest.class,
31-
CodeGenerationXTest.class,
32-
CompilationContextTest.class,
33-
ExpressionsExtentionsTest.class
34-
// @Format-On
23+
"com.avaloq.tools.ddk.xtext.generator.expression",
24+
"com.avaloq.tools.ddk.xtext.generator.test.util",
25+
"com.avaloq.tools.ddk.xtext.generator.xbase.test"
26+
// @Format-On
3527
})
28+
3629
public class GeneratorTestSuite {
3730
}

com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/test/util/EClassComparatorTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
import static org.eclipse.emf.ecore.EcorePackage.Literals.EDATA_TYPE;
1616
import static org.eclipse.emf.ecore.EcorePackage.Literals.EOBJECT;
1717
import static org.eclipse.emf.ecore.EcorePackage.Literals.EPACKAGE;
18-
import static org.junit.Assert.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

2020
import java.util.List;
2121

2222
import org.eclipse.emf.ecore.EClass;
2323
import org.eclipse.emf.ecore.EPackage;
2424
import org.eclipse.emf.ecore.EcorePackage;
2525
import org.eclipse.xtext.XtextPackage;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727

2828
import com.avaloq.tools.ddk.xtext.expression.generator.EClassComparator;
2929
import com.google.common.base.Function;
@@ -33,12 +33,12 @@
3333

3434

3535
@SuppressWarnings("PMD.JUnitAssertionsShouldIncludeMessage")
36-
public class EClassComparatorTest {
36+
class EClassComparatorTest {
3737

3838
private final Function<EClass, EClass> mapping = Functions.<EClass> identity();
3939

4040
@Test
41-
public void testSorting() {
41+
void testSorting() {
4242
List<EClass> sorted = EClassComparator.sortedGroups(Lists.newArrayList(ECLASS, EDATA_TYPE, EPACKAGE, ECLASSIFIER), mapping);
4343
assertEquals(Lists.newArrayList(ECLASS, EDATA_TYPE, EPACKAGE, ECLASSIFIER), sorted);
4444

@@ -53,7 +53,7 @@ public void testSorting() {
5353
}
5454

5555
@Test
56-
public void testSortingWithEObject() {
56+
void testSortingWithEObject() {
5757
List<EClass> sorted = EClassComparator.sortedGroups(Lists.newArrayList(EOBJECT, ECLASS), mapping);
5858
assertEquals(Lists.newArrayList(ECLASS, EOBJECT), sorted);
5959

@@ -62,7 +62,7 @@ public void testSortingWithEObject() {
6262
}
6363

6464
@Test
65-
public void testSortingByEPackage() {
65+
void testSortingByEPackage() {
6666
ListMultimap<EPackage, EClass> sorted = EClassComparator.sortedEPackageGroups(Lists.newArrayList(EOBJECT, ECLASS), mapping);
6767
assertEquals(2, sorted.size());
6868
assertEquals(1, sorted.keySet().size());

com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/test/util/GraphTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.xtext.generator.test.util;
1212

13-
import static org.junit.Assert.assertTrue;
14-
import static org.junit.Assert.fail;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
import static org.junit.jupiter.api.Assertions.fail;
1515

1616
import java.util.List;
1717
import java.util.Map;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import com.avaloq.tools.ddk.xtext.expression.generator.Graph;
2222
import com.google.common.collect.HashMultimap;
@@ -25,11 +25,11 @@
2525

2626

2727
@SuppressWarnings({"PMD.JUnitAssertionsShouldIncludeMessage", "nls"})
28-
public class GraphTest {
28+
class GraphTest {
2929
// CHECKSTYLE:CONSTANTS-OFF
3030

3131
@Test
32-
public void testTopologicalSorting() {
32+
void testTopologicalSorting() {
3333
Multimap<String, String> graph = HashMultimap.create();
3434
graph.put("7", "11");
3535
graph.put("7", "8");
@@ -47,7 +47,7 @@ public void testTopologicalSorting() {
4747
}
4848

4949
@Test
50-
public void testDependencyCycle() {
50+
void testDependencyCycle() {
5151
Multimap<String, String> graph = ImmutableMultimap.of("1", "2", "2", "3", "3", "1");
5252

5353
try {

0 commit comments

Comments
 (0)