funbee / mockito

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

allow stubbing with callbacks #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Proposed interface:

stub(mock.getStuff())
    .toAnswer(new Answer() {
        Object answer(Invocation invocation) throws Throwable {
            Object[] params = invocation.getParameters();
            return "foo";
        }  
    });

stubVoid(mock)
    .toAnswer(myAnswer)
    .on().someMethod();

Original issue reported on code.google.com by szcze...@gmail.com on 25 Jun 2008 at 6:40

GoogleCodeExporter commented 9 years ago
Here is a preliminary implementation (based on trunk). A couple of comments 
about the implementation:

1) I piggy backed off of the DontThrow exception to implement the stubbing for 
void methods. It looks a little 
hackish, but it worked.
2) I modified the Answer interface. I think maybe the interface should be moved 
from internal.stubbing to a 
higher level package.

Original comment by john.ham...@gmail.com on 26 Jun 2008 at 5:59

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, I'll have look later today.

Original comment by szcze...@gmail.com on 26 Jun 2008 at 9:00

GoogleCodeExporter commented 9 years ago
Committed to trunk. Nice job! 

I'll sort out DontThrow later.

Original comment by szcze...@gmail.com on 26 Jun 2008 at 4:22

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 19 Apr 2009 at 7:40