Mockitoを使用して具体的なクラスをモックしようとしています。ただし、テスト対象のサービスではnullのままです。
私の具体的なクラスとサービス:
//My Concrete Class
@Component("supporter")
public class Supporter
{
@Autowired
private IDriver driver;
public int someMethod(int){...}
...
}
//Service Class that uses this abstract class
public class Service implements IService
{
private ExceptionHandler exceptionHandler;
@Autowired
public void setExceptionHandler(ExceptionHandler exceptionHandler) {
this.exceptionHandler = exceptionHandler;
}
private Supporter supporter;
@Autowired
public void setSupporter(Supporter supporter) {
this.supporter = supporter;
}
public int hookItem(int arg)
{
...
//supporter is always null while mock testing <----
int count = supporter.someMethod(arg);
...
return count;
}
}
私のテストコード:
public class ServiceTest extends AbstractTestMockito
{
...
IService service = null;
@Mock
private ExceptionHandler exceptionHandler;
@BeforeMethod
public void setup() {
service = new Service();
}
@Test(enabled=true)
public void shouldDoSomething()
{
Supporter supporter = Mockito.mock(Supporter.class);
given(supporter.someMethod(1)).willReturn(new Integer(10));
final int response = service.hookItem(1);
//Assert...
}
}
それがnullである理由は何でしょうか?(私のクラス/サービスはSpring Beansです)