CategoryServiceImpl extends BaseGenericServiceImpl<Category> implements CategoryService { @Override public boolean isCategoryHasChildren(final long categoryId) { final List<Long> id = getCategoryIdAndLinkId(categoryId); if (id != null) { final int qty = categoryDao.findCountByNamedQuery("CATEGORY.SUBCATEGORY.COUNT", id); return qty > 0; } return false; } CategoryServiceImpl(final GenericDAO<Category, Long> categoryDao,
                               final ShopCategoryRelationshipSupport shopCategoryRelationshipSupport); @Override Category getRootCategory(); @Override List<Long> getCategoryLinks(final long categoryId); @Override String getCategoryTemplate(final long categoryId); @Override String getCategorySearchTemplate(final long categoryId); @Override Long getCategoryProductTypeId(final long categoryId); @Override boolean isCategoryHasChildren(final long categoryId); @Override List<Category> getChildCategories(final long categoryId); @Override List<Category> findChildCategoriesWithAvailability(final long categoryId, final boolean withAvailability); @Override Set<Category> getChildCategoriesRecursive(final long categoryId); @Override Set<Long> getAllCategoryIds(final Collection<String> guids); @Override List<Long> getChildCategoriesRecursiveIds(final long categoryId); @Override List<Long> getChildCategoriesRecursiveIdsAndLinkIds(final long categoryId); @Override List<Category> findCategories(final int start, final int offset, final String sort, final boolean sortDescending, final Map<String, List> filter); @Override int findCategoryCount(final Map<String, List> filter); @Override List<Long> getCategoryIdAndLinkId(final long categoryId); @Override boolean isCategoryHasSubcategory(final long topCategoryId, final long subCategoryId); @Override Category getById(final long pk); @Override Long findCategoryIdBySeoUri(final String seoUri); @Override Long findCategoryIdByGUID(final String guid); @Override String findSeoUriByCategoryId(final Long categoryId); @Override Category findCategoryIdBySeoUriOrGuid(final String seoUriOrGuid); @Override List<Category> findByProductId(final long productId); CategoryService getSelf();  }
@Test public void testIsCategoryHasChildrenTrue() throws Exception { assertTrue(categoryService.isCategoryHasChildren(101L)); }
@Test public void testIsCategoryHasChildrenLinkedTrue() throws Exception { assertTrue(categoryService.isCategoryHasChildren(411L)); }
@Test public void testIsCategoryHasChildrenFalse() throws Exception { final Category newCategory = categoryService.getGenericDao().getEntityFactory().getByIface(Category.class); newCategory.setGuid("TEST-CHILDREN"); newCategory.setName("TEST-CHILDREN"); final Category saved = categoryService.create(newCategory); assertFalse(categoryService.isCategoryHasChildren(saved.getCategoryId())); categoryService.delete(saved); }