Exemple #1
0
  @Test
  public void testInsertInstitucionNoExiste() {
    System.out.println("insertInstitucionExiste");
    Plantel plantel = null;
    PlantelDAO instance = new PlantelDAO();

    plantel = new Plantel();
    CInstitucion institucion = new CInstitucion();
    institucion.setIdCInstitucion((int) (Math.random() * 100));
    institucion.setNombre("No existente " + (int) (Math.random() * 100));
    institucion.setModificadoPor("system");
    institucion.setCreacion(new Date(System.currentTimeMillis()));
    institucion.setUltimaModif(new Date(System.currentTimeMillis()));

    plantel.setNombre("dsadsa 2" + (int) (Math.random() * 1000));
    plantel.setModificadoPor("system");
    plantel.setCreacion(new Date(System.currentTimeMillis()));
    plantel.setUltimaModif(new Date(System.currentTimeMillis()));
    //        plantel.setInstitucion(institucion);
    CInstitucionDAO cInstitucionDAO = new CInstitucionDAO();
    cInstitucionDAO.insert(institucion);

    int expResult = 1;
    // Insertar
    int result = instance.insert(plantel);
    assertEquals(expResult, result);
  }
  /** 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));
  }
  // Returns are randomly generated email id, part before the domain name
  private String shuffleEmail(String email) {

    String shuffledString = "";

    while (email.length() != 0) {
      int index = (int) Math.floor(Math.random() * email.length());
      char c = email.charAt(index);
      email = email.substring(0, index) + email.substring(index + 1);
      shuffledString += c;
    }

    return shuffledString;
  }
 @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();
   }
 }
  public static int randomNumber() {

    return (int) (Math.random() * 10) + 0;
  }
 private String getUniqueId() {
   return Long.toHexString(Double.doubleToLongBits(Math.random()));
 }