CrmWebserviceEndpoint { @WebMethod public ContactDto addContact(@WebParam(name = "contactDto") ContactDto contactDto) { Contact contact = new Contact(); obtainContactMapper().mapContactWithoutHistoryInbound(contactDto, contact); contact.setRev(0); incrementRevision(contact); contact = contactDao.merge(contact, new HashMap<String, Object>()); contactDto = new ContactDto(); obtainContactMapper().mapContactWithoutHistory(contact, contactDto); return contactDto; } CrmWebserviceEndpoint();  CrmWebserviceEndpoint(ContactDao contactDao); @Inject @WebMethod(exclude = true) void setContactDao(ContactDaoEjb contactDao); @WebMethod List<ContactDto> getContracts(@WebParam(name = "from") int from, @WebParam(name = "limit") int limit); @WebMethod ContactDto getContactIncludingHistory(@WebParam(name = "id") long id); @WebMethod ContactDto addContact(@WebParam(name = "contactDto") ContactDto contactDto); @WebMethod ContactDto updateContact(@WebParam(name = "contactDto") ContactDto contactDto); @WebMethod ContactDto addHistoryToContact(@WebParam(name = "contactDto") ContactDto contactDto, @WebParam(name = "historyDto") HistoryDto historyDto,
			@WebParam(name = "returnHistory") boolean returnHistory);  }
@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()); Method idSetter = contactRet.getClass().getDeclaredMethod("setId", Long.TYPE); idSetter.setAccessible(true); idSetter.invoke(contactRet, 111); return contactRet; } }); 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()); }