In the previous two videos, we actually created our challenge,
our banking application.
And in this video we're gonna go ahead now and actually test it.
We're going to put some code in our main class, in the main
method within that class, and just test that it's all doing as it should be doing.
So, we're going to start here in our main class as I said, in the main method.
So, let's start implementing some of this.
So firstly, we're going to start with Bank, so Bank bank = new Bank.
And I'll choose a bank that's in Australia, National Australia Bank.
Nothing new there.
So we're creating a new class, a new object for the bank class.
Next we wanna add a branch, so let's add a branch, bank.addBranch.
The branch is going to be called Adelaide.
Next, let's add some customers.
And if you recall the customers, bank.addCustomer.
And then it will be Adelaide, the customer name, and
in this case it would be me, it's Tim.
And let's put $50.05.
Let's add a couple more.
addCustomer.
We'll do the same branch again.
Mike, 175.34.
bank.addCustomer("Adelaide", "Percy",
220.12).
So, that's three customers that we've added to the Adelaide branch,
which is part of the National Australian Bank.
So, let's create another branch on the other side.
bank.addBranch, and of course, we're in Sydney.
And, let's just add one customer to it.
addCustomer.
And will be Sydney of course.
And Bob.
Bob, and I missed his quote there.
And besides $150.54.
Okay, next we'll add some more transactions.
So these are obviously the customers, we've added them once, so there'll only be
one transaction for each of those because they're being added literally just once.
But we'll add some transactions, bank.addCustomerTransaction.
And let's do them for Adelaide.
Adelaide, we'll do a couple for me and then one for, say Mike.
44.22.
We'll add a couple more here, and I'll just copy and
paste them to save a bit of time.
Space there.
So the next one, let's add another one for me.
I must be rich.
$12.44.
And the last one, say $1.65 for Mike.
Okay.
Now we've done that, let's actually try and see whether this works.
So we'll do first bank.listCustomers("Adelaide").
We can do it false first, so we're not gonna show the transactions.
So I think we've got enough code in there now to actually run this.
So let's run this and actually see what happens and see whether it actually works.
Run.
Okay, so we can see over here to the right hand side, Customer details for
branch Adelaide.
We've got customer.
Customer number 1 is Tim, customer number 2 is Mike, 3 is Percy.
And that's in order there.
Tim, Mike, and Percy.
So that's good.
And it didn't show us our transactions, or
didn't show the transactions because we selected false there.
So if we select true there, let's try that, and run that again, and
see what happens, and see if that works.
Okay so let's have a look at this.
So we've got customer Tim number 1.
Transactions for Tim should be $50.05, which it should be in order,
which is $50.05 when Tim was added as a new customer.
44.22 which is this one here.
And $12.44, so that is correct.
Customer 2 is Mike.
So he had initial one was 175.34.
He then got another one for $1.65, so that's his two entries there.
Customer number 3, Percy, $220.12.
And he didn't get another transaction there, so
therefore that seems to all be working well.
And Customer details for branch Adelaide is also working.
So just to make sure that it is working, let's add another one here.
bank.listCustomers("Sydney").
And we'll show the list of transactions for that as well.
And we should only get the one transaction for Bob,
cuz that's the only one we've actually added.
Customer details for branch Sydney, customer Bob number 1,
transactions number 1, amount $150.54.
So that seems to be working well, which is good.
So let's try some other things here.
We'll actually try sending some data through that's invalid.
So getting back to our branch Adelaide.
Let's try and do something like this.
We'll put if(!bank.addCustomer()).
And we'll call this one Melbourne,
which we haven't created that yet, Brian, $5.53.
We're gonna print out the error to say Error Melbourne branch does not exist.
Exist, like so, and we run this again.
Error Melbourne branch does not exist.
So we're correctly getting an error because Melbourne didn't exist.
And just to confirm that is the case,
we can then do something like, bank.addBranch("Melbourne").
And by doing that we should find that error will disappear now because of course
that branch does exist.
And the error's actually gone away, so that's good.
So our basic testing is working.
The other thing that we can test here, we can do a few more.
I won't do them all, but I'll leave you to actually do some more of these in
the future to see whether you can get this to work and
find all the areas to see if that we've actually correctly validated them all.
But another one we can try to do is add a branch we know already exists.
So what we can do there is we could put if(!bank.addBranch("Adelaide")).
Adelaide branch already exists.
So in other words, we're getting an error
trying to return a branch that already exists.
We should actually see that error on the screen.
So if I run that.
Adelaide branch already exists, so we correctly identify that there's an error.
And just to confirm that, we can put something here.
We can put if branch Adelaide at the top here,
if we wanted our message to say Adelaide Branch created.
Like so. So I run that again.
Adelaide Branch created.
So our true and falses are working, so
in other words our data validation is working.
And what's another one we can try?
Let's try and add another entry for, in this case,
a non existent customer and see what happens.
So we can put something like
if(!bank.addCustomerTransaction("Adela- ide", "Fergus".
And we'll put, Customer does not exist at branch.
So we should get an error there because Fergus doesn't exist.
Customer does not exist at branch.
So, that's good that we're getting some good validation there.
We're getting the correct validation that's working which is, of course,
what we wanna see.
All right and, lastly, let's try and add a customer.
I don't think we've done that.
Actually, we've done that already, haven't we?
We've tried to add a customer here, but we're actually testing to see whether
the actual bank failed, but what we can actually do there is use a valid bank but
an invalid customer to see what actually happens for that.
So what we want to do here is we want to try and call the method to add a customer,
where the customer all ready exists at a particular branch.
So to do that, we can put if(!bank.addCustomer.
And we're going to use, I need to make a bit of space here to see what we're doing.
We're gonna use ("Adelaide", "Tim", 12.21).
We'll just put Customer.
Customer Tim already exists.
So we're testing to see whether Tim already exists at the Adelaide branch and
we'll run that.
Customer Tim already exists, so that's good.
That's validating it.
And the last thing we can try and do now is try and add a transaction.
Actually we've done that already.
Customer does not exist at branch, so that's good.
I think that's about all the transactions we can actually test.
So it seems to all be working, but go through your code anyway and
make sure that you have got that validation working.
But anyway, that was my version of the challenge.
I hope you've got a lot out of that.
And again, this is just one implementation.
There's obviously more ways to approach it.
This is the one that I've come up with it.
And I hope you've got a lot out of it.
So I'll see you in the next set of videos.