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

@MockitoSpyBean does not see the first interaction #33986

Closed
McKratt opened this issue Nov 28, 2024 · 3 comments
Closed

@MockitoSpyBean does not see the first interaction #33986

McKratt opened this issue Nov 28, 2024 · 3 comments
Assignees
Labels
in: test Issues in the test module status: duplicate A duplicate of another issue type: regression A bug that is also a regression

Comments

@McKratt
Copy link

McKratt commented Nov 28, 2024

Hello,

I just migrate a working code from 3.3.2 to 3.4.0 and when I change my tests to use the new @MockitoSpyBean I got exceptions with Mockito telling me that there is not the expected interaction with my mock. I cannot produce code easily, but here the exception :

Wanted but not invoked:
clientInitiator.start();
-> at quickfix.ThreadedSocketInitiator.start(ThreadedSocketInitiator.java:112)

However, there were exactly 3 interactions with this mock:
clientInitiator.startInitiators();
-> at quickfix.ThreadedSocketInitiator.start(ThreadedSocketInitiator.java:114)

clientInitiator.startSessionTimer();
-> at quickfix.mina.initiator.AbstractSocketInitiator.startInitiators(AbstractSocketInitiator.java:317)

clientInitiator.isLoggedOn();
-> at com.pictet.trading.gateway.FixToHttpIT.should_send_message_in_http(FixToHttpIT.java:133)

Here an extract of the code the producing the exception :

@MockitoSpyBean(name = "clientInitiator")
private Initiator initiator;
...
 then(initiator).should().start();

The actual class on Github : https://github.com/quickfix-j/quickfixj/blob/QFJ_RELEASE_2_3_1/quickfixj-core/src/main/java/quickfix/ThreadedSocketInitiator.java#L111

As you can see you cannot call startInitiators() without calling start().

If I put back @SpyBean then everything works !

Thank you in advance for your help 🙏🏻

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 28, 2024
@sbrannen sbrannen self-assigned this Nov 28, 2024
@sbrannen sbrannen added in: test Issues in the test module status: waiting-for-triage An issue we've not yet triaged or decided on and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 28, 2024
@sbrannen sbrannen changed the title Spring-Boot 3.4.0 @MockitoSpyBean don't see the first interaction @MockitoSpyBean does not see the first interaction Nov 28, 2024
@quaff
Copy link
Contributor

quaff commented Nov 29, 2024

It may be duplicate of #33941.

sbrannen added a commit that referenced this issue Nov 29, 2024
As a follow up to commit 0088b9c, this commit introduces an
integration test which verifies that a spy created via @⁠MockitoSpyBean
using the MockReset.AFTER strategy is not reset between the refresh of
the ApplicationContext and the first use of the spy within a @⁠Test
method.

See gh-33941
See gh-33986
@sbrannen
Copy link
Member

Hi @McKratt,

Congratulations on submitting your first issue for the Spring Framework! 👍

Like @quaff, I also assumed this was a duplicate of #33941, but I wanted to verify that.

So, I created an integration test specific to @MockitoSpyBean in 51956fa. That fails with 6.2.0 but passes with 6.2.1 snapshots.

In light of that, I am closing this issue.

In any case, if you get a chance please try out 6.2.1-SNAPSHOT builds and let us know if your issue is resolved.

Cheers,

Sam

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2024
@sbrannen sbrannen added status: duplicate A duplicate of another issue type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 29, 2024
@McKratt
Copy link
Author

McKratt commented Nov 29, 2024

Hi @sbrannen,

Great news ! Thanks a lot. I'll wait the next version then 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module status: duplicate A duplicate of another issue type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants