2.0.8-beta -> 2.0.9-beta 'Unable to initialize @Spy annotated field
See original GitHub issueNo test failures when using 2.0.8-beta, but when incrementing to 2.0.9-beta, the following error occurs:
org.mockito.exceptions.base.MockitoException: Unable to initialize @Spy annotated field 'monitorTaskScheduler'.
Unable to create mock instance of type 'MonitorTaskScheduler'
at net.project.dash.monitor.MonitorTaskScheduler$MockitoMock$1184625981.getExecutorService(Unknown Source)
at net.project.dash.monitor.MonitorTaskScheduler.<init>(MonitorTaskScheduler.java:39)
at net.project.dash.monitor.MonitorTaskScheduler$MockitoMock$1184625981.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.mockito.internal.creation.instance.ConstructorInstantiator.invokeConstructor(ConstructorInstantiator.java:42)
at org.mockito.internal.creation.instance.ConstructorInstantiator.noArgConstructor(ConstructorInstantiator.java:66)
at org.mockito.internal.creation.instance.ConstructorInstantiator.newInstance(ConstructorInstantiator.java:17)
at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:27)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:33)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59)
at org.mockito.Mockito.mock(Mockito.java:1284)
at org.mockito.internal.configuration.SpyAnnotationEngine.newSpyInstance(SpyAnnotationEngine.java:117)
at org.mockito.internal.configuration.SpyAnnotationEngine.process(SpyAnnotationEngine.java:67)
at org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentAnnotations(InjectingAnnotationEngine.java:73)
at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:55)
at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:108)
at net.project.dash.monitor.MonitorTaskSchedulerTest.setUp(MonitorTaskSchedulerTest.java:38)
Relevant code (MonitorTaskSchedulerTest.java)
@Spy
MonitorTaskScheduler monitorTaskScheduler;
@Before
public void setUp()
{
MockitoAnnotations.initMocks(this);
}
Relevant code (MonitorTaskScheduler.java)
public class MonitorTaskScheduler
{
public MonitorTaskScheduler()
{
this.futureToTaskMap = new ConcurrentHashMap<>();
}
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Mockito - Unable to initialize Spy on HttpEntity - Stack Overflow
HttpEntity is an interface, it cannot be spied, only mocked. So just change the annotation with @Mock , or another option is to...
Read more >InjectMocks (Mockito 2.0.8-beta API) - javadoc.io
Minimizes repetitive mock and spy injection. Mockito will try to inject mocks only either by constructor injection, setter injection, or property injection in ......
Read more >Assessment of the Microbial Spoilage and Quality of ... - MDPI
Abstract: Fourier-transform infrared spectroscopy (FT-IR), multispectral imaging (MSI), and an elec- tronic nose (E-nose) were implemented ...
Read more >iOS version history - Wikipedia
iOS is a mobile operating system developed by Apple Inc. It was first released as iPhone OS in June 2007. iPhone OS was...
Read more >availables.xml - MIT
2.0 Bart Cremers A small calculator integrated in IntelliJ. ... Inspection that reports fields annotated with @PrivateWrite that are assigned a value, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually there maybe a better workaround, using the
Mockito.spy()
factory method.This even works with
@InjectMocks
2d036ec fixed my original issue indeed! Thanks so much, great work.