Object[] args = inv.getArguments();
return stored.get((String) args[0]);
}
public static JsonSerializer createMockSerializer() {
JsonSerializer ser = mock(JsonSerializer.class);
// @formatter:off
when(ser.toString(any(Document.class))).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock inv) {
Document doc = (Document) inv.getArguments()[0];
serialized.put(doc.getUserId(), doc);
return doc.getUserId();
}
});
when(ser.toString(any(Item.class))).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock inv) {
Item item = (Item) inv.getArguments()[0];
String key = String.valueOf(item.getId());
serialized.put(key, item);
return key;
}
});
when(ser.getDocument(anyString())).thenAnswer(new Answer<Document>() {
public Document answer(InvocationOnMock inv) {
String key = (String) inv.getArguments()[0];
return (Document) serialized.get(key);
}
});
when(ser.getItem(anyString())).thenAnswer(new Answer<Item>() {
public Item answer(InvocationOnMock inv) {
String key = (String) inv.getArguments()[0];
return (Item) serialized.get(key);
}
});