I have the following interface and implementation classes:-
public interface MyService {
void method1();
}
public interface MyServiceImpl implements MyService {
public void method1() {
// ...
}
/*protected*/ void method2() {
// ...
}
}
MyServiceImpl has some Spring wirings, in another word, both method1() and method2() rely on some beans wired by Spring to do their tasks.
I'm trying to test my testcase to test method2(), which is a protected method. Regardless the arguments whether we should be testing protected/private methods, that's not what I want to address here.
Right now, I'm having trouble trying to get my testcase to work properly so that it wires the beans properly.
I initially have this, but it doesn't work because it doesn't expose method2().
@Autowired
private MyService myService;
I tried this, and I get org.springframework.beans.factory.NoSuchBeanDefinitionException:-
@Autowired
@Qualifier ("myService")
private MyServiceImpl myService;
Then ,I tried this, and I get org.springframework.beans.factory.BeanNotOfRequiredTypeException:-
@Resource(name = "myService")
private MyServiceImpl myService;
The only way I can think of now is to stick with autowire and MyService, and then explicitly cast it to MyServiceImpl before executing method2().
Is there a more elegant way to do so?
Thanks.