The solution is going to cover part three.
The second test case tells us that if a movie is removed after being sold, so write a unit test named
sell movie test.
And the movie we're going to sell is The Shawshank Redemption.
So ideally, calling cell should remove this object from the array list.
All right, and now we'll need to make an assertion.
Assert false, and this test will pass a Astorga that contains The Shawshank Redemption returns false.
And now inside Staudt Java, we can write code to make the test fail.
Public Void Cell Movie.
And the unit test implies that we need to pass a string into our method.
And for now, we'll do nothing, I want my test to fail.
And it does good now we need to write code to make the test pass.
The simplest code I can think of is to just create a loop that runs through the size of the array list.
And if the name of the movie object at the index.
Matches the name being Pastan.
Then we'll remove the movie and index I.
Let's run the test.
And it passes.
Here, it removes the movie and our assertion passes because the story doesn't contain it anymore.
OK, here comes the most important question can this be a refactored, can it be made simpler?
And the answer to that is absolutely loop's are really messy.
And since Java eight aerialists and call a remove F method.
They stop movies that remove if.
The remove, if once a predicate, a predicate is something that is true or false.
So that means our lambda expression is going to receive every element as a parameter.
Remember that every lambda expression has an arrow that points to a piece of code.
Where we need to return a boolean and we're going to return a boolean that checks, if the string of
the element we're running through is equal to the name parameter.
And as you can see, using a functional approach is more elegant than using loops.
And as we refactor, we always have to run the unit test to make sure that the new could be added does
not have any bugs and perfect the test passes.
Now, once again, can we refactor?
That's a question you have to keep asking yourself until you're absolutely certain that your code is
as simple as it's going to get in this case.
Yes, if the code is only one line, then you can remove the curly brackets as well as the return keyword.
And Jeff is going to know you intend on returning a boolean.
That's kind of cool if you ask me.
OK, I'll run the unit test.
And beautiful, the unit test passes, so I know that my code is working as intended now.
Once again, can we refactor?
Nope, we can move on to the next unit test.