@Test public void getOrderByUsername_shouldFindEmptyListForNonExistingUsername() { List<Order> orders = orderDao.getOrdersByUsername("NON_EXISTING_USERNAME"); assertThat(orders.size(), is(0)); }
public List<Order> getOrdersByUsername(@Nonnull final String username) { checkNotNull(emptyToNull(username), "Argument[username] must not be empty or null"); List<Order> orders = new ArrayList<>(); DBObject query = new BasicDBObject("username", username); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("order_id", 1))) { while (cursor.hasNext()) { DBObject orderObj = cursor.next(); orders.add(Order.fromDBObject(orderObj)); } } logger.info("Found for username [{}] [{}] order(s)", username, orders.size()); return orders; }
OrderDao extends AbstractBaseDao<Order, Integer> implements OrderMapper, LineItemMapper { public List<Order> getOrdersByUsername(@Nonnull final String username) { checkNotNull(emptyToNull(username), "Argument[username] must not be empty or null"); List<Order> orders = new ArrayList<>(); DBObject query = new BasicDBObject("username", username); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("order_id", 1))) { while (cursor.hasNext()) { DBObject orderObj = cursor.next(); orders.add(Order.fromDBObject(orderObj)); } } logger.info("Found for username [{}] [{}] order(s)", username, orders.size()); return orders; } }
OrderDao extends AbstractBaseDao<Order, Integer> implements OrderMapper, LineItemMapper { public List<Order> getOrdersByUsername(@Nonnull final String username) { checkNotNull(emptyToNull(username), "Argument[username] must not be empty or null"); List<Order> orders = new ArrayList<>(); DBObject query = new BasicDBObject("username", username); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("order_id", 1))) { while (cursor.hasNext()) { DBObject orderObj = cursor.next(); orders.add(Order.fromDBObject(orderObj)); } } logger.info("Found for username [{}] [{}] order(s)", username, orders.size()); return orders; } OrderDao(@Nonnull final String collectionName); }
OrderDao extends AbstractBaseDao<Order, Integer> implements OrderMapper, LineItemMapper { public List<Order> getOrdersByUsername(@Nonnull final String username) { checkNotNull(emptyToNull(username), "Argument[username] must not be empty or null"); List<Order> orders = new ArrayList<>(); DBObject query = new BasicDBObject("username", username); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("order_id", 1))) { while (cursor.hasNext()) { DBObject orderObj = cursor.next(); orders.add(Order.fromDBObject(orderObj)); } } logger.info("Found for username [{}] [{}] order(s)", username, orders.size()); return orders; } OrderDao(@Nonnull final String collectionName); List<LineItem> getLineItemsByOrderId(final int orderId); void insertLineItem(@Nonnull final LineItem lineItem); List<Order> getOrdersByUsername(@Nonnull final String username); Order getOrder(final int orderId); void insertOrder(@Nonnull final Order order); void insertOrderStatus(@Nonnull final Order order); }
OrderDao extends AbstractBaseDao<Order, Integer> implements OrderMapper, LineItemMapper { public List<Order> getOrdersByUsername(@Nonnull final String username) { checkNotNull(emptyToNull(username), "Argument[username] must not be empty or null"); List<Order> orders = new ArrayList<>(); DBObject query = new BasicDBObject("username", username); try (DBCursor cursor = collection.find(query).sort(new BasicDBObject("order_id", 1))) { while (cursor.hasNext()) { DBObject orderObj = cursor.next(); orders.add(Order.fromDBObject(orderObj)); } } logger.info("Found for username [{}] [{}] order(s)", username, orders.size()); return orders; } OrderDao(@Nonnull final String collectionName); List<LineItem> getLineItemsByOrderId(final int orderId); void insertLineItem(@Nonnull final LineItem lineItem); List<Order> getOrdersByUsername(@Nonnull final String username); Order getOrder(final int orderId); void insertOrder(@Nonnull final Order order); void insertOrderStatus(@Nonnull final Order order);  }