From: Tim M. <tim...@po...> - 2003-05-12 23:47:13
|
Vincent - I think you seem to be panicing a bit. If you slow down a second and look at the example you will find its not as bad as you think - there are some useful comments in the actual test, and many of the parameters of the methods you are calling have pretty explicit names. If you recall I did send you a long message documenting a lot of this stuff for you already, however as I know you have a tight deadline I will repeat and clarify some of this stuff so you can go faster. > - what is now replacing the setupDefaultResult() method? > Ex: mockRequest.setupDefaultResult(String.class, null); > > - what's the difference between expect*() and match*()? It seems to me > that the verify() will trigger a check to verify that the expect*() > calls did actually happen whereas this would not be checked for the > match*() ones? Is that correct? As Steve correctly pointed out - matchAndReturn does this. There is a comment above these lines saying "// Set no expectations but answer a value for the specified method ". Using ANY_ARGS as parameter constraint will give you the same behavior as you used to have, however using constraints can give you hashtable like behavior for example. We did consider calling this method "stubAndReturn" however Steve felt it didn't indicate the matching of the constraints very well. > - I've started looking at the > src\examples\com\mockobjects\examples\dynamic\ SimpleServletTest.java > example. It doesn't seem to be finished though and is missing some > comments. But that would be the best help for those starting with the > new dyna Mock API. Some questions: The example is an example of test first programming - e.g. the code doesn't actually have to work to have all the tests passing. Some of the real implementations are left to the reader to implement them. > - I don't understand what's the purpose of the Timer class. Also, it > wasn't in the testDoGetOldStyle() method. I think the Timer is muddying > the example and should be removed altogether (unless there's something I > don't understand!). The timer demonstrates an interface of an object that we expect to return multiple results from a single method (the idea being, if we were going to indicate the elapsed time of an operation this is ofent something). I would say the code in the Servlet gives this impression: writer.print("timer before:" + timer.getTime()); mailSender.sendMail(subject, recipients, body); writer.print("timer after:" + timer.getTime()); > - What's the point of using the second parameter (i.e. "response") in: > new OrderedMock(HttpServletResponse.class, "response"); As the name of the Parameter, "name" implies, it gives the mock a non default name. A simple examination of the code makes this pretty obvious. If you have two objects of the same time (e.g. a Customer) - it is useful if the error message is the same for both of them if one is causing the failure. As I am sure you are going to ask - MailSender is an example of an object that takes an Object[] as a parameter. In Java its important to get this one right so that the error messages are clear. > - At some point, it says: " // Proposed enhancement to allow > individual ordering". Is it done? As the http response is an ordered > mock, isn't the implemented solution already doing the same as what is > in the comments? No - the comment is right, its not implemented yet. MockHttpResponse shouldn't actually be totally ordered as not all messages have to be in a specific order, it really should just be a Mock with this type of code. > - Is the ConstraintMatcher[] supposed to be used internally or used by > the user? It is not used in the sample servlet test. In other words, how > would you translate the following (old style): > > mockRequest.expectVoid("setAttribute", new Constraint[] { > C.eq("result"), C.IS_ANYTHING }); You can instantiate a FullConstraintMatcher if you want e.g.: mockRequest.expect("setAttribute", new FullConstraintMatcher(C.eq("result"), C.IS_ANYTHING)); but simpler still is: mockRequest.expect("setAttribute", C.args(C.eq("result"), C.IS_ANYTHING); > Thanks No problem. Tim --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.476 / Virus Database: 273 - Release Date: 24/04/2003 |