@Test public void shouldComputeTotalExpenseAndTotalRevenueForAllMonthlyCashFlows() { when(validationContext.getMessageContext()).thenReturn(messageContext); when(messageContext.hasErrorMessages()).thenReturn(false); MonthlyCashFlowDetail cashFlowDetail1 = new MonthlyCashFlowDetail(new DateTime(), new BigDecimal(12), new BigDecimal(12), "notes"); MonthlyCashFlowDetail cashFlowDetail2 = new MonthlyCashFlowDetail(new DateTime(), new BigDecimal(23), new BigDecimal(34), "notes"); MonthlyCashFlowDetail cashFlowDetail3 = new MonthlyCashFlowDetail(new DateTime(), new BigDecimal(20), new BigDecimal(30), "notes"); CashFlowDetail cashFlowDetail = new CashFlowDetail(asList(cashFlowDetail1, cashFlowDetail2, cashFlowDetail3)); CashFlowForm cashFlowForm = new CashFlowForm(cashFlowDetail, false, new BigDecimal(1000), 10d); cashFlowValidator.validateCaptureCashFlow(cashFlowForm, validationContext); assertThat(cashFlowForm.getTotalExpenses().doubleValue(), is(76d)); assertThat(cashFlowForm.getTotalRevenues().doubleValue(), is(55d)); verify(messageContext, times(2)).hasErrorMessages(); verify(validationContext).getMessageContext(); }
public void validateCaptureCashFlow(CashFlowForm cashFlow, ValidationContext context) { MessageContext messageContext = context.getMessageContext(); for (MonthlyCashFlowForm monthlyCashFlowForm : cashFlow.getMonthlyCashFlows()) { validateExpense(messageContext, monthlyCashFlowForm); validateRevenue(messageContext, monthlyCashFlowForm); validateNotes(messageContext, monthlyCashFlowForm); } validateCumulativeCashFlow(cashFlow, messageContext); validateTotalCapitalAndLiability(cashFlow, messageContext); validateIndebtednessRatio(cashFlow, messageContext); setTotalsOnCashFlowForm(cashFlow, messageContext); }
CashFlowValidator { public void validateCaptureCashFlow(CashFlowForm cashFlow, ValidationContext context) { MessageContext messageContext = context.getMessageContext(); for (MonthlyCashFlowForm monthlyCashFlowForm : cashFlow.getMonthlyCashFlows()) { validateExpense(messageContext, monthlyCashFlowForm); validateRevenue(messageContext, monthlyCashFlowForm); validateNotes(messageContext, monthlyCashFlowForm); } validateCumulativeCashFlow(cashFlow, messageContext); validateTotalCapitalAndLiability(cashFlow, messageContext); validateIndebtednessRatio(cashFlow, messageContext); setTotalsOnCashFlowForm(cashFlow, messageContext); } }
CashFlowValidator { public void validateCaptureCashFlow(CashFlowForm cashFlow, ValidationContext context) { MessageContext messageContext = context.getMessageContext(); for (MonthlyCashFlowForm monthlyCashFlowForm : cashFlow.getMonthlyCashFlows()) { validateExpense(messageContext, monthlyCashFlowForm); validateRevenue(messageContext, monthlyCashFlowForm); validateNotes(messageContext, monthlyCashFlowForm); } validateCumulativeCashFlow(cashFlow, messageContext); validateTotalCapitalAndLiability(cashFlow, messageContext); validateIndebtednessRatio(cashFlow, messageContext); setTotalsOnCashFlowForm(cashFlow, messageContext); }  }
CashFlowValidator { public void validateCaptureCashFlow(CashFlowForm cashFlow, ValidationContext context) { MessageContext messageContext = context.getMessageContext(); for (MonthlyCashFlowForm monthlyCashFlowForm : cashFlow.getMonthlyCashFlows()) { validateExpense(messageContext, monthlyCashFlowForm); validateRevenue(messageContext, monthlyCashFlowForm); validateNotes(messageContext, monthlyCashFlowForm); } validateCumulativeCashFlow(cashFlow, messageContext); validateTotalCapitalAndLiability(cashFlow, messageContext); validateIndebtednessRatio(cashFlow, messageContext); setTotalsOnCashFlowForm(cashFlow, messageContext); }  void validateCaptureCashFlow(CashFlowForm cashFlow, ValidationContext context); }
CashFlowValidator { public void validateCaptureCashFlow(CashFlowForm cashFlow, ValidationContext context) { MessageContext messageContext = context.getMessageContext(); for (MonthlyCashFlowForm monthlyCashFlowForm : cashFlow.getMonthlyCashFlows()) { validateExpense(messageContext, monthlyCashFlowForm); validateRevenue(messageContext, monthlyCashFlowForm); validateNotes(messageContext, monthlyCashFlowForm); } validateCumulativeCashFlow(cashFlow, messageContext); validateTotalCapitalAndLiability(cashFlow, messageContext); validateIndebtednessRatio(cashFlow, messageContext); setTotalsOnCashFlowForm(cashFlow, messageContext); }  void validateCaptureCashFlow(CashFlowForm cashFlow, ValidationContext context);  }