Skip to content

Commit 1179d88

Browse files
author
mpetrov
committed
#8 rename account
1 parent 6347134 commit 1179d88

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

jcash-core/src/main/java/org/sct/jcash/domain/Account.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,12 @@ public boolean equals(Object o) {
7171
Account account = (Account) o;
7272
return closed == account.closed &&
7373
Objects.equals(ccy, account.ccy) &&
74-
Objects.equals(children.size(), account.children.size()) &&
75-
Objects.equals(balance.size(), account.balance.size()) &&
7674
Objects.equals(name, account.name);
7775
}
7876

7977
@Override
8078
public int hashCode() {
81-
return Objects.hash(ccy, children.size(), balance.size(), closed, name);
79+
return Objects.hash(ccy, name);
8280
}
8381

8482
public String getName() {
@@ -88,4 +86,12 @@ public String getName() {
8886
public void setBalance(LocalDate date, double amount) {
8987
this.balance.put(date, amount);
9088
}
89+
90+
public void rename(String name) {
91+
this.name = name;
92+
}
93+
94+
public void close() {
95+
this.closed = true;
96+
}
9197
}

jcash-core/src/test/java/org/sct/jcash/domain/AccountTest.java

+22-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public void equality() {
4444
Account accRight = Account.of("");
4545

4646
Assertions.assertEquals(accLeft, accRight);
47+
48+
accRight = Account.of("1");
49+
Assertions.assertNotEquals(accRight, accLeft);
50+
51+
accRight = Account.of("", "USD");
52+
Assertions.assertNotEquals(accRight, accLeft);
4753
}
4854

4955
@Test
@@ -61,13 +67,21 @@ public void balance() {
6167
Assertions.assertEquals(amount, acc.getBalance(date.plus(5, ChronoUnit.DAYS)));
6268
}
6369

70+
@Test
71+
public void rename() {
72+
Account account = Account.of("");
73+
74+
account.rename("acc1");
75+
76+
Assertions.assertEquals("acc1", account.getName());
77+
}
78+
79+
@Test
80+
public void close() {
81+
Account account = Account.of("");
6482

65-
// todo: account balance for particular date
66-
// todo: parent-child relationship:
67-
// RUR -> RUR (OK)
68-
// RUR -> USD (ERROR)
69-
// todo: USD currency account
70-
// todo: make Account.of()
71-
// todo: rename account
72-
// todo: close account
83+
account.close();
84+
85+
Assertions.assertTrue(account.isClosed());
86+
}
7387
}

0 commit comments

Comments
 (0)