Dave
Dave

Reputation: 19320

Using mockito, how do I match a field of a field?

I'm using mockito 1.9.5. I want to setup a mock call something like

            Mockito.doReturn(mockSearchData)
                    .when(myMock)
                    .searchOrganizations(id, 
                                 null,
                                 detailedSearchCriteria, 
                                 null);

only that I want to specify that I want to setup the mock when the "id" field of the "detailedSearchCriteria" object is equal to the value of "ZZ." The "detailedSearchCriteria" doesn't have an equals method and I don't control the code in order to create one. Is there any way to do this with mockito and if not, what is another framework and how could this be done there?

Upvotes: 0

Views: 569

Answers (1)

Dawood ibn Kareem
Dawood ibn Kareem

Reputation: 79875

You can write your own ArgumentMatcher, that checks whether the detailedSearchCriteria matches what you need. Check out the Mockito documentation on custom argument matchers at http://docs.mockito.googlecode.com/hg/latest/org/mockito/ArgumentMatcher.html

Upvotes: 1

Related Questions