I have SomeService that uses a @Resource annotation for EJB TimerService.
@Resource private TimerService timerService;
How can I inject a mock TimerService in place of this TimerService in SomeService?
I have SomeService that uses a @Resource annotation for EJB TimerService.
@Resource private TimerService timerService;
How can I inject a mock TimerService in place of this TimerService in SomeService?
If you're using mockito: Mockito can inject annotated fields for you see: @RunWith(MockitoJUnitRunner.class) vs MockitoAnnotations.initMocks(this)
I would suggest instead of using annotations on fields to use a annotated constructor. That way you can make all injected fields final and you will get build failures when dependencies change instead of runtime/test failures/exceptions. And the added bonus is that you can just call the constructor in your tests and inject the mocks that way.