[#1648] fixed regression in InjectionExtension

Signed-off-by: Christian Dietrich <christian.dietrich@itemis.de>
This commit is contained in:
Christian Dietrich 2020-12-18 09:58:29 +01:00
parent 7c30d2ccf7
commit c6daeb75a5
5 changed files with 90 additions and 15 deletions

View file

@ -62,7 +62,7 @@ public class InjectionExtension implements BeforeEachCallback, AfterEachCallback
public RegistryReset(IRegistryConfigurator resetter) {
this.resetter = resetter;
resetter.setupRegistry();
setup();
}
public void setup() {

View file

@ -3,23 +3,25 @@
*/
package org.eclipse.xtext.testlanguages.fileAware.validation;
import org.eclipse.xtext.testlanguages.fileAware.fileAware.Element;
import org.eclipse.xtext.testlanguages.fileAware.fileAware.FileAwarePackage;
import org.eclipse.xtext.validation.Check;
/**
* This class contains custom validation rules.
* This class contains custom validation rules.
*
* See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
* See
* https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation
*/
public class FileAwareTestLanguageValidator extends AbstractFileAwareTestLanguageValidator {
// public static final INVALID_NAME = 'invalidName'
//
// @Check
// public void checkGreetingStartsWithCapital(Greeting greeting) {
// if (!Character.isUpperCase(greeting.getName().charAt(0))) {
// warning("Name should start with a capital",
// FileAwareTestLanguagePackage.Literals.GREETING__NAME,
// INVALID_NAME);
// }
// }
public static final String INVALID_NAME = "invalidName";
@Check
public void checkGreetingStartsWithCapital(Element element) {
if ("LetItFail".equals(element.getName())) {
warning("LetItFail really is a bad name!", FileAwarePackage.Literals.ELEMENT__NAME, INVALID_NAME);
}
}
}

View file

@ -13,6 +13,12 @@ dependencies {
// The MWE2 workflow depends on emf-gen, so we have to include it in the test dependencies
testCompile sourceSets.mwe2.output
testCompile 'args4j:args4j'
// optional for the utilities but mandatory to run the tests
testImplementation 'junit:junit'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.platform:junit-platform-suite-api'
testImplementation 'org.junit.platform:junit-platform-runner'
}
sourceSets.test {

View file

@ -0,0 +1,17 @@
package org.eclipse.xtext.junit5;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.UseTechnicalNames;
import org.junit.runner.RunWith;
/**
* Test suite that will pick up all Junit5 tests from the listed package and run them
* when the suite is executed with Junit4.
*/
@RunWith(JUnitPlatform.class)
@UseTechnicalNames
@SelectPackages("org.eclipse.xtext.validation.junit5")
public class RunSuiteJUnit5 {
}

View file

@ -0,0 +1,50 @@
/*******************************************************************************
* Copyright (c) 2020 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.validation.junit5;
import org.eclipse.xtext.testing.InjectWith;
import org.eclipse.xtext.testing.extensions.InjectionExtension;
import org.eclipse.xtext.testing.util.ParseHelper;
import org.eclipse.xtext.testing.validation.ValidationTestHelper;
import org.eclipse.xtext.testlanguages.fileAware.fileAware.FileAwarePackage;
import org.eclipse.xtext.testlanguages.fileAware.fileAware.PackageDeclaration;
import org.eclipse.xtext.testlanguages.fileAware.tests.FileAwareTestLanguageInjectorProvider;
import org.eclipse.xtext.testlanguages.fileAware.validation.FileAwareTestLanguageValidator;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import com.google.inject.Inject;
/**
* @author cdietrich - Initial contribution and API
*/
@ExtendWith(InjectionExtension.class)
@InjectWith(FileAwareTestLanguageInjectorProvider.class)
public class FileAwareTestLanguageValidationJunit5Test {
@Inject
private ParseHelper<PackageDeclaration> parseHelper;
@Inject
private ValidationTestHelper validationTestHelper;
@Test
public void testWithJunit5_01() throws Exception {
PackageDeclaration model = parseHelper.parse("package x element Y {}");
validationTestHelper.assertNoIssues(model);
}
@Test
public void testWithJunit5_02() throws Exception {
PackageDeclaration model = parseHelper.parse("package x element LetItFail {}");
validationTestHelper.assertWarning(model.eResource(), FileAwarePackage.Literals.ELEMENT,
FileAwareTestLanguageValidator.INVALID_NAME);
}
}