thanks much for the detailed explanation.
I was trying to only test out interface contract of my own service and
not worry about testing avalon interface contracts. That I would have
just left to the AbstractMerlinTestCase.
I think that is what you are taking into account if I am not mistaking.
A more complete test of ALL of interface contracts.
Korosh.
On Mon, 2004-01-26 at 17:06, Leo Simons wrote:
> 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
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]