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

Mocking map invocation via chained call stopped working #565

Closed
cbxp opened this issue Feb 5, 2021 · 8 comments
Closed

Mocking map invocation via chained call stopped working #565

cbxp opened this issue Feb 5, 2021 · 8 comments

Comments

@cbxp
Copy link

cbxp commented Feb 5, 2021

Mockk version: 1.10.5
Kotlin version: 1.4.21
OS: MacOS Big Sur 11.2
JVM: adopt-openjdk-11 version 11.0.10

Java class under test:

import java.util.Map;

public interface Bar {
  Map<String, Integer> getAttributes();
}

Test:

val bar = mockk<Bar>(relaxed = true)
every { bar.attributes["foo"] } returns null
bar.attributes["foo"]

Expected (as in version 1.9.3)
bar.attributes should return a Map

Actual
NullPointerException because bar.attributes is null

@Raibaz
Copy link
Collaborator

Raibaz commented Feb 19, 2021

Does this still happen if you declare your mock as a relaxed mock, i.e. val bar = mockk<Bar>(relaxed = true)?

@cbxp
Copy link
Author

cbxp commented Mar 12, 2021

@Raibaz It still fails. Updated the example in original message.

@omesquita
Copy link

omesquita commented May 18, 2021

I have a same problem when i use val bar = mockk<Bar>(relaxed = true) and every { bar.list.isEmpty() } returns false.

Do someone find a solution?

@Raibaz
Copy link
Collaborator

Raibaz commented May 24, 2021

This looks like a bug in the AnyValueGenerator; it should be returning an empty map for bar.attributes if the mock is relaxed, yet it seems like it's returning null.

@omesquita
Copy link

Thank you @Raibaz. Can you me say how i fix it?

@pedrofsn
Copy link

Hello guys. Any updates about this issue?

@stale
Copy link

stale bot commented Aug 18, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just ask to put an important label.

@stale stale bot added the stale label Aug 18, 2021
@omesquita
Copy link

Hi! Anyone have a solution for this issue?

@stale stale bot removed the stale label Aug 23, 2021
Raibaz added a commit that referenced this issue Aug 31, 2021
…-stubbing

Fix stubbing by chained calls on collections (#565)
@Raibaz Raibaz closed this as completed Aug 31, 2021
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

4 participants