Skip to content
Merged
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
11 changes: 3 additions & 8 deletions com.avaloq.tools.ddk.check.core.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Require-Bundle: com.avaloq.tools.ddk.check.core,
org.eclipse.xtend.lib,
org.eclipse.xtext.ui.testing,
org.eclipse.xtext.testing,
org.junit,
org.mockito.mockito-core,
com.avaloq.tools.ddk.check.runtime.core,
org.eclipse.ui.workbench;resolution:=optional,
Expand All @@ -31,15 +30,11 @@ Require-Bundle: com.avaloq.tools.ddk.check.core,
org.eclipse.xtext.xbase.testing,
junit-jupiter-api,
junit-jupiter-engine,
junit-vintage-engine
junit-vintage-engine,
junit-platform-suite-api
Export-Package: com.avaloq.tools.ddk.check.core.test,
com.avaloq.tools.ddk.check.core.test.util,
com.avaloq.tools.ddk.check.test.core,
com.avaloq.tools.ddk.check
Import-Package: org.junit.runner;version="4.5.0",
org.junit.runner.manipulation;version="4.5.0",
org.junit.runner.notification;version="4.5.0",
org.junit.runners;version="4.5.0",
org.junit.runners.model;version="4.5.0",
org.hamcrest.core
Import-Package: org.hamcrest.core
Automatic-Module-Name: com.avaloq.tools.ddk.check.core.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
package com.avaloq.tools.ddk.check.core.generator

import org.eclipse.xtext.testing.InjectWith
import org.junit.runner.RunWith
import com.avaloq.tools.ddk.check.CheckInjectorProvider
import org.eclipse.xtext.testing.XtextRunner
import com.avaloq.tools.ddk.check.core.test.AbstractCheckGenerationTestCase
import org.junit.Test
import java.util.List
import org.eclipse.xtext.xbase.testing.JavaSource
import java.io.ByteArrayInputStream
import org.junit.jupiter.api.^extension.ExtendWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.junit.jupiter.api.Test
import static org.junit.jupiter.api.Assertions.assertTrue

@InjectWith(CheckInjectorProvider)
@RunWith(XtextRunner)
@ExtendWith(InjectionExtension)
class IssueCodeValueTest extends AbstractCheckGenerationTestCase {

static final String PACKAGE_NAME = "mypackage"
Expand Down Expand Up @@ -96,7 +97,7 @@ class IssueCodeValueTest extends AbstractCheckGenerationTestCase {

for (issueCode: expectedIssueCodeValues.entrySet) {
val expectedIssueCodeAssignment = '''public static final String «issueCode.key» = "«PACKAGE_NAME».«CATALOG_NAME»«ISSUE_CODES_SUFFIX».«issueCode.value»";'''
assertTrue('''«issueCodesClassName» contains correct initialization of «issueCode.key»''', issueCodesClass.contains(expectedIssueCodeAssignment))
assertTrue(issueCodesClass.contains(expectedIssueCodeAssignment), '''«issueCodesClassName» contains correct initialization of «issueCode.key»''')
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

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

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

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
Expand Down Expand Up @@ -76,7 +80,7 @@ public List<JavaSource> generateAndCompile(final InputStream sourceStream) {
fail("Could not load test resource" + e.getMessage());
}
CheckCatalog root = (CheckCatalog) res.getContents().get(0);
assertNotNull("Resource should contain a CheckCatalog", root);
assertNotNull(root, "Resource should contain a CheckCatalog");
// We also should have some Jvm model here.
JvmType type = null;
for (EObject obj : res.getContents()) {
Expand All @@ -85,7 +89,7 @@ public List<JavaSource> generateAndCompile(final InputStream sourceStream) {
break;
}
}
assertNotNull("Should have an inferred Jvm model", type);
assertNotNull(type, "Should have an inferred Jvm model");
// Run the generator using an in-memory file system access
InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
for (OutputConfiguration output : outputConfigurationProvider.getOutputConfigurations()) {
Expand All @@ -107,7 +111,7 @@ public List<JavaSource> generateAndCompile(final InputStream sourceStream) {
final InMemoryJavaCompiler.Result result = javaCompiler.compile(sources.toArray(new JavaSource[sources.size()]));
// Due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=541225 we must ignore this warning here
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()))) {
assertTrue("All sources should have been compiled without errors " + result.getCompilationProblems(), result.getCompilationProblems().isEmpty());
assertTrue(result.getCompilationProblems().isEmpty(), "All sources should have been compiled without errors " + result.getCompilationProblems());
}

return sources;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
package com.avaloq.tools.ddk.check.core.test;

import static com.google.common.collect.Sets.newHashSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -38,9 +41,9 @@
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.ui.testing.util.IResourcesSetupUtil;
import org.eclipse.xtext.util.StringInputStream;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;

import com.avaloq.tools.ddk.check.CheckConstants;
import com.avaloq.tools.ddk.check.ui.internal.CheckActivator;
Expand All @@ -54,14 +57,12 @@
import com.google.inject.Injector;
import com.google.inject.Provider;

import junit.framework.TestCase;


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

@Override
@Before
@BeforeEach
public void setUp() throws Exception {
getInjector().injectMembers(this);
}
Expand All @@ -83,7 +83,7 @@ public void setUp() throws Exception {
* @throws Exception
* the exception
*/
@BeforeClass
@BeforeAll
public static void prepareWorkspace() throws Exception {
PROJECT_MANAGER.setup(ImmutableList.<TestSource> of());
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public <T> T get(final Class<T> clazz) {
/**
* Clean up after all tests have terminated.
*/
@AfterClass
@AfterAll
public static void cleanUp() {
PROJECT_MANAGER.teardown();
}
Expand Down Expand Up @@ -215,7 +215,7 @@ public EObject getModel(final String fileName, final String content) throws Exce
IFile file = createFile(fileName, content);
Resource resource = get(XtextResourceSet.class).createResource(uri(file));
resource.load(new StringInputStream(content), null);
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
assertEquals(0, resource.getErrors().size(), resource.getErrors().toString());
return resource.getContents().get(0);
}

Expand Down Expand Up @@ -264,7 +264,7 @@ public EObject getModel(final String fileName) throws Exception { // NOPMD
}
}
}
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
assertEquals(0, resource.getErrors().size(), resource.getErrors().toString());
return resource.getContents().get(0);
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*
* Contributors:
* Avaloq Group AG - initial API and implementation
*******************************************************************************/
Expand All @@ -19,16 +19,15 @@ import com.avaloq.tools.ddk.check.core.test.util.CheckTestUtil
import com.google.inject.Inject
import org.eclipse.xtext.resource.XtextResource
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

import static org.junit.Assert.*
import org.junit.jupiter.api.Test
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.junit.jupiter.api.^extension.ExtendWith
import static org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Disabled

@InjectWith(typeof(CheckUiInjectorProvider))
@RunWith(typeof(XtextRunner))
@ExtendWith(typeof(InjectionExtension))
class BasicModelTest {

@Inject
Expand All @@ -46,7 +45,7 @@ class BasicModelTest {
@Test
def void testCreateEmptyModelWithPackageReference() {
val model = parser.parse("package p catalog c {}")
assertNotNull("CheckCatalog with EPackage reference successfully created", model);
assertNotNull(model, "CheckCatalog with EPackage reference successfully created")
}

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

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

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

/* Tests that Checks have an implicit name which matches the ID. */
@Test
def void testCheckNameIDIsPresent() {
val id = "CheckID"
val check = util.getFirstInstanceOf(parser.parse(modelUtil.modelWithCheck(id)), typeof(Check))
assertEquals("Check name field matches ID field", check.id, check.name)
assertEquals("Check name field matches supplied ID", id, check.name)
assertEquals(check.id, check.name, "Check name field matches ID field")
assertEquals(id, check.name, "Check name field matches supplied ID")
}

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

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

/* Tests that t.message is allowed, despite "message" being a keyword. */
@Test
def void testKeywordAsIdentifier() {
val model = parser.parse(modelUtil.modelWithContext + "try { issue bind (\"mp0\", \"mp1\"); } catch (java.lang.Throwable t) { issue bind (t.message, \"foo\"); }" + "}}}}");
assertFalse("Syntax errors not expected but occurred", (model.eResource as XtextResource).parseResult.hasSyntaxErrors);
val model = parser.parse(
modelUtil.modelWithContext +
"try { issue bind (\"mp0\", \"mp1\"); } catch (java.lang.Throwable t) { issue bind (t.message, \"foo\"); }" +
"}}}}");
assertFalse((model.eResource as XtextResource).parseResult.hasSyntaxErrors,
"Syntax errors not expected but occurred")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
*******************************************************************************/
package com.avaloq.tools.ddk.check.core.test;

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

import java.io.InputStream;
import java.net.MalformedURLException;
Expand All @@ -25,9 +25,9 @@
import org.eclipse.xtext.resource.XtextResourceSet;
import org.eclipse.xtext.scoping.IScope;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.XtextRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.eclipse.xtext.testing.extensions.InjectionExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

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

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

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

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

/**
* Tests that querying the same scope twice doesn't make the resource set grow.
*/
@Test
public void testSameScopeUseTwice() throws MalformedURLException, URISyntaxException {
void testSameScopeUseTwice() throws MalformedURLException, URISyntaxException {
XtextResourceSet rs = new XtextResourceSet();
URL url = createURL();
ModelLocation modelLocation = createModelLocation(url);
Expand All @@ -142,7 +142,7 @@ public void testSameScopeUseTwice() throws MalformedURLException, URISyntaxExcep
* Tests that querying two different scopes doesn't make the resource set grow. That one was the real cause of bug AIG-1314.
*/
@Test
public void testDifferentScopeUseTwice() throws MalformedURLException, URISyntaxException {
void testDifferentScopeUseTwice() throws MalformedURLException, URISyntaxException {
XtextResourceSet rs = new XtextResourceSet();
URL url = createURL();
ModelLocation modelLocation = createModelLocation(url);
Expand Down
Loading