Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 335624

Summary: AbstractXtextTests does not set current language when there is no resource
Product: [Modeling] TMF Reporter: Henrik Lindberg <henrik.lindberg>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: sebastian.zarnekow, sven.efftinge
Version: 2.0.0Flags: sebastian.zarnekow: indigo+
Target Milestone: M5   
Hardware: All   
OS: All   
Whiteboard:

Description Henrik Lindberg CLA 2011-01-27 16:44:15 EST
When a test is performed (as this snippet from the documentation):

 public void testError2() { 
    FooElement model = MyLanguageFactory.eINSTANCE.createFooElement() 
    model.setBarAttribute("barbarbarbarfoo"); 
    
    tester.validate(model).assertError(101); 
  } 

And the validator is initialized in the setUp() method like this:
		super.setUp();
		with(MyStandaloneSetup.class);
		MyJavaValidator validator = get(MyJavaValidator.class);
		EValidatorRegistrar registrar = get(EValidatorRegistrar.class);
		tester = new ValidatorTester<MyJavaValidator>(validator, registrar);

Then, no methods will be called in the MyValidator unless it's isLanguageSpecific() method is overridden and returns false.

The problem seems to be that the key org.eclipse.xtext.validation.AbstractInjectableValidator.currentLanguageName is set to an empty string in the context. Looks like it is setting that from the model's resource, but since it does not have one, the result is that the language name is empty.
Comment 1 Sebastian Zarnekow CLA 2011-01-27 17:14:40 EST
I think the ValidatorTester should put the language name into the diagnostic context when #valiator() is called. What do others think?
Comment 2 Sven Efftinge CLA 2011-01-27 23:15:51 EST
(In reply to comment #1)
> I think the ValidatorTester should put the language name into the diagnostic
> context when #valiator() is called. What do others think?

Yes, that seems to be ok in a test-context. 
We shouldn't require EObjects being contained in a resource in tests.
Comment 3 Sebastian Zarnekow CLA 2011-01-30 09:22:07 EST
Pushed the fix to master.
Comment 4 Karsten Thoms CLA 2017-09-19 17:39:20 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 17:50:36 EDT
Closing all bugs that were set to RESOLVED before Neon.0