From: Tim M. <tim...@po...> - 2003-05-14 00:14:01
|
> -----Original Message----- > From: Vincent Massol [mailto:vm...@pi...] > > > - what is now replacing the setupDefaultResult() method? > > > Ex: mockRequest.setupDefaultResult(String.class, null); > > Any answer for that? Yes: use matchAndReturn("methodName", C.isA(String.class), null) > Does what? My questions is "simply what's the difference between > expect*() and match*()"... > > > There is a > > comment above these lines saying "// Set no expectations but answer a > > value > > for the specified method ". > > Yes, I have read this comment, hence my comment: " 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". > > My English may seem good but I don't think in the same way as you do > guys so it may take me longer to understand something... please bear > with me ;-) This has been answered in a previous email which defines expect and match. > I'll complement my question: Is expect*() considered deprecated now? But > then, why is it in the example... expect is Not deprecated, see the previous email > ok, I think I get it now. A comment would be nice to explain this... Am > I allowed to comment it? I will admit that without more context it can be tricky - why not change the 1000 and 2000 numbers to constants that would express this without a comment? Go on - try doing something to the Test that would make you happy without a comment? > I had looked at the code. Here it is: > > public class OrderedMock extends Mock { > > public OrderedMock(Class mockedClass) { > this(mockedClass, mockNameFromClass(mockedClass)); > } > > public OrderedMock(Class mockedClass, String name) { > super(new DefaultCallFactory(), new > CallSequence(),mockedClass, name); > } > > } > > It doesn't tell anything to me.... and then if you have the time to > follow the code, it calls the following constructor from the Mock class: > > public Mock(CallFactory callFactory, CallableAddable > callableAddable, Class mockedClass, String name) { > this.name = name; > [...] > > Still without any comment! > > I would need to browse and scan the full code to understand what it > does... Come on Vincent - you are a better programmer than that - what do you think the method "mockNameFromClass(mockedClass)" does????? Especially when it calls a method which when I hover over in my idea pops up a window that says: "com....Mock(Class mockedClass, String name)" This doesn't need a comment!!!!! That took all of 15 seconds. In fact less as when choosing the constructor my IDE shows me the method signature for both. HOWEVER - having written this, I could improve the variable name, to nonDefaultName, which I have just done. > > > As the name of the Parameter, "name" implies, it gives the mock a non > > default name. > > I mean I can see that. My question wasn't that. It was: > > > > - What's the point of using the second parameter (i.e. "response") > in: > > > new OrderedMock(HttpServletResponse.class, "response"); > > I can't figure out why we need to use "response" in this test sample! It > doesn't seem to be used anywhere. I mean if we want to show how to use > the second parameter we should demonstrate an example where we need this > second parameter and explain why... Actually - I can improve that too, is "response that servlet writes to" a better example of something you might want to do so that you would get a better error description? Unfortunately its on the todo list to have a little App that generates all error messages to the console so that we can see them and understand the errors better. > Thus, if I understand correctly, there will be 2 solution for sequence > calls: > - use a OrderedMock but then all calls are supposed to be in the same > order as the order in which we define the match*() (or expect*()) calls. > - use expectBefore() when you simply need to order 2 calls > > Is that correct? Exactly! Others have proposed that with this primitive we can do some other stuff but thats later. I think we finally got to the bottom of the stuff now - and I hope this has helped get a better description for your book. --- 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 |