ProductCategoryServiceImpl extends BaseGenericServiceImpl<ProductCategory> implements ProductCategoryService { @Override public int getNextRank(final long categoryId) { Integer maxRank = (Integer) getGenericDao().getScalarResultByNamedQuery("GET.MAX.RANK", categoryId); if (maxRank == null) { return RANK_STEP; } else { return maxRank + RANK_STEP; } } ProductCategoryServiceImpl(final GenericDAO<ProductCategory, Long> productCategoryDao); @Override ProductCategory findByCategoryIdProductId(final long categoryId, final long productId); @Override List<Long> getByProductId(final long productId); @Override List<ProductCategory> findByProductId(final long productId); @Override void removeByCategoryProductIds(final long categoryId, final long productId); @Override void removeByProductIds(final long productId); @Override int getNextRank(final long categoryId);  }
@Test public void testGetProductById() { ProductCategoryService productCategoryService = (ProductCategoryService) ctx().getBean(ServiceSpringKeys.PRODUCT_CATEGORY_SERVICE); int rez = productCategoryService.getNextRank(211L); assertEquals("Next rank must be 450 for 211 category", 450, rez); rez = productCategoryService.getNextRank(-777L); assertEquals("Next rank must be 50 for unexisting -777 category", 50, rez); rez = productCategoryService.getNextRank(116L); assertEquals("Next rank must be 50 for existing -116 category without products", 50, rez); }