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

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

glavoie opened this issue Aug 14, 2015 · 0 comments

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

glavoie opened this issue Aug 14, 2015 · 0 comments


Copy link

@glavoie glavoie commented Aug 14, 2015

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.

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

public String getBye() {
    return "Bye";


public class SomeService {
private List injectableClassList;

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


public class JmockitInjectionIssueTest {
private SomeService someService;

@Test(fullyInitialized = true)
public void shouldPassButFailsWithNullPointerException() {


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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

No branches or pull requests

2 participants