korosh afshar wrote: <snip the irrelevant bits of the sample/>
// ...private ExampleComponent component;
ContainerUtil.enableLogging( component, logger );
what is the use for ContainerUtil if I can just call MyComponent.enableLogging( logger ) ?
in the sample above, the test is testing the interface contract ExampleComponent implemented by ExampleComponentImpl. Thus, you need to cast the component to a LogEnabled. Which is precisely what ContainerUtil does for you (look up the source for the method; it's three lines).
protected ExampleComponent getComponent() { return new ExampleComponentImpl(); }
public void testComponentIsNotSoSillyAsToCallLoggerInEnableLogging() { loggerControl.replay(); component = getComponent(); if( component instanceof LogEnabled ) { LogEnabled le = (LogEnabled)component; le.enableLogging( logger ); }
I don't underestand whats going on here? getComponent will always give me an instance of my own component. Why the check for LogEnabled instance ?
consider an
AlternativeExampleComponentTestCase extends ExampleComponentTestCase
{
protected ExampleComponent getComponent()
{
return new AlternativeExampleComponent();
// AlternativeExampleComponent does not implement LogEnabled!!!
}
}the test should not fail in this case (the AlternativeExampleComponent does not log things from enableLogging(), since it doesn't have an enableLogging() method!).
BTW, you could replace the if() {} check and body with ContainerUtil.enableLogging() again, but I kept it here for clarity.
sorry, the descriptive method name didn't clear things up for me. component will never call its own lifecycle method.
the component isn't calling its own method. The testcase is taking on the role of the container and calling enableLogging. The test will fail if the component has something like
public void enableLogging( Logger logger )
{
logger.debug("Hey, I'm here!");
}note that all of this has little to do with the specifics of testing avalon components and more with testing practices in general. It's okay if things don't make sense; I'm just really delving into all of this myself :D
-- cheers,
- Leo Simons
----------------------------------------------------------------------- Weblog -- http://leosimons.com/ IoC Component Glue -- http://jicarilla.org/ Articles & Opinions -- http://articles.leosimons.com/ ----------------------------------------------------------------------- "We started off trying to set up a small anarchist community, but people wouldn't obey the rules." -- Alan Bennett
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
