From: Francois B. <fb...@us...> - 2003-06-24 05:14:09
|
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/ |