@Test public void testBagMultiply() { // {[12 CHF][7 USD]} *2 == {[24 CHF][14 USD]} IMoney expected = MoneyBag.create(new Money(24, "CHF"), new Money(14, "USD")); assertEquals(expected, fMB1.multiply(2)); assertEquals(fMB1, fMB1.multiply(1)); assertTrue(fMB1.multiply(0).isZero()); }
@Test public void testMoneyBagEquals() { assertTrue(!fMB1.equals(null)); assertEquals(fMB1, fMB1); IMoney equal = MoneyBag.create(new Money(12, "CHF"), new Money(7, "USD")); assertTrue(fMB1.equals(equal)); assertTrue(!fMB1.equals(f12CHF)); assertTrue(!f12CHF.equals(fMB1)); assertTrue(!fMB1.equals(fMB2)); }
@Test public void testNormalize3() { // {[12 CHF][7 USD]} - {[12 CHF][3 USD]} == [4 USD] IMoney ms1 = MoneyBag.create(new Money(12, "CHF"), new Money(3, "USD")); Money expected = new Money(4, "USD"); assertEquals(expected, fMB1.subtract(ms1)); }
@Test public void testBagNotEquals() { IMoney bag = MoneyBag.create(f12CHF, f7USD); assertFalse(bag.equals(new Money(12, "DEM").add(f7USD))); }
@Test public void testIsZero() { assertTrue(fMB1.subtract(fMB1).isZero()); assertTrue(MoneyBag.create(new Money(0, "CHF"), new Money(0, "USD")).isZero()); }
@Test public void testBagSumAdd() { // {[12 CHF][7 USD]} + {[14 CHF][21 USD]} == {[26 CHF][28 USD]} IMoney expected = MoneyBag.create(new Money(26, "CHF"), new Money(28, "USD")); assertEquals(expected, fMB1.add(fMB2)); }
@Test public void testBagSubtract() { // {[12 CHF][7 USD]} - {[14 CHF][21 USD] == {[-2 CHF][-14 USD]} IMoney expected = MoneyBag.create(new Money(-2, "CHF"), new Money(-14, "USD")); assertEquals(expected, fMB1.subtract(fMB2)); }
@Test public void testBagSimpleAdd() { // {[12 CHF][7 USD]} + [14 CHF] == {[26 CHF][7 USD]} IMoney expected = MoneyBag.create(new Money(26, "CHF"), new Money(7, "USD")); assertEquals(expected, fMB1.add(f14CHF)); }
@Test public void testBagNegate() { // {[12 CHF][7 USD]} negate == {[-12 CHF][-7 USD]} IMoney expected = MoneyBag.create(new Money(-12, "CHF"), new Money(-7, "USD")); assertEquals(expected, fMB1.negate()); }
@Test public void testNormalize2() { // {[12 CHF][7 USD]} - [12 CHF] == [7 USD] Money expected = new Money(7, "USD"); assertEquals(expected, fMB1.subtract(f12CHF)); }
@Test public void testMoneyBagHash() { IMoney equal = MoneyBag.create(new Money(12, "CHF"), new Money(7, "USD")); assertEquals(fMB1.hashCode(), equal.hashCode()); }