Matteo Pelucco wrote:

> I need to test one method of my class. How can I build a JUnit test case 
> using Components and IoC?
> This is the test method, I need something to replace the <???>: 

You'll want to create mocks for the constructor arguments of 
MyProjectTemplatingFunction and use those to to instantiate 
MyProjectTemplatingFunction (the class you want to unit test). Using Mockito it 
would look something like this:

[code]
TemplatingFunctions cmsfn = mock(TemplatingFunctions.class);
STKTemplatingFunctions stkfn = mock(STKTemplatingFunctions.class);
DamTemplatingFunctions damfn = mock(DamTemplatingFunctions.class);
NectarTemplatingFunctions nectarfn = mock(NectarTemplatingFunctions.class);

// Stub any method calls you need on these mocks, e.g.: 
// when(cmsfn.link("website", 
"550e8400-e29b-41d4-a716-446655440000")).thenReturn("http://example.org/";);

MyProjectTemplatingFunction fn = new MyProjectTemplatingFunction(cmsfn, stkfn, 
damfn, nectarfn);

// Run your test on fn
[/code]

Nils.

----------------------------------------------------------------
For list details, see http://www.magnolia-cms.com/community/mailing-lists.html
Alternatively, use our forums: http://forum.magnolia-cms.com/
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to