@Test public void searchLineItemForErrors_withOneCorrectFieldAndOthersNull_returnsNull() { assertNull(searchLineItemForErrors(LineItem.newBuilder() .setTotalPrice("10.00") .build())); }
public static CartError searchLineItemForErrors(LineItem lineItem) { if (lineItem == null) { return null; } if (!matchesCurrencyPatternOrEmpty(lineItem.getUnitPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getUnitPrice(), CURRENCY_REGEX), lineItem); } if (!matchesQuantityPatternOrEmpty(lineItem.getQuantity())) { return new CartError(CartError.LINE_ITEM_QUANTITY, String.format(Locale.ENGLISH, "Invalid quantity string: %s does not match required pattern of %s", lineItem.getQuantity(), QUANTITY_REGEX), lineItem); } if (!matchesCurrencyPatternOrEmpty(lineItem.getTotalPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getTotalPrice(), CURRENCY_REGEX), lineItem); } return null; }
PaymentUtils { public static CartError searchLineItemForErrors(LineItem lineItem) { if (lineItem == null) { return null; } if (!matchesCurrencyPatternOrEmpty(lineItem.getUnitPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getUnitPrice(), CURRENCY_REGEX), lineItem); } if (!matchesQuantityPatternOrEmpty(lineItem.getQuantity())) { return new CartError(CartError.LINE_ITEM_QUANTITY, String.format(Locale.ENGLISH, "Invalid quantity string: %s does not match required pattern of %s", lineItem.getQuantity(), QUANTITY_REGEX), lineItem); } if (!matchesCurrencyPatternOrEmpty(lineItem.getTotalPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getTotalPrice(), CURRENCY_REGEX), lineItem); } return null; } }
PaymentUtils { public static CartError searchLineItemForErrors(LineItem lineItem) { if (lineItem == null) { return null; } if (!matchesCurrencyPatternOrEmpty(lineItem.getUnitPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getUnitPrice(), CURRENCY_REGEX), lineItem); } if (!matchesQuantityPatternOrEmpty(lineItem.getQuantity())) { return new CartError(CartError.LINE_ITEM_QUANTITY, String.format(Locale.ENGLISH, "Invalid quantity string: %s does not match required pattern of %s", lineItem.getQuantity(), QUANTITY_REGEX), lineItem); } if (!matchesCurrencyPatternOrEmpty(lineItem.getTotalPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getTotalPrice(), CURRENCY_REGEX), lineItem); } return null; }  }
PaymentUtils { public static CartError searchLineItemForErrors(LineItem lineItem) { if (lineItem == null) { return null; } if (!matchesCurrencyPatternOrEmpty(lineItem.getUnitPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getUnitPrice(), CURRENCY_REGEX), lineItem); } if (!matchesQuantityPatternOrEmpty(lineItem.getQuantity())) { return new CartError(CartError.LINE_ITEM_QUANTITY, String.format(Locale.ENGLISH, "Invalid quantity string: %s does not match required pattern of %s", lineItem.getQuantity(), QUANTITY_REGEX), lineItem); } if (!matchesCurrencyPatternOrEmpty(lineItem.getTotalPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getTotalPrice(), CURRENCY_REGEX), lineItem); } return null; }  static boolean matchesCurrencyPatternOrEmpty(@Nullable String priceString); static boolean matchesQuantityPatternOrEmpty(@Nullable String quantityString); @NonNull static List<CartError> validateLineItemList(
            List<LineItem> lineItems,
            @NonNull String currencyCode); static CartError searchLineItemForErrors(LineItem lineItem); @NonNull static String getPriceString(long price); @NonNull static List<CartError> removeErrorType(
            @NonNull List<CartError> errors,
            @NonNull @CartError.CartErrorType String errorType); @NonNull static String getPriceString(Long price, @NonNull Currency currency); static IsReadyToPayRequest getStripeIsReadyToPayRequest(); }
PaymentUtils { public static CartError searchLineItemForErrors(LineItem lineItem) { if (lineItem == null) { return null; } if (!matchesCurrencyPatternOrEmpty(lineItem.getUnitPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getUnitPrice(), CURRENCY_REGEX), lineItem); } if (!matchesQuantityPatternOrEmpty(lineItem.getQuantity())) { return new CartError(CartError.LINE_ITEM_QUANTITY, String.format(Locale.ENGLISH, "Invalid quantity string: %s does not match required pattern of %s", lineItem.getQuantity(), QUANTITY_REGEX), lineItem); } if (!matchesCurrencyPatternOrEmpty(lineItem.getTotalPrice())) { return new CartError(CartError.LINE_ITEM_PRICE, String.format(Locale.ENGLISH, "Invalid price string: %s does not match required pattern of %s", lineItem.getTotalPrice(), CURRENCY_REGEX), lineItem); } return null; }  static boolean matchesCurrencyPatternOrEmpty(@Nullable String priceString); static boolean matchesQuantityPatternOrEmpty(@Nullable String quantityString); @NonNull static List<CartError> validateLineItemList(
            List<LineItem> lineItems,
            @NonNull String currencyCode); static CartError searchLineItemForErrors(LineItem lineItem); @NonNull static String getPriceString(long price); @NonNull static List<CartError> removeErrorType(
            @NonNull List<CartError> errors,
            @NonNull @CartError.CartErrorType String errorType); @NonNull static String getPriceString(Long price, @NonNull Currency currency); static IsReadyToPayRequest getStripeIsReadyToPayRequest();  }