1 00:00:00,460 --> 00:00:02,290 The solution is going to cover part two. 2 00:00:03,790 --> 00:00:08,380 And the team constructor, through an illegal argument exception, if any of the fields are null or 3 00:00:08,380 --> 00:00:09,970 any of the string values are blank. 4 00:00:10,480 --> 00:00:16,900 Also, if housecalls null or if the keeper equals null or if the seeker equals null. 5 00:00:19,490 --> 00:00:22,130 Then throw a new illegal argument exception. 6 00:00:27,840 --> 00:00:29,490 Field values cannot be no. 7 00:00:35,180 --> 00:00:37,460 Then say if a house is blank. 8 00:00:40,870 --> 00:00:42,400 Or if keeper is blank. 9 00:00:44,670 --> 00:00:46,350 Or if speaker is blank. 10 00:00:50,720 --> 00:00:53,240 Throw a new illegal argument, exception. 11 00:00:54,940 --> 00:00:56,790 Field values cannot be blank. 12 00:01:06,450 --> 00:01:09,690 And finally, if the length of chasers is not equal to three. 13 00:01:13,810 --> 00:01:16,300 Well, throw a new illegal argument exception. 14 00:01:18,800 --> 00:01:20,660 Must have three chasers. 15 00:01:28,060 --> 00:01:33,190 We need to throw another exception if the Chaser's Array contains an illegal element, the logic to 16 00:01:33,190 --> 00:01:38,680 implement that without using loops is I consider meaningful code that we should write using test driven 17 00:01:38,680 --> 00:01:39,370 development. 18 00:01:39,850 --> 00:01:44,680 Accordingly, the first test case is to test if Chaser's Array has illegal elements. 19 00:01:45,040 --> 00:01:47,980 So we'll write a unit test named has null test. 20 00:01:57,280 --> 00:02:00,730 Inside the test, I'll define an era where the first element is known. 21 00:02:06,710 --> 00:02:08,120 And the other two are filled. 22 00:02:13,940 --> 00:02:15,620 And then you can use a search through. 23 00:02:18,820 --> 00:02:20,980 To check if team has no. 24 00:02:24,230 --> 00:02:25,820 Returns true for this array. 25 00:02:35,290 --> 00:02:38,980 OK, now inside Team Java, we can write code to make the test fail. 26 00:02:43,490 --> 00:02:45,440 I'll create a method that returns a boolean. 27 00:02:46,670 --> 00:02:47,840 Named has no. 28 00:03:00,090 --> 00:03:01,800 And for now, I'll just return false. 29 00:03:04,840 --> 00:03:09,640 And I'm going to make this method static because I don't want to have to create an object just to call 30 00:03:09,640 --> 00:03:12,310 a method that doesn't interact with any fields'. 31 00:03:13,800 --> 00:03:16,620 I want to be able to call this method directly from the class. 32 00:03:17,850 --> 00:03:21,990 So by making it static, we specify that this function belongs to the class. 33 00:03:27,540 --> 00:03:31,620 Anyways, the test fails, OK, now we need to write code to make the test pass. 34 00:03:39,900 --> 00:03:43,290 Inside the function, use a for loop that runs through the length of the array. 35 00:03:46,180 --> 00:03:48,670 And we'll return true if any element is no. 36 00:04:02,210 --> 00:04:03,750 Otherwise, return false. 37 00:04:04,400 --> 00:04:05,270 Run the test. 38 00:04:11,300 --> 00:04:12,260 And it passes. 39 00:04:17,390 --> 00:04:23,960 But can this code be any simpler, can it be a refactored and the answer is a resounding yes, loops 40 00:04:23,960 --> 00:04:28,640 are messy, and if you're able to use a stream pipeline, which is normally the case when you're dealing 41 00:04:28,640 --> 00:04:31,450 with arrays or array lists, then use a stream. 42 00:04:32,180 --> 00:04:35,090 In this case, we can use the arrays, utility class. 43 00:04:38,520 --> 00:04:40,080 To call the method stream. 44 00:04:42,360 --> 00:04:47,490 And remember that history is a sequence of elements that we can run through a pipeline of operations 45 00:04:48,060 --> 00:04:52,830 and we're just going to apply the terminal operation any much, any match is going to compare every 46 00:04:52,830 --> 00:04:55,320 element in the array against a predicates. 47 00:04:57,320 --> 00:04:59,540 The lambda expression receives every element. 48 00:05:01,820 --> 00:05:05,210 And any match is going to check if any element is equal to No. 49 00:05:09,180 --> 00:05:14,220 And if any of them are not, any match is going to return, true, so we'll just return the result of 50 00:05:14,220 --> 00:05:15,080 this pipeline. 51 00:05:23,360 --> 00:05:25,580 Run the tests now and Perfect's. 52 00:05:36,870 --> 00:05:42,750 One of the elements is known and the sequence of elements enters the pipeline as a stream and any match 53 00:05:42,750 --> 00:05:46,080 returns true because one of the elements matches the predicates. 54 00:05:56,010 --> 00:05:57,720 Can this could be any simpler than that? 55 00:05:58,020 --> 00:05:59,280 No, we can move on. 56 00:06:06,480 --> 00:06:09,900 OK, we also need to create a test that checks if any of the elements are black. 57 00:06:13,110 --> 00:06:15,150 So once again, create a test that fails. 58 00:06:18,400 --> 00:06:20,620 Public void has blank test. 59 00:06:26,040 --> 00:06:28,710 And create an array where the first element is blank. 60 00:06:34,230 --> 00:06:35,670 And then we can use a true. 61 00:06:39,300 --> 00:06:41,670 To check if team has blank returns, true. 62 00:06:48,540 --> 00:06:54,080 An outside team, Java, we can write code to make the test fail, I'll get a static method that returns 63 00:06:54,080 --> 00:06:57,650 a boolean named has blank receives an array. 64 00:07:03,280 --> 00:07:05,050 And for now, I'll just return false. 65 00:07:14,730 --> 00:07:15,930 And the test fails. 66 00:07:16,020 --> 00:07:18,810 OK, now we need to write some code to make it pass. 67 00:07:22,470 --> 00:07:25,350 I'll skip the explanation, use the same pipeline as before. 68 00:07:29,140 --> 00:07:33,010 But this one is going to return true if any of the elements happen to be blank. 69 00:07:39,900 --> 00:07:40,740 Run the test. 70 00:07:43,980 --> 00:07:45,090 And it passes. 71 00:07:48,570 --> 00:07:50,280 There is no need to refactor this code. 72 00:07:50,310 --> 00:07:51,030 We can move on. 73 00:07:58,500 --> 00:08:02,220 OK, now in the constructor, I can say if The Chaser's Parameter has no. 74 00:08:10,750 --> 00:08:11,950 Or has blank. 75 00:08:24,400 --> 00:08:26,980 Then they need to throw an illegal argument exception. 76 00:08:29,340 --> 00:08:30,480 Legal elements. 77 00:08:34,140 --> 00:08:37,590 OK, now we can apply the same quality control inside the setas. 78 00:08:41,280 --> 00:08:43,260 If House is Neller blank. 79 00:08:51,180 --> 00:08:53,220 Through a new legal argument exception. 80 00:09:01,890 --> 00:09:05,220 We'll copy this over here, change some things up. 81 00:09:14,340 --> 00:09:15,720 One more time for speaker. 82 00:09:18,500 --> 00:09:24,170 And that's it, and for chasers will check if chasers that length is not equal to three. 83 00:09:29,360 --> 00:09:31,550 Or has no chaser's. 84 00:09:38,870 --> 00:09:40,550 Or Chaser's has blank. 85 00:09:49,080 --> 00:09:53,400 Then we'll throw a new illegal argument, exception, a legal chaser, arguments. 86 00:09:58,800 --> 00:10:02,040 OK, now, before we wrap up, we seem to be using this code a lot. 87 00:10:07,560 --> 00:10:09,810 So how about we create a function called Sheck Field? 88 00:10:23,440 --> 00:10:25,810 That checks if some field is another blank. 89 00:10:32,550 --> 00:10:34,830 So if the field being passed in is No. 90 00:10:38,440 --> 00:10:42,130 Or blank, then we're going to throw a new illegal argument, exception. 91 00:10:43,350 --> 00:10:45,630 That field cannot be null or blank. 92 00:10:51,350 --> 00:10:53,960 And now wherever you can invoke this function. 93 00:11:15,970 --> 00:11:22,240 You unit tested two methods, each method is modular and free of bugs and to make sure you can run every 94 00:11:22,240 --> 00:11:22,660 test. 95 00:11:24,660 --> 00:11:29,640 And seeing these beautiful green check marks is a good reminder that our code is working as it should. 96 00:11:33,840 --> 00:11:39,210 You also added checkpoints to the team class, each checkpoint forbids the caller from misusing the 97 00:11:39,210 --> 00:11:40,440 methods or constructor.