@Test(expected = NullPointerException.class) public void getProductListByCategory_shouldThrowNPEForNullCategoryIdArgument() { productDao.getProductListByCategory(null); }
public List<Product> getProductListByCategory(final String categoryId) { checkNotNull(emptyToNull(categoryId), "Argument[categoryId] must not be empty or null"); List<Product> products = new ArrayList<>(); DBObject query = new BasicDBObject("category_id", categoryId); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("product_id", 1))) { while (cursor.hasNext()) { DBObject productObj = cursor.next(); products.add(Product.fromDBObject(productObj)); } } logger.info("Found for category id [{}] [{}] product(s)", categoryId, products.size()); return products; }
ProductDao extends AbstractBaseDao<Product, String> implements ProductMapper { public List<Product> getProductListByCategory(final String categoryId) { checkNotNull(emptyToNull(categoryId), "Argument[categoryId] must not be empty or null"); List<Product> products = new ArrayList<>(); DBObject query = new BasicDBObject("category_id", categoryId); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("product_id", 1))) { while (cursor.hasNext()) { DBObject productObj = cursor.next(); products.add(Product.fromDBObject(productObj)); } } logger.info("Found for category id [{}] [{}] product(s)", categoryId, products.size()); return products; } }
ProductDao extends AbstractBaseDao<Product, String> implements ProductMapper { public List<Product> getProductListByCategory(final String categoryId) { checkNotNull(emptyToNull(categoryId), "Argument[categoryId] must not be empty or null"); List<Product> products = new ArrayList<>(); DBObject query = new BasicDBObject("category_id", categoryId); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("product_id", 1))) { while (cursor.hasNext()) { DBObject productObj = cursor.next(); products.add(Product.fromDBObject(productObj)); } } logger.info("Found for category id [{}] [{}] product(s)", categoryId, products.size()); return products; } ProductDao(final String collectionName); }
ProductDao extends AbstractBaseDao<Product, String> implements ProductMapper { public List<Product> getProductListByCategory(final String categoryId) { checkNotNull(emptyToNull(categoryId), "Argument[categoryId] must not be empty or null"); List<Product> products = new ArrayList<>(); DBObject query = new BasicDBObject("category_id", categoryId); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("product_id", 1))) { while (cursor.hasNext()) { DBObject productObj = cursor.next(); products.add(Product.fromDBObject(productObj)); } } logger.info("Found for category id [{}] [{}] product(s)", categoryId, products.size()); return products; } ProductDao(final String collectionName); List<Product> getProductListByCategory(final String categoryId); Product getProduct(final String productId); List<Product> searchProductList(final String keyword); }
ProductDao extends AbstractBaseDao<Product, String> implements ProductMapper { public List<Product> getProductListByCategory(final String categoryId) { checkNotNull(emptyToNull(categoryId), "Argument[categoryId] must not be empty or null"); List<Product> products = new ArrayList<>(); DBObject query = new BasicDBObject("category_id", categoryId); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("product_id", 1))) { while (cursor.hasNext()) { DBObject productObj = cursor.next(); products.add(Product.fromDBObject(productObj)); } } logger.info("Found for category id [{}] [{}] product(s)", categoryId, products.size()); return products; } ProductDao(final String collectionName); List<Product> getProductListByCategory(final String categoryId); Product getProduct(final String productId); List<Product> searchProductList(final String keyword);  }