Is there any way to mock a method which is injected by spring container using method injection approach.
Let me explain in detail
I have abstract class called Singleton which has abstract method in it
public abstract class Singleton {
protected abstract LoanField check();
private LoanField getLoanField(String name) {
LoanField field = check();
}
and it's corresponding configuration is there in one of the spring-config file.
<bean id="checkDetails" class="com.abc.tools.Singleton">
<lookup-method name="check" bean="field"/>
</bean>
<bean id="field" class="com.abc.tools.LoanField" scope="prototype"/>
Here is my test class in short
Singleton fieldManager = Mockito.mock(Singleton.class, Mockito.CALLS_REAL_METHODS);
LoanField loanField = PowerMockito.mock(LoanField.class);
PowerMockito.when(fieldManager.create()).thenReturn(loanField);
Actual problem here is, in Method Injection Spring overrides a given abstract method of an abstract class and provides an implementation of the overridden method but when i try to stub that method in my test class I'm getting below error
java.lang.AbstractMethodError: com.abc.tools.Singleton.create()Lcom/abc/tools/LoanField;
at com.abc.tools.SingletonTest.loanFiledNotNull(SingletonTest.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:66)
at
i know its not possible to stub an abstract method but is there any work around to stub the method? Please help me out.
Ps: I mentioned all the depended class in @preparefortest