diff options
author | Michael Hoisie <hoisie@google.com> | 2024-04-17 10:04:05 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-04-17 10:04:59 -0700 |
commit | f8bbdb1ea44c931938cfa2f747b0736b9f88ba7f (patch) | |
tree | d7da326c2daf16fb3e859864f2234ce853426a45 | |
parent | fef58ca6c1ca56fe2fd49d741fae8fd25c41f9b0 (diff) | |
download | robolectric-f8bbdb1ea44c931938cfa2f747b0736b9f88ba7f.tar.gz |
Clarify `@DoNotMock` error message in ClassInstrumentor
Robolectric's ClassInstrumentor adds a @DoNotMock annotation to Android classes
that originally contained the 'final' modifier.
The warning message always suggested to create or enhance a Shadow for the
Android class being instrumented. However, there are cases when it is
preferable to create a Builder, such as when the class is a pure Java data
class.
Update the `@DoNotMock` message to include this nuance.
Note that this @DoNotMock annotation is purely informative and requires special
infrastructure to enforce, so it's not on by default for Gradle/third-party
projects.
PiperOrigin-RevId: 625720769
-rw-r--r-- | sandbox/src/main/java/org/robolectric/internal/bytecode/ClassInstrumentor.java | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/sandbox/src/main/java/org/robolectric/internal/bytecode/ClassInstrumentor.java b/sandbox/src/main/java/org/robolectric/internal/bytecode/ClassInstrumentor.java index a9b532a26..9d3d51af9 100644 --- a/sandbox/src/main/java/org/robolectric/internal/bytecode/ClassInstrumentor.java +++ b/sandbox/src/main/java/org/robolectric/internal/bytecode/ClassInstrumentor.java @@ -177,8 +177,11 @@ public class ClassInstrumentor { .visitAnnotation("Lcom/google/errorprone/annotations/DoNotMock;", true) .visit( "value", - "This class is final. Consider using the real thing, or " - + "adding/enhancing a Robolectric shadow for it."); + "This class is final. Consider either:\n" + + "1. Using the real class.\n" + + "2. If it's a pure data class, adding a Robolectric Builder for it.\n" + + "3. If it cannot function on the JVM, adding or enhancing a Robolectric" + + " Shadow for it"); } mutableClass.classNode.access = mutableClass.classNode.access & ~Opcodes.ACC_FINAL; |