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>
The text was updated successfully, but these errors were encountered:
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";
}
}
@service
public class SomeService {
@Inject
private List injectableClassList;
}
public class JmockitInjectionIssueTest {
@tested
private SomeService someService;
}
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>
The text was updated successfully, but these errors were encountered: