1 00:00:00,000 --> 00:00:02,590 [No Audio] 2 00:00:02,590 --> 00:00:03,836 Now, when you start getting a little bit 3 00:00:03,836 --> 00:00:06,104 more advanced with your assertions, you start to 4 00:00:06,104 --> 00:00:08,650 see weaknesses in the JUnit Assertions API. 5 00:00:08,650 --> 00:00:10,364 So, for example, it would be nice as well 6 00:00:10,364 --> 00:00:11,564 though, to be able to write extra things. 7 00:00:11,564 --> 00:00:13,844 So, for example, to say also assert that 8 00:00:13,844 --> 00:00:16,642 no users in this collection of AdminUser. 9 00:00:16,642 --> 00:00:18,524 And when you start to get at those kind of things, 10 00:00:18,524 --> 00:00:20,807 when you start to want to write assertions like that, 11 00:00:20,807 --> 00:00:22,272 when you do that, then you see that the JUnit 12 00:00:22,272 --> 00:00:24,822 Assertions API kind of lets you down because 13 00:00:24,822 --> 00:00:26,504 it's pretty good. It's a good start. 14 00:00:26,504 --> 00:00:28,256 The problem is that, that the methods that it 15 00:00:28,256 --> 00:00:30,704 offers are a little bit too low level. 16 00:00:30,704 --> 00:00:32,408 It's almost like you want constructs that can be at 17 00:00:32,408 --> 00:00:34,762 a higher level that you can somehow kind of compose, 18 00:00:34,762 --> 00:00:37,594 for example, with and, or's so we can add conditions 19 00:00:37,594 --> 00:00:39,584 together or we can or them together. 20 00:00:39,584 --> 00:00:42,632 If you have that kind of mechanism combined with things 21 00:00:42,632 --> 00:00:45,524 like assert equals, but maybe not exact equals, but 22 00:00:45,524 --> 00:00:47,852 maybe I'm kind of like checking if things are kind 23 00:00:47,852 --> 00:00:50,854 of equal in a certain way, like, for example, equals, 24 00:00:50,854 --> 00:00:54,370 ignore case or collections containing elements of this 25 00:00:54,370 --> 00:00:56,670 particular type, that kind of thing, then it'd be much 26 00:00:56,670 --> 00:00:59,254 easier because then we wouldn't have to write a lot of 27 00:00:59,254 --> 00:01:02,734 code to be able to use these low level Junit sessions 28 00:01:02,734 --> 00:01:05,324 API constructs. We wouldn't have to write code then, 29 00:01:05,324 --> 00:01:07,075 which would be an imperative approach where 30 00:01:07,075 --> 00:01:09,884 we're physically coding how we're testing things. 31 00:01:09,884 --> 00:01:11,517 And again, we all know that the more code be 32 00:01:11,517 --> 00:01:13,166 introduced, the more likely it is we're going to get 33 00:01:13,166 --> 00:01:14,866 bugs in there. That's why we want to have as little 34 00:01:14,866 --> 00:01:17,396 code as possible in our unit tests and want to 35 00:01:17,396 --> 00:01:19,304 keep them as simple as possible by just doing 36 00:01:19,304 --> 00:01:22,284 things as basic as creating a list, individual ads for 37 00:01:22,284 --> 00:01:25,726 list, individual assert statements, one call to invoke 38 00:01:25,726 --> 00:01:27,494 the test method, that kind of thing. 39 00:01:27,494 --> 00:01:30,202 And if we had this kind of better assertions mechanism 40 00:01:30,202 --> 00:01:32,060 or assertions library, then we could use it. 41 00:01:32,060 --> 00:01:34,496 And that's exactly what Hamcrest does for us. 42 00:01:34,496 --> 00:01:36,479 So let's have a look now and see how we might 43 00:01:36,479 --> 00:01:39,676 rewrite this using the Hamcrest assertions library. 44 00:01:39,676 --> 00:01:44,361 Let's call this getRegularUsers_junit. 45 00:01:44,361 --> 00:01:45,994 Let's copy this method 46 00:01:45,994 --> 00:01:49,644 [No Audio] 47 00:01:49,644 --> 00:01:51,161 and call it getRegularUsers 48 00:01:51,161 --> 00:01:54,466 [No Audio] 49 00:01:54,466 --> 00:01:56,128 Hamcrest. Great. 50 00:01:56,128 --> 00:01:57,302 So now we're all set up and we can 51 00:01:57,316 --> 00:01:59,872 start to explore Hamcrest in the next videos.