Skip to content

Unable to mock Map[String, String] #236

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

Closed
diegoboston opened this issue May 6, 2020 · 8 comments
Closed

Unable to mock Map[String, String] #236

diegoboston opened this issue May 6, 2020 · 8 comments

Comments

@diegoboston
Copy link

diegoboston commented May 6, 2020

I'm using IdiomaticMockito in my test.

val mocked = mock[Map[String, String]]
mocked.apply(*) shouldReturn "123"
mocked("key") should equal("123")
mocked.apply(*) wasCalled once

This fails at run-time as shown below. A workaround is:

    abstract class TestMap extends Map[String, String]
    val mocked = mock[TestMap]

Note that the first example works fine with regular Mockito.

The failure:

                There was 1 failure:
                 1) initializationError(<MYTESTPATH>)
                 java.lang.StackOverflowError
                 	at ru.vyarus.java.generics.resolver.util.GenericsResolutionUtils.resolveGenerics(GenericsResolutionUtils.java:92)
                 	at ru.vyarus.java.generics.resolver.util.walk.TypesWalker.visitGenerics(TypesWalker.java:120)
                   ....
@ultrasecreth
Copy link
Member

ultrasecreth commented May 6, 2020 via email

@diegoboston
Copy link
Author

Thanks. About my use case, I need a mock that returns "123" for every key.

@ultrasecreth
Copy link
Member

ultrasecreth commented May 7, 2020 via email

@diegoboston
Copy link
Author

Yes, thanks so much, that would also work. Still, I'm curious to see if you can find the underlying bug. Mockito (Java) seems to be fine with this case.

@ultrasecreth
Copy link
Member

ultrasecreth commented May 7, 2020 via email

@diegoboston
Copy link
Author

Wow, thanks for the quick fix!

@diegoboston
Copy link
Author

Confirmed that the bug is fixed for me with version 1.14.1. Thanks so much.

@ultrasecreth
Copy link
Member

ultrasecreth commented May 11, 2020 via email

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

No branches or pull requests

2 participants