I have a class with a method that Bill generates. I have a DateUtil component to create the date
public Bill generateBill(List<ProvidedItem> providedItems) {
Bill bill = new Bill();
Date date = dateUtil.now();
bill.setStartDate(date);
bill.setEndDate(dateUtil.plusDays(date, ConstantValues.DEFAULT_DURATION_BILL_DAYS));
return billDao.saveOrUpdate(bill);
}
I have test for method generate Bill
@Test
public void generateBill_shouldCorrectlyGenerateBill() {
Bill actualBill = billService.generateBill(actualProvidedItems);
Date date = dateUtil.now();
Bill expectedBill = BillMother.createTestInstanceWithAmount(sumProvidedItems, date, dateUtil.plusDays(date,
ConstantValues.DEFAULT_DURATION_BILL_DAYS));
Assert.assertThat(actualBill, is(expectedBill));
}
BillMother:
public static Bill createTestInstanceWithAmount(BigDecimal totalAmount, Date startDate, Date endDate) {
Bill bill = new Bill();
bill.setStartDate(startDate);
bill.setEndDate(endDate);
bill.setTotalAmount(totalAmount);
return bill;
}
I have different objects because the date is called at another time.
I can't skip these dates in the Equals method because they are one of the most important parts of this object
How to make it work properly in this situation?
Aucun commentaire:
Enregistrer un commentaire