easyforgood / mockito

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

Deep stubs javadoc comment warning is simplistic. #424

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
In
http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html#RETURNS_DEEP_STUB
S

the javadoc says "WARNING: This feature should rarely be required for regular 
clean code! Leave it for legacy code. Mocking a mock to return a mock, to 
return a mock, (...), to return something meaningful hints at violation of Law 
of Demeter or mocking a value object (a well known anti-pattern)."

However, as has been pointed put in blogs, this feature is very useful and 
valid for cleanly mocking fluent interfaces (which Mockito itself is). It has 
been argued that fluent interfaces don't violate the Law of Demeter, as they 
don't cross architectural layers.

This warning is a general note, and perhaps doesn't belong here.
Perhaps notes like this should be brought together in a developers guide, 
rather than be peppered throughout the javadoc.

Original issue reported on code.google.com by mpharri...@gmail.com on 1 Mar 2013 at 8:39

GoogleCodeExporter commented 8 years ago
I agree fluent API could don't violate Demeter Law. Still many people uses 
DEEP_STUBS in such case, which is wrong, I prefer to have the javadoc saying 
it's wrong instead of having to go to some guide, blog or wiki.

However, it is possible to add that fluent API could not fall under this 
category. For reference I'd like to see the paper that says that fluent 
interfaces don't violate the Law of Demeter.

Thx for reporting the javadoc issue.
Brice

Original comment by brice.du...@gmail.com on 14 Mar 2013 at 7:41

GoogleCodeExporter commented 8 years ago
Well, I just searched google for fluent api law of demeter and found a few 
useful pages, like:
http://haacked.com/archive/2009/07/13/law-of-demeter-dot-counting.aspx

and 

http://mvdms.com/wp-content/uploads/2013/01/Martijn-van-der-Maas_Fluent-or-Law-o
f-Demeter.pdf

Fluent APIs are useful for a DSL-like interface. They are a different design 
approach, with different priorities, and coupling should still be kept to a 
minimum to achieve it. Martin Fowler prefers to call it the "Occasionally 
Useful Law of Demeter". It is a rule of thumb, not a hard and fast rule.

Original comment by mpharri...@gmail.com on 15 Mar 2013 at 9:45

GoogleCodeExporter commented 8 years ago
Cool thanks for links, I actually remember this saying of Martin Fowler. I 
personally like fluent APIs design, still I've never actually read solid papers 
on them. Never actually took the time to search though.

I think it's fair to mention a fluent api is a reasonable usage for the 
RETURNS_DEEP_STUBS usage, but still keeps the warning regarding the Law of 
Demeter.

Cheers,
Brice

Original comment by brice.du...@gmail.com on 15 Mar 2013 at 10:44

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 29 Apr 2013 at 4:04