For this solution, we're gonna cover tasks two and three.
Going back to the third test case, we need to write a unit test that expects cell movie to throw an
exception if a movie has already been rented.
So here I can write a unit test that expects an illegal state exception.
Test expected.
And it expects an illegal state exception.
DECLASSE.
The unit test is called Movie Night in Stock.
First, I'll rent The Godfather.
And then I'll try to sell The Godfather.
If I run the test now.
It fails, it's expecting the test to throw in a legal state exception, but it isn't.
And so now we need to make the test pass by throwing an illegal -- exception from sell movie.
If the movie is already rented.
Throw an illegal STD exception.
Rerun the test and perfect.
And just have a look at how clean and elegant the code is, when you write tests, before you write
code, you're being forced to write code that is easy to test.
At the same time, code that is easy to test won't get any bugs.
And now what I'm going to do is run every single test.
They all pass, which means the code inside Staudt Java doesn't have any bugs.
And before we wrap up, just I want you to really appreciate how polished our code is.
Compared the old code with the new code in the old code, the functions were massive, this function
here is impossible to test.
So if you get a bug here, it's going to be really hard to fix.
In general, this is not good coding, but with unit testing, our code is a lot cleaner and immune
to bugs.