### Question:
EntityRepositoryHandler implements EntityRepository<E, PK>, DelegateQueryHandler { @Override public E findBy(PK primaryKey) { Query query = context.getMethod().getAnnotation(Query.class); if (query != null && query.hints().length > 0) { Map<String, Object> hints = new HashMap<String, Object>(); for (QueryHint hint : query.hints()) { hints.put(hint.name(), hint.value()); } return entityManager().find(entityClass(), primaryKey, hints); } else { return entityManager().find(entityClass(), primaryKey); } }  @Override @RequiresTransaction E save(E entity); @Override @RequiresTransaction E saveAndFlush(E entity); @Override @RequiresTransaction E saveAndFlushAndRefresh(E entity); @Override @RequiresTransaction void refresh(E entity); @Override E findBy(PK primaryKey); @Override Optional<E> findOptionalBy(PK primaryKey); @Override List<E> findBy(E example, SingularAttribute<E, ?>... attributes); @Override List<E> findBy(E example, int start, int max, SingularAttribute<E, ?>... attributes); @Override List<E> findByLike(E example, SingularAttribute<E, ?>... attributes); @Override List<E> findByLike(E example, int start, int max, SingularAttribute<E, ?>... attributes); @SuppressWarnings("unchecked") @Override List<E> findAll(); @SuppressWarnings("unchecked") @Override List<E> findAll(int start, int max); @Override Long count(); @Override Long count(E example, SingularAttribute<E, ?>... attributes); @Override Long countLike(E example, SingularAttribute<E, ?>... attributes); @SuppressWarnings("unchecked") @Override PK getPrimaryKey(E entity); @Override @RequiresTransaction void remove(E entity); @Override @RequiresTransaction void removeAndFlush(E entity); @Override @RequiresTransaction void attachAndRemove(E entity); @Override @RequiresTransaction void flush(); EntityManager entityManager(); CriteriaQuery<E> criteriaQuery(); TypedQuery<E> typedQuery(String qlString); @SuppressWarnings("unchecked") Class<E> entityClass(); String tableName(); String entityName();  }### Answer:
@Test public void should_find_by_pk() throws Exception { Simple simple = testData.createSimple("testFindByPk"); Simple find = repo.findBy(simple.getId()); assertEquals(simple.getName(), find.getName()); }
@Test @SuppressWarnings("unchecked") public void should_find_by_example() throws Exception { Simple simple = testData.createSimple("testFindByExample"); List<Simple> find = repo.findBy(simple, Simple_.name); assertNotNull(find); assertFalse(find.isEmpty()); assertEquals(simple.getName(), find.get(0).getName()); }
@Test @SuppressWarnings("unchecked") public void should_find_by_example_with_start_and_max() throws Exception { Simple simple = testData.createSimple("testFindByExample1", Integer.valueOf(10)); testData.createSimple("testFindByExample1", Integer.valueOf(10)); List<Simple> find = repo.findBy(simple, 0, 1, Simple_.name, Simple_.counter); assertNotNull(find); assertFalse(find.isEmpty()); assertEquals(1, find.size()); assertEquals(simple.getName(), find.get(0).getName()); }
@Test @SuppressWarnings("unchecked") public void should_find_by_example_with_no_attributes() throws Exception { Simple simple = testData.createSimple("testFindByExample"); SingularAttribute<Simple, ?>[] attributes = new SingularAttribute[] {}; List<Simple> find = repo.findBy(simple, attributes); assertNotNull(find); assertFalse(find.isEmpty()); assertEquals(simple.getName(), find.get(0).getName()); }