Hi,
I am using easymock now to get passed the avalon collaborator objects
required for my implementation.
I'll be using it to test out my own interface contracts later as I was
creating my own mock objects for that.
thanks allot for the reference.
just a couple of questions. please see inline comments below...
On Sun, 2004-01-25 at 15:45, Leo Simons wrote:
> 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 );
what is the use for ContainerUtil if I can just call
MyComponent.enableLogging( 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 );
> }
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 ?
sorry, the descriptive method name didn't clear things up for me.
component will never call its own lifecycle method.
> 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]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]