Skip to content

Commit

Permalink
Reintroduced ValidatorTester in xtext.testing bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Nov 29, 2023
1 parent 652c2c4 commit 28dd893
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
/*******************************************************************************
* Copyright (c) 2009 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2023 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;
package org.eclipse.xtext.testing.validation;

import java.util.Map;

import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EDataType;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.xtext.testing.validation.AssertableDiagnostics;

/**
* @author Moritz Eysholdt - Initial contribution and API
*
* @since 2.34
*/
public abstract class AbstractValidatorTester {

Expand All @@ -27,7 +28,7 @@ public AssertableDiagnostics validate(EDataType type, Object obj) {
Diagnostic d = diagnostician.validate(type, obj);
return new AssertableDiagnostics(d);
}

public AssertableDiagnostics validate(EObject obj) {
Diagnostic d = diagnostician.validate(obj);
return new AssertableDiagnostics(d);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
/*******************************************************************************
* Copyright (c) 2009 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2023 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;
package org.eclipse.xtext.testing.validation;

import org.eclipse.emf.common.util.BasicDiagnostic;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EValidator;
import org.eclipse.emf.ecore.impl.EValidatorRegistryImpl;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.xtext.Constants;
import org.eclipse.xtext.testing.validation.AssertableDiagnostics;
import org.eclipse.xtext.validation.AbstractDeclarativeValidator;
import org.eclipse.xtext.validation.AbstractDeclarativeValidator.State;
import org.eclipse.xtext.validation.AbstractInjectableValidator;
import org.eclipse.xtext.validation.EValidatorRegistrar;

import com.google.inject.Inject;
import com.google.inject.Injector;
Expand All @@ -25,6 +27,8 @@

/**
* @author Moritz Eysholdt - Initial contribution and API
*
* @since 2.34
*/
public class ValidatorTester<T extends AbstractDeclarativeValidator> extends AbstractValidatorTester {

Expand All @@ -37,7 +41,7 @@ public ValidatorTester(T validator, Injector injector) {
injector.getInstance(EValidatorRegistrar.class),
injector.getInstance(Key.get(String.class, Names.named(Constants.LANGUAGE_NAME))));
}

@Inject
public ValidatorTester(T validator, EValidatorRegistrar registrar, @Named(Constants.LANGUAGE_NAME) final String languageName) {
this.validator = validator;
Expand All @@ -56,7 +60,7 @@ public java.util.Map<Object,Object> createDefaultContext() {
registrar.setRegistry(originalRegistry);
validatorCalled = false;
}

public AssertableDiagnostics diagnose() {
if (!validatorCalled)
throw new IllegalStateException("You have to call validator() before you call diagnose()");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.xtext.XtextStandaloneSetup;
import org.eclipse.xtext.testing.validation.ValidatorTester;
import org.eclipse.xtext.tests.AbstractXtextTests;
import org.junit.Test;

Expand Down

0 comments on commit 28dd893

Please sign in to comment.