### Question:
RoundingMonetaryAmountOperator implements MonetaryOperator { @Override public MonetaryAmount apply(MonetaryAmount amount) { Objects.requireNonNull(amount, "Amount required."); CurrencyUnit currency = amount.getCurrency(); int scale = scaleOptional.orElse(currency.getDefaultFractionDigits()); BigDecimal value = amount.getNumber().numberValue(BigDecimal.class).setScale(scale, roundingMode); return amount.getFactory().setNumber(value).create(); } RoundingMonetaryAmountOperator();  RoundingMonetaryAmountOperator(RoundingMode roundingMode);  RoundingMonetaryAmountOperator(RoundingMode roundingMode, int scale); @Override MonetaryAmount apply(MonetaryAmount amount);  }### Answer:
@Test public void shouldReturnPositiveValue() { CurrencyUnit currency = Monetary.getCurrency("EUR"); MonetaryAmount money = Money.parse("EUR 2.3523"); MonetaryAmount result = operator.apply(money); assertEquals(result.getCurrency(), currency); assertEquals(result.getNumber().doubleValue(), 2.35); }
@Test public void shouldReturnNegativeValue() { CurrencyUnit currency = Monetary.getCurrency("BHD"); MonetaryAmount money = Money.parse("BHD -1.34534432"); MonetaryAmount result = operator.apply(money); assertEquals(result.getCurrency(), currency); assertEquals(result.getNumber().doubleValue(), -1.345); }
@Test public void shouldReturnPositiveValueUsingRoundingType() { operator = new RoundingMonetaryAmountOperator(RoundingMode.HALF_EVEN); CurrencyUnit currency = Monetary.getCurrency("EUR"); MonetaryAmount money = Money.parse("EUR 2.3523"); MonetaryAmount result = operator.apply(money); assertEquals(result.getCurrency(), currency); assertEquals(result.getNumber().doubleValue(), 2.35); }
@Test public void shouldReturnNegativeValueUsingRoundingType() { operator = new RoundingMonetaryAmountOperator(RoundingMode.HALF_EVEN); CurrencyUnit currency = Monetary.getCurrency("BHD"); MonetaryAmount money = Money.parse("BHD -1.34534432"); MonetaryAmount result = operator.apply(money); assertEquals(result.getCurrency(), currency); assertEquals(result.getNumber().doubleValue(), -1.345); }
@Test public void shouldReturnPositiveValueUsingRoundingTypeAndScale() { operator = new RoundingMonetaryAmountOperator(RoundingMode.HALF_EVEN, 3); CurrencyUnit currency = Monetary.getCurrency("EUR"); MonetaryAmount money = Money.parse("EUR 2.3523"); MonetaryAmount result = operator.apply(money); assertEquals(result.getCurrency(), currency); assertEquals(result.getNumber().doubleValue(), 2.352); }
@Test public void shouldReturnNegativeValueUsingRoundingTypeAndScale() { operator = new RoundingMonetaryAmountOperator(RoundingMode.HALF_EVEN, 4); CurrencyUnit currency = Monetary.getCurrency("BHD"); MonetaryAmount money = Money.parse("BHD -1.34534432"); MonetaryAmount result = operator.apply(money); assertEquals(result.getCurrency(), currency); assertEquals(result.getNumber().doubleValue(), -1.3453); }
@Test(expectedExceptions = NullPointerException.class) public void shouldReturnErroWhenIsNull() { operator.apply(null); fail(); }