@Test(expected = HotelInputException.class) public void testDoAdapterWithEmptyInput() throws Exception { hotelInputReader.clean(); CustomerAdapter adapter = new CustomerAdapter(hotelInputReader); adapter.doAdapter(); }
private Customer getCustomerByFile(String file) throws IOException, HotelInputException { String input = super.loadInputFromFile(file); hotelInputReader.read(input); CustomerAdapter adapter = new CustomerAdapter(hotelInputReader); adapter.doAdapter(); return adapter.getCustomer(); }
/** * Map an Order object to a Mongo Document object. * * @param o Order * @return A Document object with all the information of the Order. */ public static final Document toDocument(Order o) { Document c = CustomerAdapter.toDocument(o.getCustomer()); c.remove("_id"); List<Document> itemsDoc = new ArrayList<>(o.getItems().size()); Document iDoc = null; for (Item i : o.getItems()) { iDoc = ItemAdapter.toDocument(i); iDoc.remove("_id"); itemsDoc.add(iDoc); } Document d = new Document("total", o.getTotal()) .append("date", o.getDate()) .append("status", o.getStatus().getName()) .append("customer", c) .append("items", itemsDoc); if (o.getId() != null) { d.append("_id", new ObjectId(o.getId())); } return d; }
/** * Map a Mongo Document object to an Order object. * * @param d Document * @return An Order object with all the information of the Document object. */ public static final Order toOrder(Document d) { ObjectId id = d.get("_id", ObjectId.class); Document c = d.get("customer", Document.class); @SuppressWarnings("unchecked") List<Document> itemsDoc = (List<Document>) d.get("items"); List<Item> items = new ArrayList<>(itemsDoc.size()); for (Document itemDoc : itemsDoc) { items.add(ItemAdapter.toItem(itemDoc)); } Order o = new Order( id == null ? "" : id.toString(), d.getDouble("total"), d.getDate("date"), OrderStatus.findOrderStatus(d.getString("status")), CustomerAdapter.toCustomer(c), items); return o; }