<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">Issue reported on Mockito:</div><div class="gmail_default"><font face="monospace, monospace"><a href="https://github.com/mockito/mockito/issues/990">https://github.com/mockito/mockito/issues/990</a></font><br></div><div class="gmail_default"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 16, 2017 at 8:36 PM, Allon Mureinik <span dir="ltr"><<a href="mailto:amureini@redhat.com" target="_blank">amureini@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">The root cause seems to be MigrateVmCommandTest and its relation to MigrateVmCommand.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">A common misconception is that if an object is annotated with @InjectMocks, Mockito will inject its @Mocks and @Spys to fields annotated with @Inject.</div><div class="gmail_default" style="font-family:monospace,monospace">This is, as noted, not correct - Mockito will attempt to injcet its mocks to *ALL* the fields, regardless of annotations.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">And here's where things start getting funky.</div><div class="gmail_default" style="font-family:monospace,monospace">Since the new field you introduced is an Object, any mock would be a possible match for it. If more than one mock fits the field (as you have in the test - dbFacade and vmValidator), Mockito silently skips injecting it, and leaves it null (not sure if this is a bug or an intentional ugly behavior) - need to look into this further.</div><div class="gmail_default" style="font-family:monospace,monospace">Even worse, this failure breaks the mocking sequence, so the mocked object isn't spied. When you attempt to stub it's behavior (e.g., with doReturn, as the first line of <wbr>testValidationFailsWhenVmHasDi<wbr>sksPluggedWithScsiReservation does), it will fail with a NotAMockException). From there on, it's all down hill.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">The good news is that this test doesn't really need to inject mocks, so just removing that annotation solves the issue. I've posted a patch [1], please review it.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">I'll also organize an MCVE reproducer and report a bug against mockito, and we'll see if there's any chance to get it solved any time soon.</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">-Allon</div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace">[1] <a href="https://gerrit.ovirt.org/#/q/topic:MigrateVmCommandTest" target="_blank">https://gerrit.ovirt.org/#<wbr>/q/topic:MigrateVmCommandTest</a></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 16, 2017 at 11:55 AM, Shmuel Melamud <span dir="ltr"><<a href="mailto:smelamud@redhat.com" target="_blank">smelamud@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi!<br>
<br>
I've found yesterday a very strange bug, most likely in Mockito. Hard<br>
to believe it really happens, but I've reproduced it in different<br>
environmentы and several revisions of oVirt master.<br>
<br>
I've added the following line into MigrateVmCommand:<br>
<br>
private Integer actualDowntime;<br>
+ private Object actualDowntimeLock;<br>
<br>
This line causes ALL tests to fail with NullPointerException. Some<br>
tests print such a stack trace:<br>
<br>
java.lang.NullPointerException<br>
at org.mockito.internal.junit.uti<wbr>l.TestName.getTestName(TestNam<wbr>e.java:11)<br>
at org.mockito.internal.junit.Mis<wbr>matchReportingTestListener.tes<wbr>tFinished(MismatchReportingTes<wbr>tListener.java:29)<br>
at org.mockito.internal.runners.D<wbr>efaultInternalRunner$1$1.testF<wbr>inished(DefaultInternalRunner.<wbr>java:56)<br>
at org.junit.runner.notification.<wbr>SynchronizedRunListener.testFi<wbr>nished(SynchronizedRunListener<wbr>.java:56)<br>
at org.junit.runner.notification.<wbr>RunNotifier$7.notifyListener(R<wbr>unNotifier.java:190)<br>
...<br>
<br>
Name of the field doesn't matter, but type matters - changing the type<br>
to Integer solved the problem.<br>
<br>
Does anybody has an idea why this happens and how to fix it?<br>
<br>
Shmuel<br>
______________________________<wbr>_________________<br>
Devel mailing list<br>
<a href="mailto:Devel@ovirt.org" target="_blank">Devel@ovirt.org</a><br>
<a href="http://lists.ovirt.org/mailman/listinfo/devel" rel="noreferrer" target="_blank">http://lists.ovirt.org/mailman<wbr>/listinfo/devel</a></blockquote></div><br></div>
</div></div></blockquote></div><br></div>