@Test public void add() { var m1 = new Money(Currency.SEK, 150.00); var m2 = new Money(Currency.SEK, 225.00); assertThat(m1.add(m2)).isEqualTo(new Money(Currency.SEK, 375.00)); }
@NonNull public Money add(@NonNull Money augend) { Objects.requireNonNull(augend, "augend must not be null"); if (currency != augend.currency) { throw new IllegalArgumentException("Cannot add two Money objects with different currencies"); } return new Money(currency, amount + augend.amount); }
Money implements ValueObject { @NonNull public Money add(@NonNull Money augend) { Objects.requireNonNull(augend, "augend must not be null"); if (currency != augend.currency) { throw new IllegalArgumentException("Cannot add two Money objects with different currencies"); } return new Money(currency, amount + augend.amount); } }
Money implements ValueObject { @NonNull public Money add(@NonNull Money augend) { Objects.requireNonNull(augend, "augend must not be null"); if (currency != augend.currency) { throw new IllegalArgumentException("Cannot add two Money objects with different currencies"); } return new Money(currency, amount + augend.amount); } @JsonCreator  Money(@NonNull @JsonProperty("currency") Currency currency, @JsonProperty("amount") int amount);  Money(@NonNull Currency currency, double amount); }
Money implements ValueObject { @NonNull public Money add(@NonNull Money augend) { Objects.requireNonNull(augend, "augend must not be null"); if (currency != augend.currency) { throw new IllegalArgumentException("Cannot add two Money objects with different currencies"); } return new Money(currency, amount + augend.amount); } @JsonCreator  Money(@NonNull @JsonProperty("currency") Currency currency, @JsonProperty("amount") int amount);  Money(@NonNull Currency currency, double amount); static Money valueOf(Currency currency, Integer value); @NonNull Money add(@NonNull Money augend); @NonNull Money subtract(@NonNull Money subtrahend); @NonNull Money multiply(int multiplicand); @NonNull Currency currency(); int fixedPointAmount(); double doubleAmount(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
Money implements ValueObject { @NonNull public Money add(@NonNull Money augend) { Objects.requireNonNull(augend, "augend must not be null"); if (currency != augend.currency) { throw new IllegalArgumentException("Cannot add two Money objects with different currencies"); } return new Money(currency, amount + augend.amount); } @JsonCreator  Money(@NonNull @JsonProperty("currency") Currency currency, @JsonProperty("amount") int amount);  Money(@NonNull Currency currency, double amount); static Money valueOf(Currency currency, Integer value); @NonNull Money add(@NonNull Money augend); @NonNull Money subtract(@NonNull Money subtrahend); @NonNull Money multiply(int multiplicand); @NonNull Currency currency(); int fixedPointAmount(); double doubleAmount(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }