01: package net.sourceforge.jaxor.example.tests;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.jaxor.example.Money;
05:
06: import java.math.BigDecimal;
07:
08: public class MoneyTest extends TestCase {
09:
10: public void testAdd() {
11: Money m = new Money("2.00");
12: Money n = new Money("3.00");
13: Money sum = m.add(n);
14: assertEquals(new Money("5.00"), sum);
15: }
16:
17: public void testEqualsWhenEqual() {
18: assertEquals(new Money("5.00"), new Money("5.00"));
19: }
20:
21: public void testEqualsWhenUnequalByPenny() {
22: Money m = new Money("2.00");
23: Money n = new Money("2.01");
24: assertTrue(!m.equals(n));
25: }
26:
27: public void testHashcodesEqualWhenEqual() {
28: Money m = new Money("2.00");
29: Money n = new Money("2.00");
30: assertEquals(m.hashCode(), n.hashCode());
31: }
32:
33: public void testEqualsWhenUnequalByLessThanHalfPenny() {
34: Money m = new Money("2.00");
35: Money n = new Money("2.004999999");
36: assertEquals(m, n);
37: }
38:
39: public void testToString() {
40: assertEquals("$100.00", new Money("100").toString());
41: }
42:
43: public void testScaleSetInConstructor() {
44: assertEquals(2, new Money("5").getAmount().scale());
45: }
46:
47: public void testZeroMoneyIsZero() {
48: assertEquals(new Money("0"), Money.ZERO);
49: }
50:
51: public void testMultiply() {
52: Money five = new Money("5");
53: assertEquals(new Money("25"), five.multiply(5));
54: }
55:
56: public void testMultiplyBigDecimal() {
57: Money five = new Money("5");
58: assertEquals(new Money("25"), five.multiply(
59: new BigDecimal("5"), BigDecimal.ROUND_UP));
60: }
61:
62: public void testLessThanZeror() {
63: Money five = new Money("5");
64: assertTrue(!five.isLessThanZero());
65: Money neg = new Money("-1");
66: assertTrue(neg.isLessThanZero());
67: assertTrue(!Money.ZERO.isLessThanZero());
68: }
69: }
|