[No Audio]
Now, when you start getting a little bit
more advanced with your assertions, you start to
see weaknesses in the JUnit Assertions API.
So, for example, it would be nice as well
though, to be able to write extra things.
So, for example, to say also assert that
no users in this collection of AdminUser.
And when you start to get at those kind of things,
when you start to want to write assertions like that,
when you do that, then you see that the JUnit
Assertions API kind of lets you down because
it's pretty good. It's a good start.
The problem is that, that the methods that it
offers are a little bit too low level.
It's almost like you want constructs that can be at
a higher level that you can somehow kind of compose,
for example, with and, or's so we can add conditions
together or we can or them together.
If you have that kind of mechanism combined with things
like assert equals, but maybe not exact equals, but
maybe I'm kind of like checking if things are kind
of equal in a certain way, like, for example, equals,
ignore case or collections containing elements of this
particular type, that kind of thing, then it'd be much
easier because then we wouldn't have to write a lot of
code to be able to use these low level Junit sessions
API constructs. We wouldn't have to write code then,
which would be an imperative approach where
we're physically coding how we're testing things.
And again, we all know that the more code be
introduced, the more likely it is we're going to get
bugs in there. That's why we want to have as little
code as possible in our unit tests and want to
keep them as simple as possible by just doing
things as basic as creating a list, individual ads for
list, individual assert statements, one call to invoke
the test method, that kind of thing.
And if we had this kind of better assertions mechanism
or assertions library, then we could use it.
And that's exactly what Hamcrest does for us.
So let's have a look now and see how we might
rewrite this using the Hamcrest assertions library.
Let's call this getRegularUsers_junit.
Let's copy this method
[No Audio]
and call it getRegularUsers
[No Audio]
Hamcrest. Great.
So now we're all set up and we can
start to explore Hamcrest in the next videos.