Mind the context of the null pointers

Image for post
Image for post
Photo by Raquel Pedrotti on Unsplash
public abstract class BankAccount {    public BankAccount(Entity primary, Entity secondary,
String label, Deposit initialDeposit) {
this.accountBalance = INITIALIZATION_ACCOUNT_BALANCE;
this.processDeposit(initialDeposit);

this.accountNumber = getNewAccountNumber();
this.primaryAccountHolder = primary;
this.noSecondaryAccountHolderFlag = (secondary == null);
this.secondaryAccountHolder = secondary;
this.accountLabel = label;
this.accountHistory = new ArrayList<>();
this.accountBeneficiary = null;
}
}
public class CheckingAccount extends BankAccount {    private ArrayList<Check> checksList;    private SavingsAccount assocSav;    public CheckingAccount(Entity primary, Deposit initialDeposit) {
this(primary, null, "Primary Checking", initialDeposit);
}
public CheckingAccount(Entity primary, Entity secondary,
String label, Deposit initialDeposit) {
super(primary, secondary, label, initialDeposit);
this.checksList = new ArrayList<>();
this.assocSav = null;
}
}
Testsuite: bankaccounts.CheckingAccountTest
Tests run: 0, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.775 sec
Testcase: bankaccounts.CheckingAccountTest: Caused an ERROR
null
java.lang.NullPointerException
at bankaccounts.BankAccount.processDeposit(BankAccount.java:53)
at bankaccounts.BankAccount.<init>(BankAccount.java:84)
at bankaccounts.SavingsAccount.<init>(SavingsAccount.java:22)
at bankaccounts.SavingsAccount.<init>(SavingsAccount.java:18)
at bankaccounts.CheckingAccountTest.setUpClass(CheckingAccountTest.java:41)
Test bankaccounts.CheckingAccountTest FAILED
test:
Deleting: C:\Users\AL\AppData\Local\Temp\TEST-bankaccounts.CheckingAccountTest.xml
BUILD SUCCESSFUL (total time: 3 seconds)
    public final void processDeposit(Deposit deposit) {
this.accountBalance =
this.accountBalance.plus(deposit.getTransactionAmount());
this.accountHistory.add(deposit);
}
    public BankAccount(Entity primary, Entity secondary,
String label, Deposit initialDeposit) {
this.accountBalance = INITIALIZATION_ACCOUNT_BALANCE;
this.accountNumber = getNewAccountNumber();
this.primaryAccountHolder = primary;
this.noSecondaryAccountHolderFlag = (secondary == null);
this.secondaryAccountHolder = secondary;
this.accountLabel = label;
this.accountHistory = new ArrayList<>();
this.processDeposit(initialDeposit);
this.accountBeneficiary = null;
}
Testsuite: bankaccounts.CheckingAccountTest
Savings account balance: $10000.00 prior to test
Checking account balance: $1500.00 prior to test
Verifying the same deposit can't be made twice...
Savings account balance: $10000.00 after test
Checking account balance: $2810.72 after test
Testcase: testDoubleDeposit(bankaccounts.CheckingAccountTest): FAILED
expected:<$2155.36> but was:<$2810.72>
junit.framework.AssertionFailedError: expected:<$2155.36> but was:<$2810.72>
at bankaccounts.CheckingAccountTest.testDoubleDeposit(CheckingAccountTest.java:79)

is a composer and photographer from Detroit, Michigan. He has been working on a Java program to display certain mathematical diagrams.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store