1 00:00:00,000 --> 00:00:02,612 [No Audio] 2 00:00:02,612 --> 00:00:04,904 Now, when I was recording this video, I actually made 3 00:00:04,904 --> 00:00:09,296 a mistake and I could just rerecord the video, but 4 00:00:09,296 --> 00:00:10,856 I wanted to leave the video as is because it 5 00:00:10,856 --> 00:00:13,378 shows us how we can use Hamcrest with lists. 6 00:00:13,378 --> 00:00:15,718 And also it shows you that anybody makes mistakes. 7 00:00:15,718 --> 00:00:16,834 So don't feel bad if you're writing 8 00:00:16,834 --> 00:00:18,706 unit tests and you make mistakes. 9 00:00:18,706 --> 00:00:19,882 Everybody makes mistakes. 10 00:00:19,882 --> 00:00:20,936 That's perfectly fine. 11 00:00:20,936 --> 00:00:22,652 But what I would recommend, is that you 12 00:00:22,652 --> 00:00:25,016 check over your work, at regular intervals just 13 00:00:25,016 --> 00:00:26,372 to make sure that it makes sense. 14 00:00:26,372 --> 00:00:27,974 And that's what I did in this video, 15 00:00:27,974 --> 00:00:29,774 and I realized it didn't make sense. 16 00:00:29,774 --> 00:00:31,544 And at that point then it enables you 17 00:00:31,544 --> 00:00:33,415 to be able to backtrack and correct what 18 00:00:33,415 --> 00:00:34,940 you've done and then move forward. 19 00:00:34,940 --> 00:00:37,016 But I think it's useful to see anyway, just to 20 00:00:37,016 --> 00:00:38,420 show you that you don't have to be perfect. 21 00:00:38,420 --> 00:00:40,800 I'm not to worry if you do make a mistake. 22 00:00:40,800 --> 00:00:45,233 So what I want to put here is a Hamcrest expression 23 00:00:45,233 --> 00:00:47,672 which basically encapsulates both of these two 24 00:00:47,672 --> 00:00:50,720 things, or they combine both of those two things. 25 00:00:50,720 --> 00:00:53,648 So as I say, whereas we can check the individual 26 00:00:53,648 --> 00:00:56,324 user 1, individual user 2, so we can do an 27 00:00:56,324 --> 00:00:59,434 index based get, on the list to get the user 28 00:00:59,434 --> 00:01:02,002 1, or in the case of the second one, the user 2, 29 00:01:02,002 --> 00:01:05,682 and then perform these individual assertions on the 30 00:01:05,696 --> 00:01:07,529 object that is passed back to return from the 31 00:01:07,529 --> 00:01:10,028 collection. There's a nicer way of being able to do 32 00:01:10,028 --> 00:01:12,490 it now as we get more deeper into Hamcrest 33 00:01:12,490 --> 00:01:14,961 and look at how we can analyze collections. 34 00:01:14,961 --> 00:01:17,504 Also, another aspect of our mind is 35 00:01:17,504 --> 00:01:19,964 that getRegularUsers return to set. 36 00:01:19,964 --> 00:01:21,890 And so this test should actually break 37 00:01:21,890 --> 00:01:23,984 because we can't guarantee the order of 38 00:01:23,984 --> 00:01:25,997 elements that come back from a set. 39 00:01:25,997 --> 00:01:28,448 So prices for guessing the mistake that 40 00:01:28,448 --> 00:01:31,232 I made when I did this. Yes, that's right. 41 00:01:31,232 --> 00:01:33,356 I didn't use the result of this. 42 00:01:33,356 --> 00:01:37,139 I didn't use the actualUsers return value. 43 00:01:37,139 --> 00:01:39,764 Instead, I'm mistakenly used to the userList. 44 00:01:39,764 --> 00:01:42,466 That's okay, because we were demonstrating Hamcrest, 45 00:01:42,466 --> 00:01:43,833 but let's just fix it up now. 46 00:01:43,833 --> 00:01:49,830 [No Audio] 47 00:01:49,830 --> 00:01:52,092 And of course we say we can't do this now because 48 00:01:52,092 --> 00:01:55,206 we don't have the get method on a set anyway. 49 00:01:55,206 --> 00:01:59,016 So in these circumstances, you wouldn't really be 50 00:01:59,016 --> 00:02:00,264 able to use this kind of thing. 51 00:02:00,264 --> 00:02:02,124 But I wanted to demonstrate how you could 52 00:02:02,124 --> 00:02:03,780 use it if you had a list. 53 00:02:03,780 --> 00:02:06,012 However, we don't have a list, so let's fix 54 00:02:06,012 --> 00:02:08,613 it up in a different way by using a really 55 00:02:08,613 --> 00:02:11,918 nice match in Hamcrest called Is Iterable containing. 56 00:02:11,918 --> 00:02:13,332 And this is basically going to allow 57 00:02:13,332 --> 00:02:15,938 us to do assertions on collections. 58 00:02:15,938 --> 00:02:19,572 Ok, let's just comment these out now. 59 00:02:19,572 --> 00:02:22,166 So we don't have any red, that's 60 00:02:22,178 --> 00:02:23,592 gone there on the left hand side. 61 00:02:23,592 --> 00:02:24,998 And now everything compiles. 62 00:02:24,998 --> 00:02:26,354 And we spotted our mistake. 63 00:02:26,354 --> 00:02:27,382 We can move on and get 64 00:02:27,396 --> 00:02:29,410 to using Hamcrest with collections.