MemoryCollectionStore extends AbstractPositionedEntityMemoryStore<Collection, CollectionPositionedEntity> implements CollectionStore { public List<EntityAndCount<Collection>> findAllWithProductCount() { return FluentIterable.from(allPositioned()).transform(entityAndCount).toList(); }  void addProduct(Collection collection, Product product); void removeProduct(Collection collection, Product product); void moveCollection(String collectionToMove, String collectionToMoveRelativeTo,
            RelativePosition relativePosition); void moveProductInCollection(Collection collection, String productToMove, String productToMoveRelativeTo,
            RelativePosition relativePosition); List<EntityAndCount<Collection>> findAllWithProductCount(); List<Collection> findAll(); List<Collection> findAllForProduct(final Product product); List<Collection> findAllForProductIds(List<UUID> ids); List<ProductCollection> findAllProductsCollectionsForIds(List<UUID> ids); @Override Collection findBySlug(final String slug, final UUID parentId); @Override List<Collection> findAllOrderedByParentAndPosition(); @Override void updateCollectionTree(List<PositionedEntity<Collection>> collections); @Override void addEntityToCollection(Collection collection, Entity entity); @Override List<EntityAndParent<Collection>> findAllForEntity(Entity entity); @Override void removeEntityFromCollection(Collection collection, Entity entity); @Override List<EntityAndParent<Collection>> findAllChildrenOfCollection(Collection entity); @Override EntityAndParent<Collection> findBySlugs(String... slugs);  }
@Test public void testFindAllWithProductCount() throws InvalidEntityException, EntityAlreadyExistsException { Product product1 = new Product(UUID.randomUUID()); Product product2 = new Product(UUID.randomUUID()); Collection collection1 = collectionStore.create(new Collection()); Collection collection2 = collectionStore.create(new Collection()); Collection collection3 = collectionStore.create(new Collection()); collectionStore.addProduct(collection1, product1); collectionStore.addProduct(collection1, product2); collectionStore.addProduct(collection2, product2); List<EntityAndCount<Collection>> allWithProductsCount = collectionStore.findAllWithProductCount(); Assert.assertEquals(3, allWithProductsCount.size()); Assert.assertEquals(new Long(2), allWithProductsCount.get(0).getCount()); Assert.assertEquals(collection1, allWithProductsCount.get(0).getEntity()); Assert.assertEquals(new Long(1), allWithProductsCount.get(1).getCount()); Assert.assertEquals(collection2, allWithProductsCount.get(1).getEntity()); Assert.assertEquals(new Long(0), allWithProductsCount.get(2).getCount()); Assert.assertEquals(collection3, allWithProductsCount.get(2).getEntity()); }