Why does updating Mockito from 1.9.5 to 1.10.8 break this Captor?

Given this target code:

...
sessionWrapper.execute(arenaCreateCql, arenaGuid, arenaName, displayName, authorName, createdOn);
...

      

And Mockito's code to test this line:

...
@Captor
private ArgumentCaptor<Date> createdOnCaptor;
...
@Test
public void testThat_Execute_CreatesNewArena() throws Exception {
    ...
    inOrder.verify(mockSessionWrapper).execute(
        eq(arenaCreateCql), eq(testArenaGuid), eq(testArenaName), eq(testArenaDisplayName), eq(testAuthorName), createdOnCaptor.capture());
    ...
    assertNotNull(createdOnCaptor.getValue());
}

      

This works using Mockito 1.9.5. On update 1.10.8, the check passes, but getValue () fails with this error:

org.mockito.exceptions.base.MockitoException: 
No argument value was captured!
You might have forgotten to use argument.capture() in verify()...
...or you used capture() in stubbing but stubbed method was not called.
Be aware that it is recommended to use capture() only with verify()

      

Edit to add MCVE. The following code works green with Mockito 1.9.5, red with Mockito 1.10.8.

MockitoExample.java:

package org.makeyourcase.example;

import java.util.Date;

public class MockitoExample {

    private MockitoExampleExecutor executor;

    public void execute(){
        executor.execute("var1", new Date());
    }
}

      

MockitoExampleExecutor.java:

package org.makeyourcase.example;

public class MockitoExampleExecutor {

    public void execute(Object... bindVariables){
    }
}

      

MockitoExample_UT:

package org.makeyourcase.example;

import java.util.Date;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public class MockitoExample_UT {

    @Mock
    private MockitoExampleExecutor mockitoExampleExecutor;
    @Captor
    private ArgumentCaptor<Date> dateCaptor;
    @InjectMocks
    private MockitoExample subject;

    @Test
    public void testThat_Execute_InvokesCalendar() throws Exception {
        subject.execute();
        verify(mockitoExampleExecutor).execute(eq("var1"), dateCaptor.capture());
        assertNotNull(dateCaptor.getValue());
    }
}

      

As a result of creating the MCVE, another piece of information was revealed - the test works fine if Date is the only element passed for bindVariables

. That is, remove "var1" from the target and test code, then the test runs fine according to 1.9.5 and 1.10.8. Also, it doesn't matter what the catcher is for a date. The same problem occurs if the parameter is of a different type, such as Integer.

+3


source to share


1 answer


Thank you, this is probably a bug, I created a GH-188 report .



Not sure when it will be fixed. Fixed in GH-211 .

+2


source







All Articles