DefaultPersistenceManager implements PersistenceManager<T, I> { @Override public T create(final T entity) { LOG.info("Saving entity for class:{}", entity.getClass()); verify(DaoMethod.CREATE, entity); enhance(DaoMethod.CREATE, entity); entityManager.persist(entity); return entity; }  @Override T create(final T entity); @Override T findById(final Class<T> clazz, final I id); @Override T update(final T entity); @Override void remove(final T entity); @Override PagedResult<T> search(final MultiplePagedQuerySearch<T> request); @Override T getSingleResult(final Query<T> query); @Override List<E> getMultipleResult(final Query<E> query); List<Object[]> executeNativeQuery(String sql); @Override Object[] executeSingleResultNativeQuery(String sql); void setPersistenceChains(final Map<DaoMethod, VerifierChainLink<? super Object>> persistenceChains); void setPersistenceEnhancers(final Map<DaoMethod, Enhancer<? super Object>> persistenceEnhancers);  }
@Test public void testCreate() throws Exception { String name = "name"; String abbrName = "abbrName"; String groupTitle = "group"; String login = "login"; User user = new User(); user.setLogin(login); Group group = new Group(); group.setTitle(groupTitle); Department expected = new Department(); expected.setAbbrName(abbrName); expected.setName(name); expected.setCrtUser(user.getLogin()); expected.setCrtUserGroup(group.getTitle()); when(sessionService.getUser()).thenReturn(user); when(sessionService.getDefaultGroup()).thenReturn(group); Department actual = unit.create(expected); verify(entityManager).persist(expected); assertEquals(expected, actual); }