korosh afshar wrote:
I know probably I need to setup mock objects with my own   avalon Logger
passed into enableLogging lifecycle method(right?), but wondering how
are people dealing with this issue.

i.e. not having to setup a whole log of mock objects to test one
implementation method ?   there might not be any other option which is
fine in which case, I ask if there is a repository of Mock avalon/merlin
objects I can pull in to use.

Use something like easymock, http://www.easymock.org/. You just pass it the Logger interface and you get back an implementation. So there's no need for such a repository :D


Here's a complete EasyMock sample for ya:

public class ExampleComponentTest extends TestCase
{
    private ExampleComponent component;
    private MockControl loggerControl;
    private Logger logger;

    protected void setUp()
    {
        loggerControl = MockControl.createControl(Logger.class);
        logger = (Logger)control.getMock();
        component = getComponent();
        ContainerUtil.enableLogging( component, logger );
    }

    protected ExampleComponent getComponent()
    {
        return new ExampleComponentImpl();
    }

    public void testComponentIsNotSoSillyAsToCallLoggerInEnableLogging()
    {
      loggerControl.replay();
      component = getComponent();
      if( component instanceof LogEnabled )
      {
        LogEnabled le = (LogEnabled)component;
        le.enableLogging( logger );
      }
      loggerControl.verify();
    }

    public void testIsSomeConditionTrue()
    {
         assertTrue( component.isSomeConditionTrue() );
    }
    public void testIsSomeConditionTrueLogsProperMessage()
    {
         logger.log("problem making the call");
         loggerControl.rewind();

         component.setSomeCondition( false );
         assertFalse( component.isSomeConditionTrue() );

         loggerControl().verify();
    }
}

That should be more than enough to get you started! (disclaimer: haven't tested this!). You may feel like setting up an abstract base class or a utility class which sets up mock service managers, loggers, etc, and tests basic lifecycle compliance. I haven't bothered to date. If someone has, please send in your stuff :D

cheers!

- LSD



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to