3. Due to #2, here's my suggestion on how to go about coding it:-pass mock settings to InvocationContainerImpl so that it can create simpler / no-op version of RegisteredInvocations for stubs.Ok, straightforward.-add a new object that validates the verification. This will be used in MockHandlerImpl. It should also include the toString() validation we already have in VerificationDataImpl, thus making VerificationDataImpl simpler.
Could you please be more elaborate on that? Do you mean that MockCreationSettings would provide a factory for creation of VerificationData instances that would be creating instances of different classes depending on stubOnly()?
-Not required to implement this feature but might be useful if we want to keep the bar high :P. We could create a public interface for RegisteredInvocations and make them travel with the mock settings. This way users could pass custom implementations of RegisteredInvocations via settings. The stubOnly() feature would use exactly that. We also would have to expose the verification validation somehow.This would be also straightforward but there is a problem with remembering parameters. The invocations are remembered in invocationContainerImpl.setInvocationForPotentialStubbing() while their parameters are stored in stubbedInvocation.captureArgumentsFrom(...). Each parameter retains its own list of passed values (in CapturingMatcher.arguments) which is independent of invocationContainerImpl.registeredInvocations. Should a more complex logic for RegisteredInvocations be implemented, this should also reflect in logic of capturing parameters.Therefore I would introducing a method captureArguments(StubbedInvocationMatcher sim, Invocation i) in RegisteredInvocations that would delegate to sim.captureArgumentsFrom(i) for mocks and do nothing for stub-only. Do you agree?
Best,--Hynek--To view this discussion on the web visit https://groups.google.com/d/msg/mockito/-/jJOGdrDYRfAJ.
You received this message because you are subscribed to the Google Groups "mockito" group.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.
Hi Szczepan/Brice,
I have committed the changes into http://code.google.com/r/hmlnarik-mockito-stub-only/source/detail?r=8139e40170911aeac8c567cf421256c765713c05, can you please review it.
First, regarding your comment about capturing argument – not storing argument values is the reason why stubOnly is so much needed and has enormous performance impact. Arguments eat a lot of heap space which in turn requests much more work from garbage collector (see original thread for proof that this can easily get GC to eat 99% of time). Therefore capturing parameters must be disabled for stubs. As capturing parameters does not make much sense without capturing invocations, there is single common point where the capture/not capture should be controlled. This is currently in RegisteredInvocations. I would rather see this to be refactored a bit more so that invocations and the argument values are kept in one object to allow for e.g. selective remembering of invocations and their parameters, but this would require a bigger refactor that the one needed for the stubOnly() itself.
I have changed the MockCreationSettings so that it does not publish isStubOnly() but instead publishes relevant factories for creation of new VerificationData and RegisteredInvocations instances, as well as flag to capture stack trace (this is not new, all of these were in original code, hidden in conditions based on MockCreationSettings.isStubOnly(). Now isStubOnly() has been removed.).
The classes InvocationContainerImpl and MockHandlerImpl have been reverted to their original state, only few lines are changed to pass parameters so that collaborating classes can work with stubOnly() feature.
Hope we converge to the final version soon J
Cheers,
--Hynek
You received this message because you are subscribed to the Google Groups "mockito-dev" group.
To post to this group, send email to mocki...@googlegroups.com.
To unsubscribe from this group, send email to mockito-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito-dev?hl=en.
Hi Szczepan,
Thanks for the review. Please find my reactions to your individual comments here:
1. I have created a new clone http://code.google.com/r/hmlnarik-mockito-stubonly-feat/ where I have committed the minimal changeset for the stubOnly feature.
2. I moved the RemoveToString definition to the classes RegisteredInvocationsAll and RegisteredInvocationsStubOnly. I am not particularly keen on defining the same functionality twice but for the time being, it is easiest solution. Should this class be moved to outer level, please let me know the location.
3. We do need a mechanism to prevent capturing the argument values for stubs – as verification does not make sense for stubs, it makes no sense to verify arguments, hence capturing arguments should be blocked. In the current code, this is achieved via explicit checks to isStubOnly(), see rev. 30707da94f9c. In the previous branch, this was checked via shouldCaptureArgumentsFor().
4. CREATOR: this is to prevent if-else programming using standard Factory pattern. Instead of using
if (mockSettings.isStubOnly()) { return new RegisteredInvocationsStubOnly(); } else { return new RegisteredInvocationsAll(); }
simple
return mockSettings.registeredInvocationsCreator.newInstace();
would be used. I have used the if-then-else structure in the current implementation (see InvocationContainerImpl.createRegisteredInvocations()), yet I prefer the Factory pattern for code cleanliness and easy extensibility. The factory would allow for more configurability in MockSettings so if putting RegisteredInvocations into public API is planned, I would vote for implementing it via the factory as it was in the original code.
Please could you review the code? I have restricted the changes to the very minimal this time which means that I’m not completely happy with the code – still the functionality is there. Let’s discuss optimizations later, after finishing this piece. J
Cheers,
--Hynek