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: HelidonTestNgListener creates new AnnotatedType #9411

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

4.x: HelidonTestNgListener creates new AnnotatedType #9411

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

Comments

@romain-grecourt
Copy link
Contributor

romain-grecourt commented Oct 17, 2024

Environment Details

  • Helidon Version: 4.1.2
  • Helidon MP

Problem Description

HelidonTestNgListener lets TestNG create the test instance and then uses CDI to perform injection.

It uses beanManager.createAnnotatedType(clazz) which discards anything done by extensions with ProcessAnnotatedType.

E.g MockBeansCdiExtension adds an @Inject annotation programmatically.

Steps to reproduce

@HelidonTest
@AddBean(TestMockBeanNoInject.Service.class)
class TestMockBeanNoInject {

    @MockBean
    private Service service;

    @Test
    void testArgumentMatcher() {
        assertThat(service, is(not(nullValue())));
    }

    @ApplicationScoped
    static class Service {
        String test(String str) {
            return "Not Mocked: " + str;
        }
    }
}
@romain-grecourt romain-grecourt added this to the 4.2.0 milestone Oct 17, 2024
@romain-grecourt romain-grecourt self-assigned this Oct 17, 2024
@github-project-automation github-project-automation bot moved this to Triage in Backlog Oct 17, 2024
@m0mus m0mus added bug Something isn't working P2 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 P2 testing
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants