@Test public void testCriteriaMet_itemsInList() { // setup Transaction transaction = TransactionTestUtils.createTransaction( toothBrush, milkCarton, toothBrush, chips, toothBrush, toothBrush); Set<Integer> alreadyClaimedProducts = Sets.newHashSet(1, 3); // test boolean result = promotionElement.criteriaMet(transaction, alreadyClaimedProducts); // verify assertThat(result, is(false)); assertThat(alreadyClaimedProducts, IsIterableContainingInAnyOrder.containsInAnyOrder(1, 3)); }
@Test public void testApplyPromotion_noDiscountsApplied() { // setup Transaction transaction = TransactionTestUtils.createTransaction( toothBrush, milkCarton, toothBrush, chips, toothBrush, toothBrush, toothBrush); // test promotionElement.applyPromotion(transaction); // verify List<TransactionItem> brushes = Lists.newArrayList(transaction.getItemMap().get(toothBrush)); assertDiscountApplied("brush 1", brushes.get(0), true, noDiscount); assertDiscountApplied("brush 2", brushes.get(1), true, noDiscount); assertDiscountApplied("brush 3", brushes.get(2), true, freeDiscount); assertDiscountApplied("brush 4", brushes.get(3), false, null); assertDiscountApplied("brush 5", brushes.get(4), false, null); }
@Test public void testCriteriaMet_false() { testCriteriaMet("one element", TransactionTestUtils.createTransaction(toothBrush), false); testCriteriaMet( "two element", TransactionTestUtils.createTransaction(toothBrush, toothBrush), false); testCriteriaMet( "three element", TransactionTestUtils.createTransaction(toothBrush, toothBrush, toothBrush), true, 1, 2, 3); testCriteriaMet( "two brush, one milk", TransactionTestUtils.createTransaction(toothBrush, toothBrush, milkCarton), false); testCriteriaMet( "three brush, one milk", TransactionTestUtils.createTransaction(toothBrush, milkCarton, toothBrush, toothBrush), true, 1, 3, 4); testCriteriaMet( "four brush, one milk", TransactionTestUtils.createTransaction( toothBrush, milkCarton, toothBrush, chips, toothBrush, toothBrush), true, 1, 3, 5); }