Mockito mock calling real method implementation when attempting to stub package protected method

The method you are mocking is not accessible to the Mockito code.

Because your test code and your code under test are in the same package, the compiler lets you set up your mock that way, but at runtime, the Mockito library has to try to access moveAttachment, but it’s not working in your case. This appears to be a bug or known limitation in Mockito as it should support that case, (and in fact, does support it in most cases).

The easiest thing to do would be to make moveAttachment a public method. If that is not an option, then first question whether you want to even mock it. What happens if the real method gets called?

The last option is to use PowerMock to treat the moveAttachment method as a private method and mock it that way.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)