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

Fix wasNotshould throw exception when called on non mocked object #1174

Merged
merged 1 commit into from Feb 29, 2024

Conversation

Gosunet
Copy link
Contributor

@Gosunet Gosunet commented Oct 8, 2023

@Raibaz Here is to PR the fix #1155

I used the internalIsMockKMock with all parameters to true to check is the called object is a mock, please tell me if I miss something.
For the tests, I added some in a separate file, I wasn't sure where to put them.

Closes #1155

@Gosunet
Copy link
Contributor Author

Gosunet commented Oct 9, 2023

Also, I have two tests failing with this implementation:

  • ConstructorMockTest.givenEmptyCallListInStubbingStateWhenRecordingDoneIsCalledThenExceptionIsThrown()
  • ConstructorMockTest.clear, those test use wasNot on a non mocked object

@jcopenhop
Copy link

I think

can be rewritten as verify(exactly = 0) { recorder.factories.stubbingAwaitingAnswerState(any()) }

similarly I think

verify { anyConstructed<MockCls>() wasNot Called }

can be
verify(exactly = 0) { anyConstructed<MockCls>() }

@Raibaz
Copy link
Collaborator

Raibaz commented Feb 16, 2024

Re: the failing tests: I think you can rewrite them both as verify(exactly = 0) as @jcopenhop suggested.

@Gosunet Gosunet force-pushed the master branch 3 times, most recently from 2f3b2e1 to ff21211 Compare February 19, 2024 16:52
@Gosunet
Copy link
Contributor Author

Gosunet commented Feb 19, 2024

It's working for the StubbingStateTest.kt as mentioned by @jcopenhop.

But replacing this:

verify { anyConstructed<MockCls>() wasNot Called } 

By this:

 verify(exactly = 0) { anyConstructed<MockCls>() }

Give me this error:

io.mockk.MockKException: Missing calls inside verify { ... } block.

@Raibaz
Copy link
Collaborator

Raibaz commented Feb 28, 2024

That seems like a bug with anyConstructed.

I think we can just skip the test for now and temporarily accept that anyConstructed is not working with exactly at the moment.

Would you mind opening an issue about it, please?

@Gosunet
Copy link
Contributor Author

Gosunet commented Feb 29, 2024

Done #1224

I have ignore this test for now and link the issue to it.

@Raibaz Raibaz merged commit 1025c9b into mockk:master Feb 29, 2024
11 checks passed
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.

verify wasNot Called leads to false positive
3 participants