From: Nat P. <nat...@b1...> - 2004-01-07 11:09:22
|
Calling expectAndReturn( method, result ) tells it to expect the method with NO parameters. Since the actual call happens with two parameters, the call will not match the expectation. The actual expectation should be: expectAndReturn( "validateLogin", C.args(C.eq(username), C.eq(password)), Boolean.TRUE ); If you want to ignore the exact values, you can do: expectAndReturn( "validateLogin", C.ANY_ARGS, Boolean.TRUE ); The behaviour is confusing, I admit. The next version will force tests to be explicit by always requiring the arguments parameter to expectXxx and stubXxx calls. I would also suggest that you use "self describing values" for your username and password parameters: addRequestParameter("username", "THE-USERNAME"); addRequestParameter("password", "THE-PASSWORD"); This will make error messages easier to read. Cheers, Nat. _______________________ Dr. Nathaniel Pryce B13media Ltd. http://www.b13media.com +44 (0)7712 526 661 ----- Original Message ----- From: "Bryce Fischer" <br...@be...> To: <moc...@li...> Sent: Wednesday, January 07, 2004 1:56 AM Subject: [MO-java-users] expectAndReturn troubles Noob here. Having a problem with getting dynamocks to work. I must be missing something important here. I'm getting the followin assertion failure: junit.framework.AssertionFailedError: mockSecurityManagerDelegate: validateLogin() was expected but not called at com.mockobjects.dynamic.Mock.verify(Mock.java:107) at com.berzerkersoft.bisweb.web.services.ValidateLoginTest.tearDown(ValidateLog inTest.java:42) at junit.framework.TestCase.runBare(TestCase.java:130) 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(RemoteTestRu nner.java:395) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner. java:279) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner .java:171) Here's my Test Code: public void testSuccessfulLogin() { mockSecurityManager.expectAndReturn("validateLogin", true); setRequestPathInfo("/validateLogin"); addRequestParameter("username", "bryce"); addRequestParameter("password", "bryce"); getRequest().setAttribute(SecurityManagerDelegate.class.getName(), securityManager); actionPerform(); verifyForward("success"); } and here's the call my class is making: ... ... if (manager.validateLogin(username, password)) { actionForward = mapping.findForward(FORWARD_loginSuccessful); ... ... I thought that calling expectAndReturn without any contstraint matchers would accept any call regardless.. Maybe I'm wrong. Hopefully someone can set me right. TIA. -- Bryce Fischer <br...@be...> ------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=ick _______________________________________________ Mockobjects-java-users mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users |