easyforgood / mockito

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

define the behaviour when the method has too many arguments #389

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Sometimes, we want to mock a behavior of method that has a lot of arguements, 
in the setup of a test, we will have many lines that makes the test less 
readable like : 
when(mockedObject.foo(any(B.class), any(C.class), anyListOf(D.class), 
anyInt()).thenReturn(anOtherObject);

Is it possible to enhance this method to have something similar to 
when(mockedObject.foo(withAnyArguments()) or 
when(mockedObject).foo(withAnyArguments()) ?

Regards

Original issue reported on code.google.com by mohamed....@gmail.com on 25 Oct 2012 at 12:02

GoogleCodeExporter commented 8 years ago
Hi,

That would be cool, however this not doable atm, the Java compiler won't allow 
this. It's more of a Java platform related topic.

I'll invalidate the issue as it's not related to mockito, but to Java in 
general, though if anywhere in JDK 27 this feature is available maybe we will 
most ertainly use this feature :)

Cheers,
Brice

Original comment by brice.du...@gmail.com on 25 Oct 2012 at 12:09

GoogleCodeExporter commented 8 years ago
Hi Brice,

Thanks for your quick replay :)
Is there any link to understand why this is not possible by the Java compiler ?
Just curious...

Regards,

Original comment by mohamed....@gmail.com on 25 Oct 2012 at 12:22

GoogleCodeExporter commented 8 years ago
The compiler include in a method signature, the name, the args, and the return 
type; if the signature don't match an existing method then the compiler will 
issue an error. But worst, if an actual method exists in the code with just 1 
argument, then the calling code will use the wrong method

Object foo(B, C, List, int) <-- don't match --> Object foo(Object)

Original comment by brice.du...@gmail.com on 25 Oct 2012 at 9:56