google / google/error-prone

Qualify `CannotMockFinalClass`

Open
#922 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

As of Mockito 2.1 one [can mock `final` classes](https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2#mockito-210). This is an opt-in feature, enabled by storing the value `mock-maker-inline` in the `mockito-extensions/org.mockito.plugins.MockMaker` classpath resource.

Suggestions:
1. Update the `CannotMockFinalClass` documentation and error message, to inform users about this new feature. (And if used, they'll have to disable this check.)
2. (Preferred.) Have the checker look for the presence of the aforementioned classpath resource and warn about mocked `final` classes only in the "inline mock maker" is not enabled.

NB: I started working on a PR for option (2), but hit an issue: the only classloader using which I can seem to find the resource is the one returned by `JavacProcessingEnvironment.instance(state.context).getProcessorClassLoader()`. Using that classloader I have a passing Error Prone unit test, and it also seems to work in a simple Maven project in which Error Prone is enabled. But this classloader no longer exposes the resource once the `maven-compiler-plugin` is configured with custom ``. Given the method's name this doesn't surprise me at all, but the question is then: how _does_ one properly look up resources on the compile classpath?

(If the above blurb of text is unclear, I can open a PR to showcase the current approach.)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.