Closed GoogleCodeExporter closed 9 years ago
Sorry, forgot to mention that I'm using 1.8-rc2.
Original comment by j...@kikini.com
on 25 Jun 2009 at 5:54
Very well spotted. Thanks a lot for reporting!
Ok, I see 2 options here. Let me know what do you think or generate some more
options:
1. captor will have methods like captureInt(), captureLong(), captureBoolean(),
etc.
2. captor will be created without type info. Type info will be added when
calling
capture:
ArgumentCaptor captor = new ArgumentCaptor();
verify(mock).foo(captor.capture(Integer.class));
Thoughts?
Original comment by szcze...@gmail.com
on 26 Jun 2009 at 9:10
Hmmm, that's a tough one. I think option 1 might be the better choice, though.
With option 1, I unfortunately have to repeat myself on the verify line:
ArgumentCaptor<Boolean> captor = new ArgumentCaptor<Boolean>();
verify(mock).someMethod(captor.captureBoolean());
// assertTrue(captor.getValue());
With option 2, I will still have to repeat myself (with object casts), but I
also
lose the type safety that generics would give me:
ArgumentCaptor captor = new ArgumentCaptor();
verify(mock).someMethod(captor.capture(Boolean.class));
// assertTrue((Boolean)captor.getValue());
Another option to consider:
ArgumentCaptor<Integer> captor = new ArgumentCaptor<Integer>(Integer.class);
That's a lot of "Integer" repetition, but it is confined to one line. :) You
could
potentially provide a factory to help:
ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class);
Original comment by j...@kikini.com
on 27 Jun 2009 at 6:56
Good ideas. I'm thinking in option 2 you still can maintain type safety:
<T> T capture(Class<T> clazz);
> ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class);
Good idea. The only little problem is that java devs are more used to natural
way of
creating objects: constructors.
Original comment by szcze...@gmail.com
on 27 Jun 2009 at 10:19
Original comment by szcze...@gmail.com
on 9 Jul 2009 at 12:53
This issue was closed by r1566.
Original comment by szcze...@gmail.com
on 19 Jul 2009 at 9:03
Fixed in trunk. This is how you construct ArgumentCaptors since now:
ArgumentCaptor<Integer> captor = ArgumentCaptor.forClass(Integer.class);
Original comment by szcze...@gmail.com
on 19 Jul 2009 at 9:43
Original issue reported on code.google.com by
j...@kikini.com
on 25 Jun 2009 at 5:46