[No Audio]
Now let's just see, what happens if we don't
have both of those things in we'll see that
Hamcrest gives you a really nice error message.
[No Audio]
So running now, we get this nice error message here.
So this means it's expecting Iterable over,
which basically just means a collection of.
So it's expecting a collection of and then here
it specifies the collection itself, and it uses
this notation where the square brackets here, you can
see a square bracket here, square bracket here.
And anything inside that is the actual
elements of a collection. So in other words, the
square brackets means a collection.
So it's expecting a collection of,
and then inside we can
see between these angle brackets.
This is where it's specifying an object,
actual object is expecting inside that collection.
So the collection has square brackets, and then
within that you'll have objects that it's expecting,
which are elements of the collection.
And those are in angle brackets.
So here is it saying it's expecting
a collection which just contains one thing.
And that one thing is anne, as you can
see here, but it's saying it's got something extra.
And what it's got extra is another object.
We can see it's just angle brackets.
So it's going to an object, which is donald.
It's saying I'm not expecting donald, you've just told
me to expect an collection just containing anne.
Instead I've got anne and donald.
That's what that means there.
So we just put that back in here
[No Audio]
to fix it up and re run.
And that's fine.
Now if it turns out we had a different password,
[No Audio]
for example, and then rerun, then again we get
another nice error message, which is very readable.
So this is a really good thing with Hamcrest
over and above the JUnit assertions API.
And that's the fact that the error messages you get
back when you get assertion failures, they're very
readable and they really tell you exactly what the
issue is. So here it's saying, okay, we expect a
collection of and now we're saying we've got two things
we're expecting in there,
[No Audio]
and
[No Audio]
and donald with that specific password.
But instead it's saying I've got a
problem because donald, I've got donald here,
which has a different password.
No, it doesn't tell you
the password is different explicitly.
So you have to kind of eyeball this and see
that this password bit here is different to this
password. But here.
But you get the idea it's still
very readable and it's much better from
JUnit and its existing assertion API.
So let's fix that up again by reverting that rerun.
Everything is fine. But now you know how to interpret
Hamcrest assertion failures. So let's move on.