Issue
I have the following use case:
I want to Unit-test a private method (I really want to). Now, there are different approaches, but I want to choose the approach "make the method package private".
In Guava, there's an annotation called href="https://github.com/google/guava/blob/master/guava/src/com/google/common/annotations/VisibleForTesting.java" rel="nofollow noreferrer">@VisibleForTesting. What I want to do is: Whenever this method is called from another class (in the same package, of course), regardless of it's a subclass of this class or not, display a warning like "Hey dude, the method you want to call is marked with @VisibleForTesting, are you sure you want to call it?".
I played a bit with custom inspections, but with no luck so far. Does anyone have an idea?
Solution
There is no need for a custom inspection, the necessary inspection is built in. Go to
Preferences | Editor | Inspections
and enable the inspection
Java | General | Test-only class or method call in production code
. Now you will get a warning if you try to call members with the @VisibleForTesting
annotation from production code, but not from test code.
Answered By - Bas Leijdekkers
Answer Checked By - Willingham (JavaFixing Volunteer)