1 00:00:00,000 --> 00:00:02,516 [No Audio] 2 00:00:02,516 --> 00:00:04,282 So we just saw the equal to matcher. 3 00:00:04,282 --> 00:00:06,056 And the key point here is that 4 00:00:06,056 --> 00:00:08,374 it's actually using the Java equals method. 5 00:00:08,374 --> 00:00:11,514 And as we said, the bad side to this from a tester 6 00:00:11,514 --> 00:00:14,531 perspective is that we're actually using production 7 00:00:14,531 --> 00:00:17,566 code, which is this User.createRegularUser method. 8 00:00:17,566 --> 00:00:19,592 We're using production code in our test 9 00:00:19,592 --> 00:00:22,186 method to create the objects that we're 10 00:00:22,186 --> 00:00:25,570 doing assertions against, which isn't really ideal. 11 00:00:25,570 --> 00:00:28,180 We really want to keep the code we're invoking 12 00:00:28,180 --> 00:00:30,814 to the bare minimum, ideally just to the method 13 00:00:30,814 --> 00:00:34,040 implication which we're testing, and not call any extra 14 00:00:34,040 --> 00:00:36,044 code, because if we do, then it's difficult to 15 00:00:36,044 --> 00:00:38,074 isolate where problems might occur. 16 00:00:38,074 --> 00:00:41,291 In other words, this code could actually be buggy. 17 00:00:41,291 --> 00:00:44,204 So for example, supposing there's some logic in here 18 00:00:44,204 --> 00:00:46,784 which creates a user object which isn't quite set 19 00:00:46,784 --> 00:00:48,646 up as we like it, then that might somehow 20 00:00:48,646 --> 00:00:51,080 skew our tests, which we don't really want. 21 00:00:51,080 --> 00:00:52,724 So the moral of the story here is 22 00:00:52,724 --> 00:00:55,448 don't call production code in your test code 23 00:00:55,448 --> 00:00:57,656 just to create the objects you're asserting against. 24 00:00:57,656 --> 00:00:59,206 Keep those production costs to a minimum, 25 00:00:59,206 --> 00:01:00,778 preferably just to the method that you're 26 00:01:00,778 --> 00:01:03,034 invoking, which is a method being tested. 27 00:01:03,034 --> 00:01:04,364 So how do we get around this? 28 00:01:04,364 --> 00:01:06,296 Because obviously we want to have the ability to be 29 00:01:06,296 --> 00:01:10,244 able to compare elements of the collection, but we want 30 00:01:10,244 --> 00:01:13,234 to do it without having a call to a factory 31 00:01:13,234 --> 00:01:16,234 method like this, or even call to the constructor. 32 00:01:16,234 --> 00:01:17,744 So we can do that in a different way, 33 00:01:17,744 --> 00:01:19,339 which I'll show in the next video.