-
Notifications
You must be signed in to change notification settings - Fork 59
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
Comments
Interesting, the stack points to the lib I use to get more info about the
generics, I’ll take a look over the weekend!
That said, I’m not sure mocking a Map is something I’d recommend, it’s the
kind of thing that would be better to just use a regular instance, what
would it be the use case here?
On Wed, 6 May 2020 at 19:33, Diego ***@***.***> wrote:
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.
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)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#236>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB3BDEVL6PCU4CPZG7EMS3RQHQSHANCNFSM4M22RBWA>
.
--
Sent from my iPhone
|
Thanks. About my use case, I need a mock that returns "123" for every key. |
In that case you can do something like
val x = Map[String, String]().withDefault(“123”)
Don’t have access to my computer right now, but that should do the trick
On Wed, 6 May 2020 at 22:20, Diego ***@***.***> wrote:
Thanks. About my use case, I need a mock that returns "123" for every key.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#236 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB3BDBNHOTONDC53UO2OYDRQIEHDANCNFSM4M22RBWA>
.
--
Sent from my iPhone
|
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. |
Oh yes, I’ll definitely hunt that down
On Thu, 7 May 2020 at 07:41, Diego ***@***.***> wrote:
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.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#236 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB3BDDZLCACM7DH6TZPYRDRQKF4DANCNFSM4M22RBWA>
.
--
Sent from my iPhone
|
Wow, thanks for the quick fix! |
Confirmed that the bug is fixed for me with version 1.14.1. Thanks so much. |
No problem!
Enjoy!
On Mon, 11 May 2020 at 02:57, Diego ***@***.***> wrote:
Confirmed that the bug is fixed for me with version 1.14.1. Thanks so much.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#236 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB3BDH4KYG63MRI4FLCJ53RQ5LRRANCNFSM4M22RBWA>
.
--
Sent from my iPhone
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using IdiomaticMockito in my test.
This fails at run-time as shown below. A workaround is:
Note that the first example works fine with regular Mockito.
The failure:
The text was updated successfully, but these errors were encountered: