[No Audio]
Now, when I was recording this video, I actually made
a mistake and I could just rerecord the video, but
I wanted to leave the video as is because it
shows us how we can use Hamcrest with lists.
And also it shows you that anybody makes mistakes.
So don't feel bad if you're writing
unit tests and you make mistakes.
Everybody makes mistakes.
That's perfectly fine.
But what I would recommend, is that you
check over your work, at regular intervals just
to make sure that it makes sense.
And that's what I did in this video,
and I realized it didn't make sense.
And at that point then it enables you
to be able to backtrack and correct what
you've done and then move forward.
But I think it's useful to see anyway, just to
show you that you don't have to be perfect.
I'm not to worry if you do make a mistake.
So what I want to put here is a Hamcrest expression
which basically encapsulates both of these two
things, or they combine both of those two things.
So as I say, whereas we can check the individual
user 1, individual user 2, so we can do an
index based get, on the list to get the user
1, or in the case of the second one, the user 2,
and then perform these individual assertions on the
object that is passed back to return from the
collection. There's a nicer way of being able to do
it now as we get more deeper into Hamcrest
and look at how we can analyze collections.
Also, another aspect of our mind is
that getRegularUsers return to set.
And so this test should actually break
because we can't guarantee the order of
elements that come back from a set.
So prices for guessing the mistake that
I made when I did this. Yes, that's right.
I didn't use the result of this.
I didn't use the actualUsers return value.
Instead, I'm mistakenly used to the userList.
That's okay, because we were demonstrating Hamcrest,
but let's just fix it up now.
[No Audio]
And of course we say we can't do this now because
we don't have the get method on a set anyway.
So in these circumstances, you wouldn't really be
able to use this kind of thing.
But I wanted to demonstrate how you could
use it if you had a list.
However, we don't have a list, so let's fix
it up in a different way by using a really
nice match in Hamcrest called Is Iterable containing.
And this is basically going to allow
us to do assertions on collections.
Ok, let's just comment these out now.
So we don't have any red, that's
gone there on the left hand side.
And now everything compiles.
And we spotted our mistake.
We can move on and get
to using Hamcrest with collections.