ssacher-tgm / mockito

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

Configure mock settings in @Mock annotation #165

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Actually more features than issues, but mockito should allow to give
settings through the @Mock annotation. Of course it will needs some
mapping, because annotations requires JDK known type, like primitives,
String, Class, and Enums. Eventually other annotation would be used like @Spy

Another nice thing would be to allow the mockito runner to inject mock in
the class under test, identified for exemple by @Tested.

And if a test need specific mocking, then the class and mock configuration
will be overriden for this specific test. Eventually disabling it would be
an option.

Original issue reported on code.google.com by brice.du...@gmail.com on 26 Jan 2010 at 3:14

GoogleCodeExporter commented 8 years ago
I like the ideas, feel free to contribute ;)

Original comment by szcze...@gmail.com on 26 Jan 2010 at 8:13

GoogleCodeExporter commented 8 years ago
I will look into it!

Original comment by brice.du...@gmail.com on 27 Jan 2010 at 4:25

GoogleCodeExporter commented 8 years ago
Here is the first part of my proposal. With unit tests in AnnotationsTest.
For no I extended the @Mock annotation from MockSettings api, and I added the 
@Spy
annotation. However it is a rather trivial attempt, the code needs improvement.

And by the way I just saw a few hours ago that James Carr raced me on this one.

Original comment by brice.du...@gmail.com on 28 Jan 2010 at 5:46

Attachments:

GoogleCodeExporter commented 8 years ago
Cool, I'll have a look!

Original comment by szcze...@gmail.com on 1 Feb 2010 at 8:03

GoogleCodeExporter commented 8 years ago
By the way another appraoch would be to use other annotations like 
@ExtraInterfaces,
@Name, @Answer, however it complicates the MockitoAnnotation /
DefaultAnnotationEngine classes.

Original comment by brice.du...@gmail.com on 1 Feb 2010 at 11:38

GoogleCodeExporter commented 8 years ago
Here's a more complete patch with a basic mock / spies only injection in fields
annotated with @InjectMock. New test class included. Runners updated.
My code probably still needs a bit of improvement.

I also added @Captor annotation as proposed in issue 166.

The patch can be applied on r1827.

Original comment by brice.du...@gmail.com on 2 Feb 2010 at 12:06

Attachments:

GoogleCodeExporter commented 8 years ago
Hi,

Will have a look but I'm quite busy at the moment. Hopefully, Bartosz/Igor/Wes 
will
pick it up. I was more thinking about @Tested instead of @InjectMock but it's 
just
the matter of the name.

Original comment by szcze...@gmail.com on 2 Feb 2010 at 12:32

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 14 Feb 2010 at 12:32

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 14 Feb 2010 at 10:11

GoogleCodeExporter commented 8 years ago
Guys,

Sorry it took me some time to get into it. I am ready to spend some time 
merging the
patch but it would be very useful if there were separate patches per feature. I 
can
see 3 features here: @Captor, @Spy, @InjectMock

Can someone split the big patch into smaller batches? 

Original comment by szcze...@gmail.com on 17 Feb 2010 at 2:43

GoogleCodeExporter commented 8 years ago
Well I have no problem with that, every one has a real life ;)

Anyway on this matter I will propably spend some time maybe tomorrow on it with 
the 
latest repository version.

Original comment by brice.du...@gmail.com on 17 Feb 2010 at 3:29

GoogleCodeExporter commented 8 years ago
A side note: I've posted a patch for @Spy experiment at issue 104 page.

Original comment by alen_vre...@yahoo.com on 18 Feb 2010 at 2:02

GoogleCodeExporter commented 8 years ago
Hello, I splitted my last patch and adapted it to r1856. The patch files are 
*cumulative*. You should apply them in order.
 1. Extended @Mock support
 2. @Spy support
 3. @InjectMockSupport

Original comment by brice.du...@gmail.com on 19 Feb 2010 at 5:08

Attachments:

GoogleCodeExporter commented 8 years ago
excellent. I will try to get it checked in today.

Original comment by szcze...@gmail.com on 20 Feb 2010 at 1:34

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r1858.

Original comment by szcze...@gmail.com on 20 Feb 2010 at 7:51

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 28 Feb 2010 at 9:08

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 3 Sep 2012 at 10:00

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 3 Sep 2012 at 10:11