From: Dan C. <da...@dy...> - 2003-06-24 18:02:26
|
Why not run a few tests. One in which the both Booleans are false, one in which both Booleans are true and one in which the first is false and the second is true? -----Original Message----- From: moc...@li... [mailto:moc...@li...] On Behalf Of Francois Beausoleil Sent: Monday, June 23, 2003 10:14 PM To: moc...@li... Subject: [MO-java-dev] How to test double conditional implementation, which could change... Hi ! I have a test which tests for the presence of two keys in a Map. If one or both keys are missing, do A, else B. So, here's what the code looks like at the moment: if (false =3D=3D getConstantsMap().containsKey(constantName + = CLASS_SUFFIX) || false =3D=3D getConstantsMap().containsKey(constantName + VALUE_SUFFIX)) { No, Java is able to short-circuit the evaluation of a condition if the truth of a condition can be determined early. Right now, I am setting up my dynamock so: final Mock mockMap =3D new Mock(Map.class); mockMap.expectAndReturn("containsKey", C.eq(constantName + ".class"), false); mockMap.expectAndReturn("containsKey", C.eq(constantName + ".value"), true); mockMap.expect("put", C.args( C.eq(constantName + ".class"), C.eq(Integer.TYPE) ) ); My test fails because Java short circuits the evaluation of the second condition. I changed to using a matchAndReturn for the second containsKey, but this is an implementation detail. What would you guys recommend ? Should I use matchAndReturn for both containsKey() setups, or should I change the implementation to use temp variables and then test these ? Thanks, Fran=E7ois -- Francois Beausoleil Developer of Java Gui Builder http://jgb.sourceforge.net/ ------------------------------------------------------- This SF.Net email is sponsored by: INetU Attention Web Developers & Consultants: Become An INetU Hosting Partner. Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |