
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
66 lines
1.6 KiB
Plaintext
66 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
|
|
|
@VisibleForTesting can be used to mark methods, fields and classes whose visibility restrictions have been relaxed more than necessary for the API to allow for easier unit testing.
|
|
|
|
|
|
Access to such methods, fields and classes only possible thanks to this relaxed visibility is fine for test code, but it should be avoided in production code. In production code these methods should be treated as if they are private.
|
|
|
|
|
|
Supported framework:
|
|
|
|
* Guava: ``++com.google.common.annotations.VisibleForTesting++``
|
|
|
|
* AssertJ: ``++org.assertj.core.util.VisibleForTesting++``
|
|
|
|
* Android: ``++androidx.annotation.VisibleForTesting++``
|
|
|
|
* Apache Flink: ``++org.apache.flink.annotation.VisibleForTesting++``
|
|
|
|
or any other annotation named ``++VisibleForTesting++``
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
/** src/main/java/MyObject.java */
|
|
|
|
@VisibleForTesting String foo;
|
|
|
|
/** src/main/java/Service.java */
|
|
|
|
new MyObject().foo; // Noncompliant, foo is accessed from production code
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
/** src/main/java/MyObject.java */
|
|
|
|
@VisibleForTesting String foo;
|
|
|
|
/** src/test/java/MyObjectTest.java */
|
|
|
|
new MyObject().foo; // Compliant, foo is accessed from test code
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this usage of {identifier name}, it is annotated with @VisibleForTesting and should not be accessed from production code.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
Visible for testing identifier name (methods or fields)
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|