Search in sources :

Example 1 with ProjectItem

use of org.estatio.module.capex.dom.project.ProjectItem in project estatio by estatio.

the class ProjectItem_OrderedAmount_Test method orderedAmount_works.

@Test
public void orderedAmount_works() throws Exception {
    // given
    BigDecimal expectedTotalNetAmountOnItems = new BigDecimal("100.00");
    BigDecimal netAmountOnItem1 = new BigDecimal("55.00");
    BigDecimal netAmountOnItem2 = new BigDecimal("45.00");
    BigDecimal netAmountOnItem3 = null;
    ProjectItem projectItem = new ProjectItem();
    ProjectItem_OrderedAmount mixin = new ProjectItem_OrderedAmount(projectItem);
    mixin.orderItemRepository = mockOrderItemRepository;
    OrderItem orderItem1 = new OrderItem();
    orderItem1.setNetAmount(netAmountOnItem1);
    OrderItem orderItem2 = new OrderItem();
    orderItem2.setNetAmount(netAmountOnItem2);
    OrderItem orderItem3 = new OrderItem();
    orderItem3.setNetAmount(netAmountOnItem3);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockOrderItemRepository).findByProjectAndCharge(null, null);
            will(returnValue(Arrays.asList(orderItem1, orderItem2, orderItem3)));
        }
    });
    // when
    BigDecimal orderedAmount = mixin.orderedAmount();
    // then
    Assertions.assertThat(orderedAmount).isEqualTo(expectedTotalNetAmountOnItems);
}
Also used : Expectations(org.jmock.Expectations) ProjectItem(org.estatio.module.capex.dom.project.ProjectItem) OrderItem(org.estatio.module.capex.dom.order.OrderItem) ProjectItem_OrderedAmount(org.estatio.module.capex.dom.order.contributions.ProjectItem_OrderedAmount) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with ProjectItem

use of org.estatio.module.capex.dom.project.ProjectItem in project estatio by estatio.

the class ProjectItem_InvoicedAmount_Test method invoicedAmount_works.

@Test
public void invoicedAmount_works() throws Exception {
    // given
    BigDecimal expectedTotalInvoicedNetAmountOnItems = new BigDecimal("100.00");
    BigDecimal netAmountOnItem1 = new BigDecimal("55.00");
    BigDecimal netAmountOnItem2 = new BigDecimal("45.00");
    BigDecimal netAmountOnItem3_discarded = new BigDecimal("12345.67");
    ProjectItem projectItem = new ProjectItem();
    ProjectItem_InvoicedAmount mixin = new ProjectItem_InvoicedAmount(projectItem);
    mixin.incomingInvoiceItemRepository = mockIncomingInvoiceItemRepository;
    IncomingInvoiceItem item1 = new IncomingInvoiceItem();
    item1.setInvoice(newIncomingInvoice());
    item1.setNetAmount(netAmountOnItem1);
    IncomingInvoiceItem item2 = new IncomingInvoiceItem();
    item2.setInvoice(newIncomingInvoice());
    item2.setNetAmount(netAmountOnItem2);
    IncomingInvoiceItem item3_discarded = new IncomingInvoiceItem() {

        @Override
        public boolean isDiscarded() {
            return true;
        }
    };
    item3_discarded.setInvoice(newIncomingInvoice());
    item3_discarded.setNetAmount(netAmountOnItem3_discarded);
    // expect
    context.checking(new Expectations() {

        {
            oneOf(mockIncomingInvoiceItemRepository).findByProjectAndCharge(null, null);
            will(returnValue(Arrays.asList(item1, item2, item3_discarded)));
        }
    });
    // when
    BigDecimal orderedAmount = mixin.invoicedAmount();
    // then
    Assertions.assertThat(orderedAmount).isEqualTo(expectedTotalInvoicedNetAmountOnItems);
}
Also used : Expectations(org.jmock.Expectations) ProjectItem_InvoicedAmount(org.estatio.module.capex.dom.invoice.contributions.ProjectItem_InvoicedAmount) ProjectItem(org.estatio.module.capex.dom.project.ProjectItem) IncomingInvoiceItem(org.estatio.module.capex.dom.invoice.IncomingInvoiceItem) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with ProjectItem

use of org.estatio.module.capex.dom.project.ProjectItem in project estatio by estatio.

the class OrderItemRepository_Test method orderItemsWithoutProjectItem_works.

@Test
public void orderItemsWithoutProjectItem_works() throws Exception {
    // given
    Project project = new Project();
    ProjectItem item1 = new ProjectItem();
    Charge chargeOnProjectItem = new Charge();
    item1.setCharge(chargeOnProjectItem);
    project.getItems().add(item1);
    Charge chargeNOTOnProjectItem = new Charge();
    OrderItem orderItemToBeFound = new OrderItem();
    orderItemToBeFound.setCharge(chargeNOTOnProjectItem);
    OrderItem orderItemNOTToBeFound = new OrderItem();
    orderItemNOTToBeFound.setCharge(chargeOnProjectItem);
    OrderItemRepository orderItemRepository = new OrderItemRepository() {

        @Override
        public List<OrderItem> findByProject(final Project project) {
            return Arrays.asList(orderItemNOTToBeFound, orderItemToBeFound);
        }
    };
    // when
    List<OrderItem> result = orderItemRepository.orderItemsNotOnProjectItem(project);
    // then
    Assertions.assertThat(result.size()).isEqualTo(1);
    Assertions.assertThat(result.get(0)).isEqualTo(orderItemToBeFound);
    Assertions.assertThat(result.get(0).getCharge()).isEqualTo(chargeNOTOnProjectItem);
}
Also used : Project(org.estatio.module.capex.dom.project.Project) ProjectItem(org.estatio.module.capex.dom.project.ProjectItem) Charge(org.estatio.module.charge.dom.Charge) Test(org.junit.Test)

Aggregations

ProjectItem (org.estatio.module.capex.dom.project.ProjectItem)3 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2 Expectations (org.jmock.Expectations)2 IncomingInvoiceItem (org.estatio.module.capex.dom.invoice.IncomingInvoiceItem)1 ProjectItem_InvoicedAmount (org.estatio.module.capex.dom.invoice.contributions.ProjectItem_InvoicedAmount)1 OrderItem (org.estatio.module.capex.dom.order.OrderItem)1 ProjectItem_OrderedAmount (org.estatio.module.capex.dom.order.contributions.ProjectItem_OrderedAmount)1 Project (org.estatio.module.capex.dom.project.Project)1 Charge (org.estatio.module.charge.dom.Charge)1