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

4.x: MockBean fails with ArgumentMatcher #9397

Closed
romain-grecourt opened this issue Oct 16, 2024 · 0 comments · Fixed by #9398
Closed

4.x: MockBean fails with ArgumentMatcher #9397

romain-grecourt opened this issue Oct 16, 2024 · 0 comments · Fixed by #9398
Assignees
Labels
4.x Version 4.x bug Something isn't working MP P3 testing
Milestone

Comments

@romain-grecourt
Copy link
Contributor

romain-grecourt commented Oct 16, 2024

Environment Details

  • Helidon Version: 4.0.12
  • Helidon MP

Problem Description

If a test uses an argument matcher, it fails with the following error:

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: 
Misplaced or misused argument matcher detected here:

When mocked instances are created in ApplicationScoped the injected instance is a client proxy, and the mocked instance is lazily created on first usage. This breaks when using argument matchers.

A work-around is to call toString() on the mocked instance to force the creation of the mock before using matchers on the mocked instance.

Steps to reproduce

@MockBean
private Service service;

@Test
void testArgumentMatcher() {
    Mockito.when(service.test(anyString())).thenReturn("Mocked");
}
@romain-grecourt romain-grecourt self-assigned this Oct 16, 2024
@github-project-automation github-project-automation bot moved this to Triage in Backlog Oct 16, 2024
@romain-grecourt romain-grecourt added this to the 4.2.0 milestone Oct 16, 2024
romain-grecourt added a commit to romain-grecourt/helidon that referenced this issue Oct 16, 2024
- Use Singleton instead of ApplicationScoped to avoid client proxies
- Use produceWith instead of createWith
- Use addTransitiveTypeClosure instead of addType to support more than just one type
- Minor refactoring of the processMockBean method
- Add unit test

Fixes helidon-io#9397

Use a pseudo scope instead of ApplicationScoped to avoid client proxies
romain-grecourt added a commit to romain-grecourt/helidon that referenced this issue Oct 16, 2024
- Use Singleton instead of ApplicationScoped to avoid client proxies
- Use produceWith instead of createWith
- Use addTransitiveTypeClosure instead of addType to support more than just one type
- Minor refactoring of the processMockBean method
- Add unit test

Fixes helidon-io#9397
romain-grecourt added a commit to romain-grecourt/helidon that referenced this issue Oct 16, 2024
- Call toString() to force initialization of the mocked instances
- Use produceWith instead of createWith
- Use addTransitiveTypeClosure instead of addType to support more than just one type
- Minor refactoring of the processMockBean method
- Add unit test

Fixes helidon-io#9397
@jbescos jbescos self-assigned this Oct 16, 2024
jbescos added a commit to jbescos/helidon that referenced this issue Oct 16, 2024
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
jbescos added a commit to jbescos/helidon that referenced this issue Oct 16, 2024
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
jbescos added a commit to jbescos/helidon that referenced this issue Oct 16, 2024
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
jbescos added a commit to jbescos/helidon that referenced this issue Oct 16, 2024
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
jbescos added a commit to jbescos/helidon that referenced this issue Oct 16, 2024
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
jbescos added a commit to jbescos/helidon that referenced this issue Oct 16, 2024
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
romain-grecourt added a commit to romain-grecourt/helidon that referenced this issue Oct 16, 2024
- Call toString() to force initialization of the mocked instances
- Use produceWith instead of createWith
- Use addTransitiveTypeClosure instead of addType to support more than just one type
- Minor refactoring of the processMockBean method
- Add unit test

Fixes helidon-io#9397
romain-grecourt added a commit to romain-grecourt/helidon that referenced this issue Oct 17, 2024
- Call toString() to force initialization of the mocked instances
- Use produceWith instead of createWith
- Use addTransitiveTypeClosure instead of addType to support more than just one type
- Minor refactoring of the processMockBean method
- Add unit test
- Re-work HelidonTestNgListener to initialize the testInstance with an extension

Fixes helidon-io#9397
@m0mus m0mus added bug Something isn't working P3 labels Oct 17, 2024
@m0mus m0mus moved this from Triage to Sprint Scope in Backlog Oct 17, 2024
@github-project-automation github-project-automation bot moved this from Sprint Scope to Closed in Backlog Oct 17, 2024
arjav-desai pushed a commit to arjav-desai/helidon that referenced this issue Dec 11, 2024
- Call toString() to force initialization of the mocked instances
- Use produceWith instead of createWith
- Use addTransitiveTypeClosure instead of addType to support more than just one type
- Minor refactoring of the processMockBean method
- Add unit test
- Re-work HelidonTestNgListener to initialize the testInstance with an extension

Fixes helidon-io#9397
Fixes helidon-io#9411
danielkec pushed a commit to danielkec/helidon that referenced this issue Dec 20, 2024
- Call toString() to force initialization of the mocked instances
- Use produceWith instead of createWith
- Use addTransitiveTypeClosure instead of addType to support more than just one type
- Minor refactoring of the processMockBean method
- Add unit test
- Re-work HelidonTestNgListener to initialize the testInstance with an extension

Fixes helidon-io#9397
Fixes helidon-io#9411

(cherry picked from commit 6a93b66)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x bug Something isn't working MP P3 testing
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants