mlinhard / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Add once() as an alias to times(1) #311

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This method should be added for multiples reasons:
* This is homogeneous with atLeastOnce()
* This is used thorough the examples showing a need for such semantic
* This will ease the diff commit readers as they no more need to know the 
default mode
* This is pretty safe to be added to the codebase

The patch as been made against changeset 1798:2642fe9af1c3

Original issue reported on code.google.com by framiere on 18 Jan 2012 at 8:56

Attachments:

GoogleCodeExporter commented 9 years ago
patch

Original comment by framiere on 18 Jan 2012 at 9:16

Attachments:

GoogleCodeExporter commented 9 years ago
In the past, I have spoken out against this change, on the mailing list 
(http://groups.google.com/group/mockito/browse_thread/thread/b3103a06526994b/c68
837e1ff7dd238?lnk=gst&q=twice#c68837e1ff7dd238).  I'll do so again, as I am 
strongly opposed to having once() in the API.

verify( xxx, times( 1 )) is exactly equivalent to verify( xxx ).  So you NEVER, 
EVER, need to write times( 1 ).  Writing times( 1 ) is an anti-pattern, because 
it clutters your test needlessly.  In fact, the team leader on my last project 
used to remove times( 1 ) from any tests where he found it.  So why would the 
mockito team add an alias for something that's never actually needed?

One of the great strengths of mockito has always been the leanness and 
simplicity of its API.  People can get up and running with mockito quickly, 
because there's not terribly much that you need to master, in order to be able 
to write effective tests with mocks, and to be able to understand tests written 
by others.  My employer wants me to spend my time writing Java code, not 
learning a mocking framework.

Lately, a few extra goodies have been added to mockito, which (in my opinion), 
have made the API more cluttered, for little gain.  I honestly think that the 
mockito team should be looking to rein in this trend.  Adding an alias for 
something which we never need to write?  Please, mockito team, DON'T DO THIS!!

Original comment by dmwallace.nz on 19 Jan 2012 at 2:39

GoogleCodeExporter commented 9 years ago
It seems David is pretty passionate against :) I don't have a strong view here 
(as I'm a fan of aliases) but so far the discussion on the mailing list led us 
to avoid adding once().

Thanks a lot for the patch but we'd like to hold off with adding this feature :/

Original comment by szcze...@gmail.com on 2 Feb 2012 at 9:12

GoogleCodeExporter commented 9 years ago

Original comment by brice.du...@gmail.com on 24 Feb 2012 at 3:50

GoogleCodeExporter commented 9 years ago

Original comment by brice.du...@gmail.com on 24 Feb 2012 at 3:54