### Question:
LocalEntityProvider implements EntityProvider<T>, Serializable { protected List<SortBy> addPrimaryKeyToSortList(List<SortBy> original) { if (sortByListContainsPrimaryKey(original)) { return original; } ArrayList<SortBy> newList = new ArrayList<SortBy>(); newList.addAll(original); if (getEntityClassMetadata().hasEmbeddedIdentifier()) { for (String p : getEntityClassMetadata().getIdentifierProperty() .getTypeMetadata().getPersistentPropertyNames()) { newList.add(new SortBy(getEntityClassMetadata() .getIdentifierProperty().getName() + "." + p, true)); } } else { newList.add(new SortBy(getEntityClassMetadata() .getIdentifierProperty().getName(), true)); } return Collections.unmodifiableList(newList); } LocalEntityProvider(Class<T> entityClass, EntityManager entityManager);  LocalEntityProvider(Class<T> entityClass);  LocalEntityProvider(Class<T> entityClass,
            EntityManagerProvider entityManagerProvider); void setEntityManagerProvider(
            EntityManagerProvider entityManagerProvider); EntityManagerProvider getEntityManagerProvider(); void setEntityManager(EntityManager entityManager); EntityManager getEntityManager(); boolean containsEntity(EntityContainer<T> container,
            Object entityId, Filter filter); T getEntity(EntityContainer<T> container, Object entityId); Object getEntityIdentifierAt(EntityContainer<T> container,
            Filter filter, List<SortBy> sortBy, int index); int getEntityCount(EntityContainer<T> container, Filter filter); Object getFirstEntityIdentifier(EntityContainer<T> container,
            Filter filter, List<SortBy> sortBy); Object getLastEntityIdentifier(EntityContainer<T> container,
            Filter filter, List<SortBy> sortBy); Object getNextEntityIdentifier(EntityContainer<T> container,
            Object entityId, Filter filter, List<SortBy> sortBy); Object getPreviousEntityIdentifier(EntityContainer<T> container,
            Object entityId, Filter filter, List<SortBy> sortBy); boolean isEntitiesDetached(); void setEntitiesDetached(boolean detached); List<Object> getAllEntityIdentifiers(EntityContainer<T> container,
            Filter filter, List<SortBy> sortBy); void setQueryModifierDelegate(QueryModifierDelegate delegate); QueryModifierDelegate getQueryModifierDelegate(); Object getIdentifier(T entity); T refreshEntity(T entity); void setLazyLoadingDelegate(LazyLoadingDelegate delegate); LazyLoadingDelegate getLazyLoadingDelegate(); void refresh();  }### Answer:
@Test public void testAddPrimaryKeyToSortListDoesntAddTheKeyIfAlreadyPresent() { List<SortBy> sortBys = new ArrayList<SortBy>(); sortBys.add(new SortBy("id", true)); List<SortBy> newSortBys = entityProvider .addPrimaryKeyToSortList(sortBys); assertEquals(1, newSortBys.size()); }
@Test public void testAddPrimaryKeyToSortListDoesntAddTheKeyIfAlreadyPresent_moreSortProperties() { List<SortBy> sortBys = new ArrayList<SortBy>(); sortBys.add(new SortBy("id", true)); sortBys.add(new SortBy("foo", true)); sortBys.add(new SortBy("bar", true)); sortBys.add(new SortBy("baz", true)); List<SortBy> newSortBys = entityProvider .addPrimaryKeyToSortList(sortBys); assertEquals(4, newSortBys.size()); }
@Test public void testAddPrimaryKeyToSortListAddsKeyIfNotPresent() { List<SortBy> sortBys = new ArrayList<SortBy>(); sortBys.add(new SortBy("foo", true)); sortBys.add(new SortBy("bar", true)); sortBys.add(new SortBy("baz", true)); List<SortBy> newSortBys = entityProvider .addPrimaryKeyToSortList(sortBys); assertEquals(4, newSortBys.size()); }