Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to test custom ResourceDescriptionStrategy?
How to test custom ResourceDescriptionStrategy? [message #866314] Mon, 30 April 2012 20:56 Go to next message
Scott Finnie is currently offline Scott FinnieFriend
Messages: 94
Registered: October 2011
Member
I have a custom ResourceDescriptionStrategy with overloaded createEObjectDescriptions() method and want to unit test it. However I'm not sure how to create the IAcceptor<IEObjectDescription>? There's no class pre-configured in the module descriptions and I can't seem to find one that's not protected. Here's the test code:

class TestResourceDescriptionStrategy {	

    @Inject
    IResourceDescriptions index;

    @Inject
    IQualifiedNameProvider qnp;

    @Test
    public void testCreateEObjectDescriptions(){
        c = MyDslFactory.eINSTANCE.createClass();
        rds = new MyDslResourceDescriptionStrategy();

        //problem: what class to construct acceptor from?
	rds.createEObjectDescriptions(c, acceptor);

	QualifiedName qn=qnp.getFullyQualifiedName(c);
	Iterable<IEObjectDescription> descriptions;
	descriptions=index.getExportedObjects(c.eClass(), qn, false);
        //...check there's only one entry in collection
    }
}


Suggestions appreciated for IAcceptor instance (or any comments on test approach...).

Thanks.

Re: How to test custom ResourceDescriptionStrategy? [message #866319 is a reply to message #866314] Mon, 30 April 2012 20:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

what about doing what the real code does

final List<IEObjectDescription> exportedEObjects = newArrayList();
		IAcceptor<IEObjectDescription> acceptor = new IAcceptor<IEObjectDescription>() {
			public void accept(IEObjectDescription eObjectDescription) {
				exportedEObjects.add(eObjectDescription);
			}
		};


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to test custom ResourceDescriptionStrategy? [message #866350 is a reply to message #866319] Mon, 30 April 2012 21:18 Go to previous messageGo to next message
Scott Finnie is currently offline Scott FinnieFriend
Messages: 94
Registered: October 2011
Member
Thanks Christian.
Re: How to test custom ResourceDescriptionStrategy? [message #870036 is a reply to message #866314] Sat, 05 May 2012 22:25 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
Oh, that's an easy one. The IAcceptor<T> interface is meant as a marker
interface, such that you no longer have to provide plain collections
that collect results as a parameter. Instead, you specify an IAcceptor,
thus marking the argument as "collecting the results".

You can just instantiate an anonymous instance filling a final
collection variable, such as

final Set<IEObjectDescription> descriptions = newHashSet();
IAcceptor<IEObjectDescription> acceptor = new
IAcceptor<IEObjectDescription>() {
public void accept(IEObjectDescription acceptMe) {
descriptions.add(acceptMe);
}
);
rds.createEObjectDescriptions(c, acceptor);
// do something with 'descriptions'


Am 30.04.12 22:56, schrieb Scott Finnie:
> I have a custom ResourceDescriptionStrategy with overloaded
> createEObjectDescriptions() method and want to unit test it. However I'm
> not sure how to create the IAcceptor<IEObjectDescription>? There's no
> class pre-configured in the module descriptions and I can't seem to find
> one that's not protected. Here's the test code:
>
>
> class TestResourceDescriptionStrategy {
>
> @Inject
> IResourceDescriptions index;
>
> @Inject
> IQualifiedNameProvider qnp;
>
> @Test
> public void testCreateEObjectDescriptions(){
> c = MyDslFactory.eINSTANCE.createClass();
> rds = new MyDslResourceDescriptionStrategy();
>
> //problem: what class to construct acceptor from?
> rds.createEObjectDescriptions(c, acceptor);
>
> QualifiedName qn=qnp.getFullyQualifiedName(c);
> Iterable<IEObjectDescription> descriptions;
> descriptions=index.getExportedObjects(c.eClass(), qn, false);
> //...check there's only one entry in collection
> }
> }
>
>
> Suggestions appreciated for IAcceptor instance (or any comments on test
> approach...).
>
> Thanks.
>
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Split Grammar into two files
Next Topic:Restricting Xbase in my own grammar
Goto Forum:
  


Current Time: Thu Apr 25 16:15:04 GMT 2024

Powered by FUDForum. Page generated in 0.02836 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top