コード例 #1
0
  /** test of iva method of class CalculateIva */
  @Test
  public void testCalculateIva() {
    CalculateIva calculateIva = Mockito.mock(CalculateIva.class);
    Purchase p = BillingCalculator.calculateTotalPurchase(customer, "EL-003,FU-001");

    when(CalculateIva.iva(p.getCode())).thenReturn(new BigDecimal(Math.random() * 0.05));
  }
コード例 #2
0
 /** test for all methods of customer points system of class Customer */
 @Test
 public void addPoints() {
   int points;
   String productsFlatFile = "EL-002,FU-007,FU-008";
   Purchase result = null;
   result = BillingCalculator.calculateTotalPurchase(customer, productsFlatFile);
   Customer client = Mockito.mock(Customer.class);
   when(client.calculatePoints())
       .thenReturn(points = (result.getTotalPrice().divide(new BigDecimal(1000))).intValue());
   when(client.addPoints()).thenReturn(customer.getPoints().add(new BigDecimal(points)));
   customer.calculatePoints();
   customer.addPoints();
 }
コード例 #3
0
 @Test
 public void calculateDiscountPoints() {
   String productsFlatFile = "EL-002,FU-007,FU-008";
   Purchase result = null;
   result = BillingCalculator.calculateTotalPurchase(customer, productsFlatFile);
   Customer client = Mockito.mock(Customer.class);
   client = result.getCustomer();
   when(client.calculateDiscountPoints())
       .thenReturn(result.getTotalPrice().multiply(new BigDecimal(Math.random() * 0.02)));
   when(client.discountPoints()).thenReturn(true);
   if ((client.getPoints().intValue()) > 1000) {
     client.discountPoints();
   }
 }
コード例 #4
0
 /** Test of calculateTotalPurchase method, of class BillingCalculator. */
 @Test
 public void testCalculateTotalPurchase() {
   String productsFlatFile = "EL-002,FU-007,FU-008";
   Purchase result = null;
   BigDecimal discounts = BigDecimal.ZERO;
   BigDecimal price = BigDecimal.ZERO;
   result = BillingCalculator.calculateTotalPurchase(customer, productsFlatFile);
   for (String code : productsFlatFile.split(",")) {
     Product p = Product.buildProduct(code);
     if (code.startsWith("EL")) {
       // true values
       price = price.add(p.getPrice());
       // just discounts
       discounts = discounts.add(p.getPrice().multiply(new BigDecimal(0.05)));
     } else if (code.startsWith("FU")) {
       price = price.add(p.getPrice());
       discounts = discounts.add(p.getPrice().multiply(new BigDecimal(0.1)));
     }
   }
   assertEquals(result.getTotalPrice().add(discounts), price);
 }