Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed ClassCastException thrown when using with PowerMock #37

Closed
wants to merge 2 commits into from

Conversation

jskierbi
Copy link

@jskierbi jskierbi commented May 15, 2016

There is ClassCastException when using this lib with PowerMock. I added class check before casting inside CreateInstance.kt, which prevents the exception. No PowerMock dependency introduced.

Problem description

Exception:

java.lang.ClassCastException: com.amazon.identity.auth.device.shared.APIListener$$EnhancerByMockitoWithCGLIB$$6966922d cannot be cast to org.mockito.internal.creation.bytebuddy.MockMethodInterceptor$MockAccess

    at com.nhaarman.mockito_kotlin.CreateInstanceKt.uncheckedMock(CreateInstance.kt:165)
    at com.nhaarman.mockito_kotlin.CreateInstanceKt.createInstance(CreateInstance.kt:55)
        ...

Code that caused the exception

@RunWith(PowerMockRunner::class)
class MockitoKotlinPowermockTest {
    @Test fun anyTest() {
        any<APIListener>() // Class cast exception inside
    }
}

@nhaarman
Copy link
Collaborator

nhaarman commented Jun 1, 2016

Thanks!
I'm not at all familiar with PowerMock though, and I'd like a regression test to make sure things won't break in the future.

Could you perhaps create a test that fails without this modification? I don't mind if you have to add additional dependencies, I'm willing to clean up after you :)

@jskierbi
Copy link
Author

jskierbi commented Jun 6, 2016

I'll write some tests, np. Just found out that this workaround misbehaves a bit - after mocking an object real method is called, which is obviously not good. I'll dig up a bit following days and try to push update to this PR both with tests and fix.

@nhaarman
Copy link
Collaborator

nhaarman commented Sep 9, 2016

What is the current status on this?

desilvai added a commit to desilvai/mockito-kotlin that referenced this pull request Oct 11, 2016
…s mock-maker-inline feature (incubating). I applied a similar fix and added tests highlighting the fix. I do not observe the same issue of the mock calling the original method as mentioned in @jskierbi's comments.
desilvai added a commit to desilvai/mockito-kotlin that referenced this pull request Oct 11, 2016
…eliminate interference with existing tests due to the test configuration.
@nhaarman
Copy link
Collaborator

The ClassCastException should be fixed by 85bb5e4. This may however cause #27 to reappear for PowerMock users, I'm not sure of that.

@nhaarman nhaarman closed this Oct 13, 2016
@nhaarman nhaarman mentioned this pull request Oct 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants