Skip to content

Method parameter injection fails with parametrized argument types #149

Closed
@JHahnHRO

Description

@JHahnHRO

The following three test fail:

@ApplicationScoped
public class MapProducer {

    @Produces
    @Dependent
    public <T> Map<String,T> produceMap(InjectionPoint ip) {
        Map<String, T> map = new HashMap<>();
        map.put(ip.getType().getTypeName(), null);
        return map;
    }
}

@EnableWeld
class TestParameterInjectionWithParametrizedTypes {
   @Test
   public void testparamInjectionWithEvent(Event<String> stringEvent) {
       Assertions.assertNotNull(stringEvent);
   }
   @Test
   public void testparamInjectionWithInstance(Instance<String> stringInstance) {
       Assertions.assertNotNull(stringInstance);
   }
   @Test
   public void testparamInjectionWithOtherParametrizedType(Map<String, Integer> map) {
       Assertions.assertNotNull(map);
       Assertions.assertTrue(map.containsKey("java.util.Map<java.lang.String, java.lang.Integer>"));
   }
}

The reason is that WeldJunit5Extension uses
getContainerFromStore(extensionContext).select(parameterContext.getParameter().getType(), ...
instead of
getContainerFromStore(extensionContext).select(parameterContext.getParameter().getParametrizedType(), ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions