DefaultPersistenceManager implements PersistenceManager<T, I> { @Override public T getSingleResult(final Query<T> query) { Query<T> finalQuery = query; TypedQuery<T> typedQuery = createQuery(finalQuery.getQuery(), finalQuery.getParameters(), finalQuery.getClazz()); return typedQuery.getSingleResult(); }  @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 testGetSingleResult() throws Exception { String querySql = "SELECT d FROM Department d WHERE d.abbrName = :abbrName"; String abbrName = "abbr name"; Map<String, Object> parameters = Collections.<String, Object>singletonMap("abbrName", abbrName); Query<Department> query = new Query<Department>(Department.class, querySql, parameters); Department expected = new Department(); when(entityManager.createQuery(anyString(), Matchers.<Class<Department>>any())).thenReturn(typedQuery); when(typedQuery.getSingleResult()).thenReturn(expected); Department actual = unit.getSingleResult(query); verify(entityManager).createQuery(querySql, query.getClazz()); verify(typedQuery).getSingleResult(); verify(typedQuery).setParameter("abbrName", abbrName); assertEquals(expected, actual); }