Skip to content

ParameterResolution for constructor argument injection for ParameterizedClass #5071

@sebersole

Description

@sebersole

I've started playing around with ParameterizedTest and ParameterizedClass a bit in Hibernate test suite. We have already built an infrastructure around extensions including ParameterResolvers. E.g., this let's us do things like:

@DomainModel(annotatedClasses=SomeEntity.class)
@SessionFactory(....)
class SomeTests {
    @Test
    void someTest(SessionFactoryScope scope) {
        SessionFactory factory = scope.getSessionFactory();
        scope.inTransaction( (session) -> {
            // do some stuff...
        } );
    }
}

(@SessionFactory registers a ParameterResolver)

Now, as I start incorporating ParameterizedClass paired with constructor-injection, I have stuff like:

@DomainModel(annotatedClasses=SomeEntity.class)
@SessionFactory(....)
@ParameterizedClass
@ValueSource(strings = { "a", "b", "c" })
class SomeTests {
    private String param;

    SomeTests(String param) {
        this.param = param;
    }

    @Test
    void someTest(SessionFactoryScope scope) {
        SessionFactory factory = scope.getSessionFactory();
        scope.inTransaction( (session) -> {
            // do some stuff...
        } );
    }
}

Which works great. But I (naively) thought I should be able to do:

@DomainModel(annotatedClasses=SomeEntity.class)
@SessionFactory(....)
@ParameterizedClass
@ValueSource(strings = { "a", "b", "c" })
class SomeTests {
    private final String param;
    private final SessionFactoryScope factoryScope;

    SomeTests(String param, SessionFactoryScope factoryScope) {
        this.param = param;
        this.factoryScope = factoryScope;
    }

    @Test
    void someTest() {
        SessionFactory factory = this.factoryScope.getSessionFactory();
        this.factoryScope.inTransaction( (session) -> {
            // do some stuff...
        } );
    }
}

Just to throw out as a thought.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions