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

	when(contactDao.find(any(), anyMap())).thenReturn(contactRef);
	when(contactDao.merge(any(Contact.class), anyMap())).thenAnswer(new Answer<Contact>() {
		@Override
		public Contact answer(InvocationOnMock invocation) throws Throwable {
			Contact contactRet = (Contact) invocation.getArguments()[0];
			// dirty but necessary
			Method idSetter = contactRet.getClass().getDeclaredMethod("setId", Long.TYPE);
			idSetter.setAccessible(true);
			idSetter.invoke(contactRet, 11);
			return contactRet;
		}
	});
	contactDtoRef.setRevision(contactRef.getRev());
	// now go
	ContactDto contactDtoNew = webservice.addHistoryToContact(contactDtoRef, contactDtoRef.getHistory().get(0), true);
	verify(contactDao).find(eq(new Long(11)), anyMap());
	verify(contactDao).merge(argThat(new BaseMatcher<Contact>() {
		@Override
		public boolean matches(Object arg0) {
			return arg0 != null && (arg0 instanceof Contact) && ((Contact) arg0).getId() == 11 && ((Contact) arg0).getRev() == 3
					&& "Hans Hummel".equals(((Contact) arg0).getName()) && ((Contact) arg0).getHistory().size() == 2
					&& "mors, mors".equals(((Contact) arg0).getHistory().get(0).getText())
					&& "grrr".equals(((Contact) arg0).getHistory().get(1).getText())
					&& dateRef.equals(((Contact) arg0).getHistory().get(1).getTimestamp());
		}
		@Override
		public void describeTo(Description arg0) {
			arg0.appendText("ID=11, Rev=3, Name=Hans Hummel, old hist + new hist");
		}
	}), anyMap());
	assertEquals(11, contactDtoNew.getId());
	assertEquals(3, contactDtoNew.getRevision());
	assertEquals("Hans Hummel", contactDtoNew.getName());
	assertEquals(2, contactDtoNew.getHistory().size());
	assertEquals("mors, mors", contactDtoNew.getHistory().get(0).getText());
	assertEquals(dateRef, contactDtoNew.getHistory().get(0).getTimestamp());
	assertEquals("grrr", contactDtoNew.getHistory().get(1).getText());
	assertEquals(dateRef, contactDtoNew.getHistory().get(1).getTimestamp());
}