tags:

views:

172

answers:

1

I am need to send a return specific value from a mock object based on a specific key value.

concreate class:

map.put("xpath", "PRICE");
search(map);

Test case:

IOurXMLDocument mock = mock(IOurXMLDocument.class);
when(mock.search(.....need help here).thenReturn("$100.00");

how do I mock this method call for this key value pair?

+1  A: 

Doesn't this work?

Map<String, String> map = new HashMap<String, String>();
map.put("xpath", "PRICE");
when(mock.search(map)).thenReturn("$100.00");

The Map parameter should behave the same way as other parameters.

Bozho
There is missing one closing bracket.
codescape
IOurXMLDocument represents our service layer that I do not want to call for my unit tests. For 1 situation we are calling it twice with 2 different map values. Instead I want to inspect the value and return a fixed result. So when the application code does the following: map.put("xpath", "PRODUCTNAME"); when(mock.search(map)).thenReturn("Candybar");
Sean