Skip to content

Commit ce8b9e6

Browse files
committed
Feat:Fix
1 parent 67ed9b1 commit ce8b9e6

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/Check.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.codedifferently.lesson17.bank;
22

33
import com.codedifferently.lesson17.bank.exceptions.CheckVoidedException;
4+
import com.codedifferently.lesson17.bank.exceptions.SavingsAccount;
45

56
/** Represents a check. */
67
public class Check {
@@ -21,6 +22,9 @@ public Check(String checkNumber, double amount, CheckingAccount account) {
2122
if (amount < 0) {
2223
throw new IllegalArgumentException("Check amount must be positive");
2324
}
25+
if (account instanceof SavingsAccount) {
26+
throw new UnsupportedOperationException("Cannot issue checks from a savings account.");
27+
}
2428
this.checkNumber = checkNumber;
2529
this.amount = amount;
2630
this.account = account;
@@ -47,7 +51,7 @@ public void voidCheck() {
4751
*/
4852
public void depositFunds(CheckingAccount toAccount) {
4953
if (isVoided) {
50-
throw new CheckVoidedException("Check is voided");
54+
throw new CheckVoidedException("MoneyOrder is voided");
5155
}
5256
account.withdraw(amount);
5357
toAccount.deposit(amount);

lesson_17/bank/bank_app/src/test/java/com/codedifferently/lesson17/bank/exceptions/MoneyOrderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void testEquals() {
6868
@Test
6969
void testToString() {
7070
// Arrange
71-
CheckingAccount account = new CheckingAccount("123456789", null, 0);
71+
CheckingAccount account = new CheckingAccount("123456789", null, 50.0);
7272
MoneyOrder classUnderTest = new MoneyOrder("123456789", 50.0, account);
7373
// Act
7474
String result = classUnderTest.toString();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)