@Test(expectedExceptions = IllegalArgumentException.class) public void shouldReturnErrorWhenScaleIsUNNECESSARY() { MathContext mathContext = new MathContext(2, RoundingMode.UNNECESSARY); PrecisionScaleRoundedOperator.of(0, mathContext); fail(); }
public static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext) { requireNonNull(mathContext); if(RoundingMode.UNNECESSARY.equals(mathContext.getRoundingMode())) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the RoundingMode.UNNECESSARY on MathContext"); } if(mathContext.getPrecision() <= 0) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the zero precision on MathContext"); } return new PrecisionScaleRoundedOperator(scale, mathContext); }
PrecisionScaleRoundedOperator implements MonetaryOperator { public static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext) { requireNonNull(mathContext); if(RoundingMode.UNNECESSARY.equals(mathContext.getRoundingMode())) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the RoundingMode.UNNECESSARY on MathContext"); } if(mathContext.getPrecision() <= 0) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the zero precision on MathContext"); } return new PrecisionScaleRoundedOperator(scale, mathContext); } }
PrecisionScaleRoundedOperator implements MonetaryOperator { public static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext) { requireNonNull(mathContext); if(RoundingMode.UNNECESSARY.equals(mathContext.getRoundingMode())) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the RoundingMode.UNNECESSARY on MathContext"); } if(mathContext.getPrecision() <= 0) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the zero precision on MathContext"); } return new PrecisionScaleRoundedOperator(scale, mathContext); } private  PrecisionScaleRoundedOperator(int scale, MathContext mathContext); }
PrecisionScaleRoundedOperator implements MonetaryOperator { public static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext) { requireNonNull(mathContext); if(RoundingMode.UNNECESSARY.equals(mathContext.getRoundingMode())) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the RoundingMode.UNNECESSARY on MathContext"); } if(mathContext.getPrecision() <= 0) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the zero precision on MathContext"); } return new PrecisionScaleRoundedOperator(scale, mathContext); } private  PrecisionScaleRoundedOperator(int scale, MathContext mathContext); static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext); @Override MonetaryAmount apply(MonetaryAmount amount); int getScale(); MathContext getMathContext(); @Override String toString(); }
PrecisionScaleRoundedOperator implements MonetaryOperator { public static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext) { requireNonNull(mathContext); if(RoundingMode.UNNECESSARY.equals(mathContext.getRoundingMode())) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the RoundingMode.UNNECESSARY on MathContext"); } if(mathContext.getPrecision() <= 0) { throw new IllegalArgumentException("To create the ScaleRoundedOperator you cannot use the zero precision on MathContext"); } return new PrecisionScaleRoundedOperator(scale, mathContext); } private  PrecisionScaleRoundedOperator(int scale, MathContext mathContext); static PrecisionScaleRoundedOperator of(int scale, MathContext mathContext); @Override MonetaryAmount apply(MonetaryAmount amount); int getScale(); MathContext getMathContext(); @Override String toString();  }