VAT implements ValueObject { @NonNull public Money subtractTax(@NonNull Money amount) { Objects.requireNonNull(amount, "amount must not be null"); var withoutTax = (amount.fixedPointAmount() * 100) / (percentage + 100); return new Money(amount.currency(), withoutTax); } @JsonCreator  VAT(int percentage); static VAT valueOf(Integer percentage); @JsonValue int toInteger(); double toDouble(); @NonNull Money addTax(@NonNull Money amount); @NonNull Money subtractTax(@NonNull Money amount); @NonNull Money calculateTax(@NonNull Money amount); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void subtractTax_noDecimals() { var withoutTax = new VAT(24).subtractTax(new Money(Currency.EUR, 124.00)); assertThat(withoutTax).isEqualTo(new Money(Currency.EUR, 100.00)); }
@Test public void subtractTax_withDecimals() { var withoutTax = new VAT(24).subtractTax(new Money(Currency.EUR, 1.24)); assertThat(withoutTax).isEqualTo(new Money(Currency.EUR, 1.00)); }