@Test public void getTotalPrice_whenSomeSectionsAreNull_returnsExpectedValue() { AndroidPayConfiguration.getInstance().setCurrencyCode("JPY"); Cart oldCart = generateCartWithAllItems("JPY"); CartManager manager = new CartManager(oldCart); assertEquals(Long.valueOf(7000L), manager.getTotalPrice()); }
@Nullable public Long getTotalPrice() { if (mCachedTotalPrice != null) { return mCachedTotalPrice; } Long[] sectionPrices = new Long[3]; sectionPrices[0] = calculateRegularItemTotal(); sectionPrices[1] = calculateShippingItemTotal(); sectionPrices[2] = calculateTax(); Long totalPrice = null; for (int i = 0 ; i < sectionPrices.length; i++) { if (sectionPrices[i] == null) { return null; } if (totalPrice == null) { totalPrice = sectionPrices[i]; } else { totalPrice += sectionPrices[i]; } } mCachedTotalPrice = totalPrice; return totalPrice; }
CartManager { @Nullable public Long getTotalPrice() { if (mCachedTotalPrice != null) { return mCachedTotalPrice; } Long[] sectionPrices = new Long[3]; sectionPrices[0] = calculateRegularItemTotal(); sectionPrices[1] = calculateShippingItemTotal(); sectionPrices[2] = calculateTax(); Long totalPrice = null; for (int i = 0 ; i < sectionPrices.length; i++) { if (sectionPrices[i] == null) { return null; } if (totalPrice == null) { totalPrice = sectionPrices[i]; } else { totalPrice += sectionPrices[i]; } } mCachedTotalPrice = totalPrice; return totalPrice; } }
CartManager { @Nullable public Long getTotalPrice() { if (mCachedTotalPrice != null) { return mCachedTotalPrice; } Long[] sectionPrices = new Long[3]; sectionPrices[0] = calculateRegularItemTotal(); sectionPrices[1] = calculateShippingItemTotal(); sectionPrices[2] = calculateTax(); Long totalPrice = null; for (int i = 0 ; i < sectionPrices.length; i++) { if (sectionPrices[i] == null) { return null; } if (totalPrice == null) { totalPrice = sectionPrices[i]; } else { totalPrice += sectionPrices[i]; } } mCachedTotalPrice = totalPrice; return totalPrice; } CartManager();  CartManager(String currencyCode);  CartManager(@NonNull Cart oldCart);  CartManager(@NonNull Cart oldCart, boolean shouldKeepShipping, boolean shouldKeepTax); }
CartManager { @Nullable public Long getTotalPrice() { if (mCachedTotalPrice != null) { return mCachedTotalPrice; } Long[] sectionPrices = new Long[3]; sectionPrices[0] = calculateRegularItemTotal(); sectionPrices[1] = calculateShippingItemTotal(); sectionPrices[2] = calculateTax(); Long totalPrice = null; for (int i = 0 ; i < sectionPrices.length; i++) { if (sectionPrices[i] == null) { return null; } if (totalPrice == null) { totalPrice = sectionPrices[i]; } else { totalPrice += sectionPrices[i]; } } mCachedTotalPrice = totalPrice; return totalPrice; } CartManager();  CartManager(String currencyCode);  CartManager(@NonNull Cart oldCart);  CartManager(@NonNull Cart oldCart, boolean shouldKeepShipping, boolean shouldKeepTax); @Nullable String addLineItem(@NonNull @Size(min = 1) String description, long totalPrice); @Nullable String addLineItem(@NonNull @Size(min = 1) String description,
                              double quantity,
                              long unitPrice); @Nullable String addShippingLineItem(@NonNull @Size(min = 1) String description, long totalPrice); @Nullable String addShippingLineItem(@NonNull @Size(min = 1) String description,
                                      double quantity,
                                      long unitPrice); @Nullable Long calculateRegularItemTotal(); @Nullable Long calculateShippingItemTotal(); Long calculateTax(); void setTaxLineItem(@NonNull @Size(min = 1) String description, long totalPrice); void setTotalPrice(@Nullable Long totalPrice); void setTaxLineItem(@Nullable LineItem item); @Nullable LineItem removeLineItem(@NonNull @Size(min = 1) String itemId); @Nullable String addLineItem(@NonNull LineItem item); @NonNull Cart buildCart(); @Nullable Long getTotalPrice(); @NonNull Currency getCurrency(); @NonNull String getCurrencyCode(); @NonNull LinkedHashMap<String, LineItem> getLineItemsRegular(); @NonNull LinkedHashMap<String, LineItem> getLineItemsShipping(); @Nullable LineItem getLineItemTax(); }
CartManager { @Nullable public Long getTotalPrice() { if (mCachedTotalPrice != null) { return mCachedTotalPrice; } Long[] sectionPrices = new Long[3]; sectionPrices[0] = calculateRegularItemTotal(); sectionPrices[1] = calculateShippingItemTotal(); sectionPrices[2] = calculateTax(); Long totalPrice = null; for (int i = 0 ; i < sectionPrices.length; i++) { if (sectionPrices[i] == null) { return null; } if (totalPrice == null) { totalPrice = sectionPrices[i]; } else { totalPrice += sectionPrices[i]; } } mCachedTotalPrice = totalPrice; return totalPrice; } CartManager();  CartManager(String currencyCode);  CartManager(@NonNull Cart oldCart);  CartManager(@NonNull Cart oldCart, boolean shouldKeepShipping, boolean shouldKeepTax); @Nullable String addLineItem(@NonNull @Size(min = 1) String description, long totalPrice); @Nullable String addLineItem(@NonNull @Size(min = 1) String description,
                              double quantity,
                              long unitPrice); @Nullable String addShippingLineItem(@NonNull @Size(min = 1) String description, long totalPrice); @Nullable String addShippingLineItem(@NonNull @Size(min = 1) String description,
                                      double quantity,
                                      long unitPrice); @Nullable Long calculateRegularItemTotal(); @Nullable Long calculateShippingItemTotal(); Long calculateTax(); void setTaxLineItem(@NonNull @Size(min = 1) String description, long totalPrice); void setTotalPrice(@Nullable Long totalPrice); void setTaxLineItem(@Nullable LineItem item); @Nullable LineItem removeLineItem(@NonNull @Size(min = 1) String itemId); @Nullable String addLineItem(@NonNull LineItem item); @NonNull Cart buildCart(); @Nullable Long getTotalPrice(); @NonNull Currency getCurrency(); @NonNull String getCurrencyCode(); @NonNull LinkedHashMap<String, LineItem> getLineItemsRegular(); @NonNull LinkedHashMap<String, LineItem> getLineItemsShipping(); @Nullable LineItem getLineItemTax();  }