### Question:
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();  }### Answer:
@Test public void searchLineItemForErrors_whenNoFieldsEntered_returnsNull() { assertNull(searchLineItemForErrors(LineItem.newBuilder().build())); }
@Test public void searchLineItemForErrors_whenNull_returnsNull() { assertNull(searchLineItemForErrors(null)); }
@Test public void searchLineItemForErrors_withAllNumericFieldsCorrect_returnsNull() { assertNull(searchLineItemForErrors(LineItem.newBuilder() .setTotalPrice("10.00") .setQuantity("1.3") .setUnitPrice("1.50") .build())); }
@Test public void searchLineItemForErrors_whenJustOneIncorrectField_returnsExpectedError() { LineItem badTotalPriceItem = LineItem.newBuilder() .setTotalPrice("10.999") .setQuantity("1.3") .setUnitPrice("1.50") .build(); CartError totalPriceError = searchLineItemForErrors(badTotalPriceItem); assertNotNull(totalPriceError); assertEquals(CartError.LINE_ITEM_PRICE, totalPriceError.getErrorType()); assertEquals(getExpectedErrorStringForPrice("10.999"), totalPriceError.getMessage()); assertEquals(badTotalPriceItem, totalPriceError.getLineItem()); LineItem badQuantityItem = LineItem.newBuilder() .setTotalPrice("10.99") .setQuantity("1.33") .setUnitPrice("1.50") .build(); CartError quantityError = searchLineItemForErrors(badQuantityItem); assertNotNull(quantityError); assertEquals(CartError.LINE_ITEM_QUANTITY, quantityError.getErrorType()); assertEquals(getExpectedErrorStringForQuantity("1.33"), quantityError.getMessage()); assertEquals(badQuantityItem, quantityError.getLineItem()); LineItem badUnitPriceItem = LineItem.newBuilder() .setTotalPrice("10.99") .setQuantity("1.3") .setUnitPrice(".50") .build(); CartError unitPriceError = searchLineItemForErrors(badUnitPriceItem); assertNotNull(unitPriceError); assertEquals(CartError.LINE_ITEM_PRICE, unitPriceError.getErrorType()); assertEquals(getExpectedErrorStringForPrice(".50"), unitPriceError.getMessage()); assertEquals(badUnitPriceItem, unitPriceError.getLineItem()); }
@Test public void searchLineItemForErrors_withOneCorrectFieldAndOthersNull_returnsNull() { assertNull(searchLineItemForErrors(LineItem.newBuilder() .setTotalPrice("10.00") .build())); }