From: Bryce F. <br...@be...> - 2004-01-07 01:56:12
|
Noob here.=20 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: validate= Login() was expected but not called at com.mockobjects.dynamic.Mock.verify(Mock.java:107) at com.berzerkersoft.bisweb.web.services.ValidateLoginTest.tearDown(Valida= teLoginTest.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(RemoteT= estRunner.java:395) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRu= nner.java:279) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestR= unner.java:171) Here's my Test Code: public void testSuccessfulLogin() { mockSecurityManager.expectAndReturn("validateLogin", true); =09 setRequestPathInfo("/validateLogin"); addRequestParameter("username", "bryce"); addRequestParameter("password", "bryce"); getRequest().setAttribute(SecurityManagerDelegate.class.getName(), securi= tyManager); =09 actionPerform(); =09 verifyForward("success"); } and here's the call my class is making: =2E.. =2E.. if (manager.validateLogin(username, password)) { actionForward =3D mapping.findForward(FORWARD_loginSuccessful); =2E.. =2E.. 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. --=20 Bryce Fischer <br...@be...> |
From: Steve F. <st...@m3...> - 2004-01-07 09:09:20
|
You need to tell the mock about the two input parameters, otherwise it can't tell which method you're referring to. There are some helper methods in the C class. S. Bryce Fischer wrote: > Here's my Test Code: > public void testSuccessfulLogin() { > mockSecurityManager.expectAndReturn("validateLogin", true); > and here's the call my class is making: > if (manager.validateLogin(username, password)) { |
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 |
From: Bryce F. <br...@be...> - 2004-01-07 19:35:50
|
Thanks to everyone who responded. Your responses helped me greatly > Steve Freeman said: > You need to tell the mock about the two input parameters, otherwise it > can't tell which method you're referring to. There are some helper > methods in the C class. That's where I was confused. I thought that specifying nothing in the parameters meant you didn't care what was passed. Now it makes more sense. Thanks. > Nat said: > If you want to ignore the exact values, you can do: > > expectAndReturn( "validateLogin", C.ANY_ARGS, Boolean.TRUE ); Which just confirmed it, and gave me what I thought I was originally doing. > Nat also said: > I would also suggest that you use "self describing values" for your username > and password parameters: > > addRequestParameter("username", "THE-USERNAME"); > addRequestParameter("password", "THE-PASSWORD"); Thanks for the tip. I will definitely consider doing that. Thanks again for all your help. -- Bryce Fischer <br...@be...> |