Coverage Report - org.paneris.jammyjoes.shopping.JammyJoesShoppingTrolleyItem
 
Classes in this File Line Coverage Branch Coverage Complexity
JammyJoesShoppingTrolleyItem
0%
0/36
0%
0/8
1.7
 
 1  
 package org.paneris.jammyjoes.shopping;
 2  
 
 3  
 import org.melati.Melati;
 4  
 import org.paneris.jammyjoes.model.JammyjoesDatabase;
 5  
 import org.paneris.jammyjoes.model.Product;
 6  
 import org.paneris.jammyjoes.model.ShopOrder;
 7  
 import org.paneris.jammyjoes.model.ShopOrderItem;
 8  
 
 9  0
 public class JammyJoesShoppingTrolleyItem extends ShoppingTrolleyItem {
 10  
 
 11  
   private Product product;
 12  
   private JammyJoesShoppingTrolley jammyjoesShoppingTrolley;
 13  
 
 14  
   public void initialise(
 15  
     ShoppingTrolley trolley,
 16  
     Melati melati,
 17  
     Integer id,
 18  
     String description,
 19  
     Double price) {
 20  0
     super.initialise(trolley, melati, id, description, price);
 21  0
     jammyjoesShoppingTrolley = (JammyJoesShoppingTrolley) trolley;
 22  0
   }
 23  
 
 24  
   /* load in information about this product given an id.  
 25  
      perhaps this id represents a poem troid?
 26  
   */
 27  
   protected void load(Integer id) {
 28  0
     JammyjoesDatabase db = (JammyjoesDatabase) melati.getDatabase();
 29  0
     product = db.getProductTable().getProductObject(id);
 30  0
     description = product.getName();
 31  0
     price = product.getRetailpriceincvat().doubleValue();
 32  0
   }
 33  
 
 34  
   protected void save(JammyjoesDatabase db, ShopOrder order) {
 35  0
     ShopOrderItem item = (ShopOrderItem) db.getShopOrderItemTable().newPersistent();
 36  0
     item.setUser(order.getUser());
 37  0
     item.setOrder(order);
 38  0
     item.setProduct(product);
 39  0
     item.setQuantity(getQuantity());
 40  0
     item.setAmount(jammyjoesShoppingTrolley.convertFromUK(price * quantity.intValue()));
 41  0
     item.setAmountUK(price * quantity.intValue());
 42  0
     db.getShopOrderItemTable().create(item);
 43  0
   }
 44  
 
 45  
   /* work out the cost of delivery
 46  
   */
 47  
   public double getDeliveryValue() {
 48  0
     return 0;
 49  
   }
 50  
 
 51  
   public String getWeightDisplay() {
 52  0
     double weight = getMass();
 53  0
     if (weight < 1000)
 54  0
       return weight + "g";
 55  0
     return weight / 1000 + "Kg";
 56  
   }
 57  
 
 58  
   public double getWeight() {
 59  0
     return getMass() * getQuantity().intValue();
 60  
   }
 61  
 
 62  
   public double getMass() {
 63  0
     double weight = 0;
 64  0
     if (product.getWeight() != null)
 65  0
       weight = product.getWeight().doubleValue();
 66  0
     return weight;
 67  
   }
 68  
 
 69  
   public Product getProduct() {
 70  0
     return product;
 71  
   }
 72  
 
 73  
   public Integer getStocklevel() {
 74  0
     Integer level = getProduct().getStocklevel();
 75  0
     if (level == null) {
 76  0
       return new Integer(0);
 77  
     } else {
 78  0
       return getProduct().getStocklevel();
 79  
     }
 80  
   }
 81  
 
 82  
   public boolean enoughStock() {
 83  0
     if (quantity.intValue() > getStocklevel().intValue())
 84  0
       return false;
 85  0
     return true;
 86  
   }
 87  
 
 88  
 }