You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Howard Lewis Ship <hl...@gmail.com> on 2005/06/16 16:48:44 UTC

Re: Unit tests

You need to create a control for the mock, and inform the control what
to return from the mock.

I.e.

Object foobar = new FooBar();

MockControl cyclec = newControl(IRequestCycle.class);
IRequestCycle cycle = (IRequestCycle)cyclec.getMock();

cycle.getAttribute("foo.bar");
cyclec.setReturnValue(foobar);

...

// Setup all controls created with newControl() or newMock() to replay
// their scripts.

replayControls();

// Run tests that use the mock cycle trained above


// Ensure that all scripts for all controls completed.
verifyControls();

On 6/16/05, Mind Bridge <mi...@yahoo.com> wrote:
> Hi Howard,
> 
> As mentioned before, I am writing unit tests for If, Else, etc.
> I am encountering a strange problem: I am getting the following
> exception when I invoke a non-void method (specifically
> cycle.getAttribute("...")). I was wondering, does EasyMock allow that?
> 
> Sorry to bother you, but I cannot find anything on google and I guess
> you have experience with this.
> 
> Best regards,
> -mb
> 
> 
> java.lang.IllegalStateException: missing behavior definition for the
> preceeding method call getAttribute("Form")
>     at
> org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:44)
>     at $Proxy1.setAttribute(Unknown Source)
>     at
> org.apache.tapestry.components.TestIfElse.testRenderSimple(TestIfElse.java:62)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:585)
>     at junit.framework.TestCase.runTest(TestCase.java:154)
>     at junit.framework.TestCase.runBare(TestCase.java:127)
>     at junit.framework.TestResult$1.protect(TestResult.java:106)
>     at junit.framework.TestResult.runProtected(TestResult.java:124)
>     at junit.framework.TestResult.run(TestResult.java:109)
>     at junit.framework.TestCase.run(TestCase.java:118)
>     at junit.framework.TestSuite.runTest(TestSuite.java:208)
>     at junit.framework.TestSuite.run(TestSuite.java:203)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
>     at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
> 
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org