@SuppressWarnings("unchecked")
@Test
public void testAddContact() {

	when(contactDao.merge(any(Contact.class), anyMap())).thenAnswer(new Answer<Contact>() {
		@Override
		public Contact answer(InvocationOnMock invocation) throws Throwable {
			Contact contactBase = (Contact) invocation.getArguments()[0];
			Contact contactRet = new Contact();
			contactRet.setRev(contactBase.getRev());
			contactRet.setName(contactBase.getName());
			contactRet.setHistory(contactBase.getHistory());
			// dirty but necessary
			Method idSetter = contactRet.getClass().getDeclaredMethod("setId", Long.TYPE);
			idSetter.setAccessible(true);
			idSetter.invoke(contactRet, 111);
			return contactRet;
		}
	});
	// now go
	ContactDto contactDtoNew = webservice.addContact(contactDtoRef);
	verify(contactDao).merge(argThat(new BaseMatcher<Contact>() {
		@Override
		public boolean matches(Object arg0) {
			return arg0 != null && (arg0 instanceof Contact) && ((Contact) arg0).getId() == 0 && ((Contact) arg0).getRev() == 1
					&& "Marge Simpson".equals(((Contact) arg0).getName()) && ((Contact) arg0).getHistory().size() == 0;
		}
		@Override
		public void describeTo(Description arg0) {
			arg0.appendText("ID=0, Rev=1, Name=Marge Simpson, no hist");
		}
	}), anyMap());
	assertEquals(111, contactDtoNew.getId());
	assertEquals(1, contactDtoNew.getRevision());
	assertEquals("Marge Simpson", contactDtoNew.getName());
	assertEquals(0, contactDtoNew.getHistory().size());
}