Injection of List<Service> doesn't work with Spring #198

Closed
glavoie opened this Issue Aug 14, 2015 · 0 comments

Projects

None yet

2 participants

@glavoie
glavoie commented Aug 14, 2015

Hi,
with Spring, if multiple services implements the same interface, it is possible to inject a List that will be filled with all the current active implementations. When a Spring bean that contains a injectable List is created by JMockit, the field is left with a null value.

I think that initializing the list with one mock object in it, or an injectable mock put in it could be a desirable behavior.

@Service
public class InjectableClass {
public String getHello() {
return "Hello";
}

public String getBye() {
    return "Bye";
}

}

@Service
public class SomeService {
@Inject
private List injectableClassList;

public int getServiceInstanceCount() {
    return injectableClassList.size();
}

}

public class JmockitInjectionIssueTest {
@Tested
private SomeService someService;

@Test(fullyInitialized = true)
public void shouldPassButFailsWithNullPointerException() {
    assertThat(someService.getServiceInstanceCount()).isGreaterThan(0);
}

}

When using @Tested(fullyInitialized = false) (default) and adding an "@Injectable InjectableClass" field, the following error occurs:

java.lang.IllegalStateException: Missing @Injectable for field SomeService#injectableClassList, of type java.util.List<some.package.InjectableClass>

@rliesenfeld rliesenfeld self-assigned this Aug 28, 2015
@rliesenfeld rliesenfeld added a commit that closed this issue Sep 4, 2016
@rliesenfeld rliesenfeld Added the ability to inject @Injectable's of the element type into fi…
…elds or constructor parameters of some iterable (List, Set, etc.) or javax.enterprise.inject.Instance type, in @Tested objects; closes #198.
e5ae795
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment