This commit is contained in:
press0@gmail.com
2023-04-10 10:37:33 -05:00
parent bde71a9dea
commit 1327f2d0af
4 changed files with 31 additions and 12 deletions

View File

@@ -16,7 +16,7 @@ class Voucher {
return true;
if (!(o instanceof Voucher))
return false;
Voucher other = (Voucher)o;
Voucher other = (Voucher) o;
boolean valueEquals = (this.value == null && other.value == null)
|| (this.value != null && this.value.equals(other.value));
boolean storeEquals = (this.store == null && other.store == null)

View File

@@ -13,15 +13,25 @@ public class MoneyUnitTest {
Money expenses = new Money(55, "USD");
assertTrue(income.equals(expenses));
assertTrue(expenses.equals(income));
}
@Test
public void givenMoneyAndWrongVoucherInstances_whenEquals_thenReturnValuesArentSymmetric() {
Money money = new Money(42, "USD");
WrongVoucher voucher = new WrongVoucher(42, "USD", "Amazon");
assertFalse(voucher.equals(money));
assertTrue(money.equals(voucher));
}
@Test
public void givenMoneyAndVoucherInstances_whenEquals_thenReturnValuesArentSymmetric() {
Money cash = new Money(42, "USD");
WrongVoucher voucher = new WrongVoucher(42, "USD", "Amazon");
Money money = new Money(42, "USD");
Voucher voucher = new Voucher(42, "USD", "Amazon");
assertFalse(voucher.equals(cash));
assertTrue(cash.equals(voucher));
assertFalse(voucher.equals(money));
assertFalse(money.equals(voucher));
}
}