Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Require-Bundle: com.avaloq.tools.ddk.test.core,
org.eclipse.xtend,
org.eclipse.xtend.typesystem.emf,
org.eclipse.xtext,
org.junit,
org.mockito.mockito-core,
com.avaloq.tools.ddk.xtext.ui,
org.eclipse.xtext.xtext.generator,
junit-jupiter-api,
junit-jupiter-engine,
junit-vintage-engine
junit-vintage-engine,
junit-platform-suite-api
Export-Package: com.avaloq.tools.ddk.xtext.generator.test.generator
Import-Package: org.eclipse.xtext.ui.resource
Automatic-Module-Name: com.avaloq.tools.ddk.xtext.generator.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
*******************************************************************************/
package com.avaloq.tools.ddk.xtext.generator.expression;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel;
import org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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

private CompilerX getCompiler() {
return (CompilerX) getTestInformation().getTestObject(CompilerX.class);
Expand Down Expand Up @@ -61,7 +61,7 @@ protected String getTestSourceFileName() {
}

@Test
public void testliterals() throws Exception {
void testliterals() throws Exception {
// CHECKSTYLE:CONSTANTS-OFF
assertEquals("42", compile("42")); // NOPMD
assertEquals("4.2", compile("4.2")); // NOPMD
Expand All @@ -73,19 +73,19 @@ public void testliterals() throws Exception {
}

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

@Test
public void testIdentifiers() throws Exception {
void testIdentifiers() throws Exception {
assertEquals("obj.getTrue()", compile("^true")); // NOPMD
}

@Test
public void testBracketing() throws Exception {
void testBracketing() throws Exception {
// CHECKSTYLE:CONSTANTS-OFF
assertEquals("(4 + 2) * 3", compile("(4 + 2) * 3")); // NOPMD
assertEquals("(4 + 2) * 3 * 4", compile("(4 + 2) * 3 * 4")); // NOPMD
Expand All @@ -97,7 +97,7 @@ public void testBracketing() throws Exception {
}

@Test
public void testBooleanLogic() throws Exception {
void testBooleanLogic() throws Exception {
// CHECKSTYLE:CONSTANTS-OFF
assertEquals("true", compile("true")); // NOPMD
assertEquals("false", compile("false")); // NOPMD
Expand All @@ -116,7 +116,7 @@ public void testBooleanLogic() throws Exception {
}

@Test
public void testArithmetics() throws Exception {
void testArithmetics() throws Exception {
// CHECKSTYLE:CONSTANTS-OFF
assertEquals("4 + 2", compile("4 + 2")); // NOPMD
assertEquals("4 - 2", compile("4 - 2")); // NOPMD
Expand All @@ -127,7 +127,7 @@ public void testArithmetics() throws Exception {
}

@Test
public void testPrefixExpressions() throws Exception {
void testPrefixExpressions() throws Exception {
// CHECKSTYLE:CONSTANTS-OFF
assertEquals("-(4 * 2)", compile("-(4 * 2)")); // NOPMD
assertEquals("-(-42)", compile("-(-42)")); // NOPMD
Expand All @@ -141,7 +141,7 @@ public void testPrefixExpressions() throws Exception {
}

@Test
public void testInfixExpressions() throws Exception {
void testInfixExpressions() throws Exception {
// CHECKSTYLE:CONSTANTS-OFF
assertEquals("(true ? 1 : 2) + 3", compile("(true ? 1 : 2) + 3")); // NOPMD
assertEquals("!(true ? true : false)", compile("!(true ? true : false)")); // NOPMD
Expand All @@ -150,50 +150,50 @@ public void testInfixExpressions() throws Exception {
}

@Test
public void testImplicitVariable() throws Exception {
void testImplicitVariable() throws Exception {
assertEquals("obj", compile("this")); // NOPMD
}

@Test
public void testCasting() throws Exception {
void testCasting() throws Exception {
assertEquals("((org.eclipse.emf.ecore.EObject) obj)", compile("(ecore::EObject) this")); // NOPMD
}

@Test
public void testTypes() throws Exception {
void testTypes() throws Exception {
assertEquals("org.eclipse.emf.ecore.EObject", compile("ecore::EObject")); // NOPMD
assertEquals("String", compile("java::lang::String")); // NOPMD
}

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

@Test
public void testEContainerNavigation() throws Exception {
void testEContainerNavigation() throws Exception {
// CHECKSTYLE:CONSTANTS-OFF
assertEquals("obj.eContainer()", compile("this.eContainer")); // NOPMD
assertEquals("obj.eContainer()", compile("this.eContainer()")); // NOPMD
// CHECKSTYLE:CONSTANTS-ON
}

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

@Test
public void testCollectionExpression() throws Exception {
void testCollectionExpression() throws Exception {
assertEquals(// NOPMD
"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)"));
}

@Test
public void testMultipleNavigations() throws Exception {
void testMultipleNavigations() throws Exception {
assertEquals(// NOPMD
"/* 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"));
assertEquals(// NOPMD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*******************************************************************************/
package com.avaloq.tools.ddk.xtext.generator.expression;

import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
Expand All @@ -21,41 +21,41 @@
import org.eclipse.xtend.expression.ExecutionContextImpl;
import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel;
import org.eclipse.xtend.typesystem.Type;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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


@SuppressWarnings("nls")
public class CompilationContextTest {
@SuppressWarnings({"nls", "PMD.SignatureDeclareThrowsException"})
class CompilationContextTest {

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

assertTrue("test extension not identified", context.isExtension("test"));
assertTrue(context.isExtension("test"), "test extension not identified");
}

@Test
public void analyze() {
void analyze() {
ExecutionContextImpl executionContext = new ExecutionContextImpl();
executionContext.registerMetaModel(new JavaBeansMetaModel());
final CompilationContext context = new CompilationContext(executionContext, null);

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

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

expectedType = executionContext.getTypeForName("String");
assertSame("Cannot analyse String 'foo'", expectedType, context.analyze("\'foo\'"));
assertSame("Cannot analyse String \"foo \" ", expectedType, context.analyze("\"foo\""));
assertSame("Cannot analyse String \"foo\" + \'bar\'", expectedType, context.analyze("\"foo\" + \'bar\'"));
assertSame(expectedType, context.analyze("\'foo\'"), "Cannot analyse String 'foo'");
assertSame(expectedType, context.analyze("\"foo\""), "Cannot analyse String \"foo \" ");
assertSame(expectedType, context.analyze("\"foo\" + \'bar\'"), "Cannot analyse String \"foo\" + \'bar\'");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
*******************************************************************************/
package com.avaloq.tools.ddk.xtext.generator.expression;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.avaloq.tools.ddk.xtext.expression.expression.Expression;
import com.avaloq.tools.ddk.xtext.expression.generator.ExpressionExtensions;
Expand All @@ -23,7 +23,7 @@


@SuppressWarnings("nls")
public class ExpressionsExtentionsTest extends AbstractXtextTest {
class ExpressionsExtentionsTest extends AbstractXtextTest {

@Override
protected GeneratorTestUtil getXtextTestUtil() {
Expand All @@ -39,7 +39,8 @@ protected String getTestSourceFileName() {
}

@Test
public final void serialize() throws IOException {
@SuppressWarnings({"PMD.SignatureDeclareThrowsException"})
void serialize() throws IOException {
Expression e = (Expression) getXtextTestUtil().getModel("test.expression." + getXtextTestUtil().getFileExtension(), "let x = 1 : 0");
assertEquals("Simple serialization works", "let x = 1 : 0", ExpressionExtensions.serialize(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,21 @@
*******************************************************************************/
package com.avaloq.tools.ddk.xtext.generator.test.generator;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import com.avaloq.tools.ddk.xtext.generator.expression.CodeGenerationXTest;
import com.avaloq.tools.ddk.xtext.generator.expression.CompilationContextTest;
import com.avaloq.tools.ddk.xtext.generator.expression.ExpressionsExtentionsTest;
import com.avaloq.tools.ddk.xtext.generator.test.util.EClassComparatorTest;
import com.avaloq.tools.ddk.xtext.generator.test.util.GraphTest;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;


/**
* Empty class serving only as holder for JUnit4 annotations.
* Junit5 version of test suites. does not implement the logic in our DiscerningSuite.
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
@Suite
@SelectPackages({
// @Format-Off
GraphTest.class,
EClassComparatorTest.class,
CodeGenerationXTest.class,
CompilationContextTest.class,
ExpressionsExtentionsTest.class
// @Format-On
"com.avaloq.tools.ddk.xtext.generator.expression",
"com.avaloq.tools.ddk.xtext.generator.test.util",
"com.avaloq.tools.ddk.xtext.generator.xbase.test"
// @Format-On
})

public class GeneratorTestSuite {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
import static org.eclipse.emf.ecore.EcorePackage.Literals.EDATA_TYPE;
import static org.eclipse.emf.ecore.EcorePackage.Literals.EOBJECT;
import static org.eclipse.emf.ecore.EcorePackage.Literals.EPACKAGE;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.xtext.XtextPackage;
import org.junit.Test;
import org.junit.jupiter.api.Test;

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


@SuppressWarnings("PMD.JUnitAssertionsShouldIncludeMessage")
public class EClassComparatorTest {
class EClassComparatorTest {

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

@Test
public void testSorting() {
void testSorting() {
List<EClass> sorted = EClassComparator.sortedGroups(Lists.newArrayList(ECLASS, EDATA_TYPE, EPACKAGE, ECLASSIFIER), mapping);
assertEquals(Lists.newArrayList(ECLASS, EDATA_TYPE, EPACKAGE, ECLASSIFIER), sorted);

Expand All @@ -53,7 +53,7 @@ public void testSorting() {
}

@Test
public void testSortingWithEObject() {
void testSortingWithEObject() {
List<EClass> sorted = EClassComparator.sortedGroups(Lists.newArrayList(EOBJECT, ECLASS), mapping);
assertEquals(Lists.newArrayList(ECLASS, EOBJECT), sorted);

Expand All @@ -62,7 +62,7 @@ public void testSortingWithEObject() {
}

@Test
public void testSortingByEPackage() {
void testSortingByEPackage() {
ListMultimap<EPackage, EClass> sorted = EClassComparator.sortedEPackageGroups(Lists.newArrayList(EOBJECT, ECLASS), mapping);
assertEquals(2, sorted.size());
assertEquals(1, sorted.keySet().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
*******************************************************************************/
package com.avaloq.tools.ddk.xtext.generator.test.util;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.junit.jupiter.api.Test;

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


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

@Test
public void testTopologicalSorting() {
void testTopologicalSorting() {
Multimap<String, String> graph = HashMultimap.create();
graph.put("7", "11");
graph.put("7", "8");
Expand All @@ -47,7 +47,7 @@ public void testTopologicalSorting() {
}

@Test
public void testDependencyCycle() {
void testDependencyCycle() {
Multimap<String, String> graph = ImmutableMultimap.of("1", "2", "2", "3", "3", "1");

try {
Expand Down
Loading