orderMngmntWebapp\src\orderMngr\domain\order\OrderFactory.java
 
/* * Copyright (c) 2006 Rogério Liesenfeld * This file is subject to the terms of the MIT license (see LICENSE.txt). */
/*...*/
5 
package orderMngr.domain.order;
 
 
import java.math.*; import java.util.*;
import ...
 
101
public final class OrderFactory
    11 
    {
    12 
       // Just for simplicity. In a real application, a more robust mechanism would be used for
    13 
       // generating sequential order numbers, such as a database sequence or identity column.
    141
       private static int nextOrderNo = 1;
       
      16 
         public Order createOrder(String customerId, List<OrderItem> items)
      17 
            throws MissingOrderItems, InvalidOrderItem, DuplicateOrderItem
      18 
         {
      1 Path coverage: 1/2 A: 0 B: 1
      191
            if (items.isEmpty()) {
      1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32
      200
               throw new MissingOrderItems();
        21 
              }
         
        231
              validateOrderItems(items);
        1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32
         
        251
              Order order = new Order(nextOrderNo++, customerId);
        1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32
        261
              order.getItems().addAll(items);
        1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32
         
        281
              new OrderRepository().create(order);
        1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32
         
        301
              return order;
        1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32
        31 
           }
         
        33 
           private void validateOrderItems(List<OrderItem> items) throws InvalidOrderItem, DuplicateOrderItem
        34 
           {
        1 Path coverage: 1/6 A: 0 B: 0 C: 0 D: 0 E: 0 F: 1
        351
              for (OrderItem item : items) {
        1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32
        1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32x2
        362
                 if (item.getQuantity() <= 0 || item.getUnitPrice().compareTo(BigDecimal.ZERO) <= 0) {
        1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32x2
        1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32x2
        370
                    throw new InvalidOrderItem("Quantity=" + item.getQuantity() + ", Unit Price=" + item.getUnitPrice());
          38 
                   }
          392
                }
          1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32x2
           
          411
                if (new HashSet<>(items).size() < items.size()) {
          1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32
          420
                   throw new DuplicateOrderItem();
            43 
                  }
            441
               }
            1. orderMngr.domain.order.OrderFactoryTest#createOrder: 32
            45 
            }