### Question:
BigDecimalUtils { public static Either<Exception, Optional<BigDecimal>> tryParse(final String maybeStringWithDecimal, final Locale locale) { if (StringUtils.isBlank(maybeStringWithDecimal)) { return Either.right(Optional.<BigDecimal>absent()); } try { DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(locale); format.setParseBigDecimal(true); BigDecimal parsedDecimal = new BigDecimal(format.parse(maybeStringWithDecimal).toString()); return Either.right(Optional.fromNullable(parsedDecimal)); } catch (Exception e) { return Either.left(e); } } private  BigDecimalUtils(); static BigDecimal convertNullToZero(final Object value); static BigDecimal convertNullToOne(final Object value); static BigDecimal toPercent(final BigDecimal decimalValue, final MathContext mathContext); static boolean valueEquals(final BigDecimal d1, final BigDecimal d2); static Either<Exception, Optional<BigDecimal>> tryParse(final String maybeStringWithDecimal, final Locale locale); static Either<Exception, Optional<BigDecimal>> tryParseAndIgnoreSeparator(final String maybeStringWithDecimal, final Locale locale); static boolean checkIfCorrectDecimalValue(final Entity entity, final String decimalFieldName); static String toString(BigDecimal decimal,int maximumFractionDigits);  }### Answer:
@Test public final void shouldParseNotEmptyEnDecimalString() { String stringValue = "1.2"; Either<Exception, Optional<BigDecimal>> res = BigDecimalUtils.tryParse(stringValue, Locale.ENGLISH); Assert.assertEquals(Either.right(Optional.of(new BigDecimal("1.2"))), res); }
@Test public final void shouldParseNotEmptyPlDecimalString() { String stringValue = "1,2"; Either<Exception, Optional<BigDecimal>> res = BigDecimalUtils.tryParse(stringValue, new Locale("pl")); Assert.assertEquals(Either.right(Optional.of(new BigDecimal("1.2"))), res); }
@Test public final void shouldParseEmptyDecimalString() { String stringValue = ""; Either<Exception, Optional<BigDecimal>> res = BigDecimalUtils.tryParse(stringValue, Locale.ENGLISH); Assert.assertEquals(Either.right(Optional.<BigDecimal> absent()), res); }
@Test public final void shouldReturnExceptionIfParseFail() { String incorrectDecimalString = "oops"; Either<Exception, Optional<BigDecimal>> res = BigDecimalUtils.tryParse(incorrectDecimalString, Locale.ENGLISH); Assert.assertTrue(res.isLeft()); }