Repository navigation
Fixes #2905 : ThreadLocal classes can be mocked. - #2908
TimvdLippe merged 3 commits into
Conversation
|
Hello, This PR is a possible fix for the issue reported in #2905 |
|
While this will solve the issue for thread local classes, it will introduce it for map objects. Let me have a look if this can be solved differently. |
Can we make sure we have a regression test for that as well? I would have merged this PR since all tests are green. Would be good to codify this requirement to ensure we don't regress. |
|
@TimvdLippe and @raphw Got it. I can add additional tests, just give me a list of use cases you want me to cover. Best |
|
Turns out the recursion check is one level deeper. For the case I meant, the self-call-check is pointless anyways. Turning this the way as suggested should not be an issue. |
|
Thanks a lot for the quick processing. |
Fixes #2905
Changes
MockMethodAdviceway of checking if an object was a mock didn't work forThreadLocalclasses. The only change here is in methodMockMethodAdvice#isMocked(Object)where the two conditions are flipped in order to avoid hitting theget()method fromThreadLocalused to check if the object was calling itself.Note: this was working in Mockito 4.9.0, didn't check what happens in 5.0.0 and 5.1.0.
Checklist
including project members to get a better picture of the change
commit is meaningful and help the people that will explore a change in 2 years
Fixes #<issue number>in the description if relevantFixes #<issue number>if relevant