@Before
  public void setup() {
    insuranceCart2QuoteListingPopulator = new InsuranceCart2QuoteListingPopulator();
    MockitoAnnotations.initMocks(this);

    quoteListingData = new InsuranceQuoteListingData();
    cartData = new CartData();
    final PriceData priceData = new PriceData();
    priceData.setFormattedValue(testFormattedValue);
    cartData.setTotalPrice(priceData);
    cartData.setCode(testCartCode);

    final List<OrderEntryData> entries = new ArrayList<>();
    final OrderEntryData orderEntryData = new OrderEntryData();
    final ProductData productData = new ProductData();
    productData.setName(testProductName);
    productData.setImages(imageDataList);
    orderEntryData.setProduct(productData);
    entries.add(orderEntryData);
    cartData.setEntries(entries);
    final SubscriptionPricePlanData pricePlanData = new SubscriptionPricePlanData();
    productData.setPrice(pricePlanData);

    quoteData = new InsuranceQuoteData();
    cartData.setInsuranceQuote(quoteData);
    quoteData.setFormattedExpiryDate(testQuoteFormattedExpiryDate);
  }
 @Test
 public void testTotal() throws Exception {
   final ExtendedModelMap model = new ExtendedModelMap();
   miniCartComponentModel.setTotalDisplay(CartTotalDisplayType.TOTAL);
   given(cmsComponentService.getAbstractCMSComponent(TEST_COMPONENT_UID))
       .willReturn(miniCartComponentModel);
   miniCartComponentController.handleGet(request, response, model);
   final PriceData priceData = (PriceData) model.get(MiniCartComponentController.TOTAL_PRICE);
   Assert.assertEquals(TOTAL_VALUE, priceData.getValue());
 }
 @Test
 public void testTotalWithoutDelivery() throws Exception {
   final ExtendedModelMap model = new ExtendedModelMap();
   miniCartComponentModel.setTotalDisplay(CartTotalDisplayType.TOTAL_WITHOUT_DELIVERY);
   given(cmsComponentService.getSimpleCMSComponent(TEST_COMPONENT_UID))
       .willReturn(miniCartComponentModel);
   miniCartComponentController.handleGet(request, response, model);
   final PriceData priceData =
       (PriceData) model.get(MiniCartComponentController.TOTAL_NO_DELIVERY);
   Assert.assertEquals(TOTAL_VALUE.subtract(DELIVERY_VALUE), priceData.getValue());
 }
  @Test
  public void testPopulate() {
    // create search result values
    final SearchResultValueData searchResultValueData = new SearchResultValueData();
    final Map<String, Object> searchValueMap = new HashMap<String, Object>();
    searchValueMap.put(BillingPlanModel.BILLINGFREQUENCY, "monthly");
    searchValueMap.put(ProductModel.SOLDINDIVIDUALLY, Boolean.TRUE);
    searchValueMap.put(SubscriptionTermModel.TERMOFSERVICERENEWAL, "yearly");
    searchValueMap.put("termLimit", "18 months");
    searchValueMap.put("lowestBundlePriceValue", Double.valueOf(1.99));
    searchResultValueData.setValues(searchValueMap);

    final CurrencyModel currency = new CurrencyModel();
    currency.setIsocode("USD");
    final PriceData priceData = new PriceData();
    priceData.setValue(BigDecimal.valueOf(1.99));
    priceData.setCurrencyIso(currency.getIsocode());
    given(commonI18NService.getCurrentCurrency()).willReturn(currency);
    given(
            priceDataFactory.create(
                PriceDataType.BUY, BigDecimal.valueOf(1.99), currency.getIsocode()))
        .willReturn(priceData);

    final ProductData productData = new ProductData();
    searchProductTelcoPopulator.populate(searchResultValueData, productData);

    assertNotNull("", productData.getSubscriptionTerm());
    assertNotNull("", productData.getSubscriptionTerm().getBillingPlan());
    assertNotNull("", productData.getSubscriptionTerm().getBillingPlan().getBillingTime());
    assertEquals(
        "",
        searchProductTelcoPopulator.getValue(searchResultValueData, "billingTime"),
        productData.getSubscriptionTerm().getBillingPlan().getBillingTime().getName());
    assertEquals(
        "",
        searchProductTelcoPopulator.getValue(searchResultValueData, ProductModel.SOLDINDIVIDUALLY),
        Boolean.valueOf(productData.isSoldIndividually()));
    assertNotNull("", productData.getSubscriptionTerm().getTermOfServiceFrequency());
    assertEquals(
        "",
        searchProductTelcoPopulator.getValue(searchResultValueData, "termLimit"),
        productData.getSubscriptionTerm().getTermOfServiceFrequency().getName());
    assertNotNull("", productData.getLowestBundlePrice());
    assertEquals(
        "",
        BigDecimal.valueOf(
            ((Double)
                    searchProductTelcoPopulator.getValue(
                        searchResultValueData, "lowestBundlePriceValue"))
                .doubleValue()),
        productData.getLowestBundlePrice().getValue());
  }
  protected void calculateRefundAmount() {
    BigDecimal refundAmountValue = BigDecimal.ZERO;
    PriceData totalPrice = null;
    for (final ConsignmentEntryData consignmentEntry : getConsignment().getEntries()) {
      totalPrice = consignmentEntry.getOrderEntry().getTotalPrice();
      refundAmountValue = refundAmountValue.add(totalPrice.getValue());
    }

    if (totalPrice != null) {
      refundAmount =
          getPriceDataFactory()
              .create(totalPrice.getPriceType(), refundAmountValue, totalPrice.getCurrencyIso());
    }
  }
  @Override
  public PriceData create(
      final PriceDataType priceType, final BigDecimal value, final CurrencyModel currency) {
    Assert.notNull(priceType, "Parameter priceType cannot be null.");
    Assert.notNull(value, "Parameter value cannot be null.");
    Assert.notNull(currency, "Parameter currency cannot be null.");

    final PriceData priceData = createPriceData();

    priceData.setPriceType(priceType);
    priceData.setValue(value);
    priceData.setCurrencyIso(currency.getIsocode());
    priceData.setFormattedValue(formatPrice(value, currency));

    return priceData;
  }
  @Before
  public void setUp() throws CMSItemNotFoundException {
    MockitoAnnotations.initMocks(this);
    miniCartComponentController = new MiniCartComponentController();
    miniCartComponentController.setCmsComponentService(cmsComponentService);

    miniCartComponentModel = new MiniCartComponentModel();

    final PriceData subTotal = new PriceData();
    subTotal.setValue(SUB_TOTAL_VALUE);
    final PriceData totalPrice = new PriceData();
    totalPrice.setValue(TOTAL_VALUE);
    final PriceData deliveryCost = new PriceData();
    deliveryCost.setValue(DELIVERY_VALUE);

    final CartData cartData = new CartData();
    cartData.setSubTotal(subTotal);
    cartData.setTotalPrice(totalPrice);
    cartData.setDeliveryCost(deliveryCost);
    cartData.setTotalUnitCount(TOTAL_UNIT_COUNT);

    given(cartFacade.getMiniCart()).willReturn(cartData);
    given(request.getAttribute(COMPONENT_UID)).willReturn(TEST_COMPONENT_UID);

    ReflectionTestUtils.setField(
        miniCartComponentController, "cartFacade", cartFacade, CartFacade.class);
  }