Q:

mockito method when passing an object

I am trying to mock a DAO method in Spring/Hibernate which takes an object and returns an object.
Mockito.when(mockedDao.findByProperty(c)).thenReturn(state);

c object has key-value pairs like "name", "ben". state object would have the employment status.
But when I run the test it returns null. I think its because the criteria parameter which I am passing in unit test is not exactly the same all though they are equal. How do I work around this issue? Criteria here is an object with key-values not related to the hibernate criteria...
here is "service.getELementByName":
    @Override
@Transactional
public State getElementByName(Object value) {
    Criteria c = new Criteria();
    c.property = "state_name";
    c.value = (String) value;
    State result = (State) stateDAO.findByProperty(c);
    return result;
}

please suggest!
Thanks

edit
code looks something like this
private State state;

@Mock
private StateDAO mockedDao;
@InjectMocks
private StateServiceImpl service;

@Before
public void init() {
    // mockedDao = mock(StateDAO.class);
    Criteria c = new Criteria();
    c.property = "state_name";
    c.value = (String) "Virginia";
    state = new State();
    state.setId(20);
    state.setIntPtLat(37.5222512);
    state.setIntPtLon(-78.6681938);
    state.setStateName("Virginia");
    Mockito.when(mockedDao.findByProperty(eq(c))).thenReturn(state);
    // service = new StateServiceImpl<State>();
}

@Test
public void testFindByProperty() {

    state = new State();
    state.setId(20);
    state.setIntPtLat(37.5222512);
    state.setIntPtLon(-78.6681938);
    state.setStateName("Virginia");

    Criteria c = new Criteria();
    c.property = "state_name";
    c.value = (String) "Virginia";
    Mockito.when(mockedDao.findByProperty(eq(c))).thenReturn(state);
    service.getElementByName("Virginia");
    State result = (State) service.getElementByName("Tes");
    assertEquals(state, result);
}

A:

If you need to add behaviour based on that specific instance of Criteria being passed to findByProperty then you need to get to the bottom of why Mockito doesn't think it's the same - until more code is posted we can't help! 
However, if that's not the case and any instance will do, then you can use an argument matcher to relax things a bit, e.g.:
Mockito.when(mockedDao.findByProperty(any(Criteria.class))).thenReturn(state);

Like I said, it depends on what you're testing though.
I hope that helps.

A:

Are you calling Mockito.initMocks(this) anywhere? If not, that may be your problem.

