For this solution to recovery tasks, two and three, the next Castells is to make sure tax is calculated
correctly.
I'm going to read a unit has named taxes valid.
In our test asserts the tax were expecting three point nine.
Is equal to the tax that gets returned when we pass a 30 dollar subtotal and to get tax.
And now inside cadaverine to write code to make the test fail public double.
Get tax.
Double subtotal.
And I'm going to return fire for now.
Run the unit test, then it fails.
Good.
Now we just write code to make sure it passes.
I'm going to multiply subtotal by point one three, because that is the tax rate from the requirements
and ideally the test should pass, but it doesn't because double digit keeps going on forever when you
multiply them.
However, we only want two decimal places.
So we're going to create a new object of the decimal format class.
And decimal format is going around our double to two decimal places.
And to remember that decimal format objects have a format method they can call that converts our number
or that around is our number, I should say, to the expected number of decimal places.
However, it returns a string and you'll also remember that the rapper double has a past double method.
Pass double passes a decimal value out of a string.
Let's rerun the test.
And it passes awesome, can this code be any simpler?
Nope, so we're done refactoring onto the next case of our unit test is going to make sure the total
calculates correctly.
So I'm going to create a unit test named Total as valid.
An artist is going to assert the total we're expecting ninety six point six seven.
Is equal to the total that gets returned when we pass in a subtotal of eighty five point fifty five.
And attacks of eleven point one to.
OK, now back in Kageyama, I'm going to write code to make our test fail public double get total.
They received the subtotal and attacks.
Inside will return zero.
Let's make sure the test fails.
It does now good to write code to make it pass, which would just be us returning the addition of both
parameters around the unit test.
And it passes gret.
Is there anything else we can do here?
I doubt I can get any simpler than this.
All right, we don't have any more methods to unit test, but we still haven't fulfilled this requirement.
We need to return a receipt.
So what I'm going to do is find a method named Checkout's that returns a string.
And it's going to return a receipt that calls every method we just created, I'm sure there's a template
we can copy over.
And here it is, and it's already been done for us, that's pretty cool.
There's nothing to unit test here, it's just a string, so we're all done part for it.
But I want you to compare the old code that we wrote in the previous section to the one we have right
now.
This code isn't good because it performs way too many tasks.
Our other methods are very long and messy.
This code is also impossible to test, so it's vulnerable to bugs.
Our new code is more polished.
Each method performs one task.
Each method is modular, and it's easy to test.