If you declare a private field in a test class:
private Foo foo;
That gets used but is never assigned, IntelliJ IDEA (and presumably other IDEs) show a warning when I hover over the declaration, and it renders it gray
private field 'foo' is never assigned
But if I'm using Mockito and annotate the field like:
@Mock
private Foo foo;
The warning disappears and renders the field in purple to indicate that it is assigned. How does the IDE know what @Mock
implies? I've had a look through the Mockito source code and there doesn't seem to be anything on the annotation definition and my IDE doesn't have a Mockito plugin.
I'm writing a library similar to Mockito with an equivilant annotation and I'd love to know to get the IDE to remove the warning.
(I'm not a Java developer, so if I've said anything wrong please correct me)
EDIT I've tried this in Eclipse and it actually removes the warning with any annotation, which is what @nikpon was suggesting.