1 00:00:00,000 --> 00:00:01,990 [No Audio] 2 00:00:01,990 --> 00:00:03,224 In this video, we're going to tidy things 3 00:00:03,224 --> 00:00:05,916 up a little bit by separating out our classes 4 00:00:05,916 --> 00:00:08,278 into packages corresponding to the different layers. 5 00:00:08,278 --> 00:00:09,934 Just keep things nice and tidy. 6 00:00:09,934 --> 00:00:11,558 So let's explore that now. 7 00:00:11,558 --> 00:00:13,630 So in here now we've got a reasonably 8 00:00:13,630 --> 00:00:15,824 fair representation of simple piece of a web 9 00:00:15,824 --> 00:00:18,430 application which we might have in production. 10 00:00:18,430 --> 00:00:21,863 So quick recap then, actually let's split them into 11 00:00:21,863 --> 00:00:25,342 the proper packages as well while we're at it. 12 00:00:25,342 --> 00:00:27,808 So there's going to be a web package, 13 00:00:27,808 --> 00:00:32,299 [No Audio] 14 00:00:32,299 --> 00:00:36,532 there's going to be a service package 15 00:00:36,532 --> 00:00:40,190 [No Audio] 16 00:00:40,190 --> 00:00:41,940 and a data package. 17 00:00:41,940 --> 00:00:43,959 [No Audio] 18 00:00:43,959 --> 00:00:45,856 So inside the web package, this is 19 00:00:45,856 --> 00:00:48,054 going to be the presentation layer. 20 00:00:48,054 --> 00:00:50,080 So our LoginController goes in there. 21 00:00:50,080 --> 00:00:53,210 [No Audio] 22 00:00:53,210 --> 00:00:55,085 There it is, 23 00:00:55,085 --> 00:00:57,826 inside our service layer, 24 00:00:57,826 --> 00:01:00,298 which is underneath the presentation layer. 25 00:01:00,298 --> 00:01:01,902 Our authentication service is going to 26 00:01:01,916 --> 00:01:05,214 exist, to put that in there. 27 00:01:05,214 --> 00:01:09,702 And finally, underneath that, we have our data layer, 28 00:01:09,702 --> 00:01:14,010 and that's where our repository class is going to exist. 29 00:01:14,010 --> 00:01:16,770 [No Audio] 30 00:01:16,770 --> 00:01:18,168 So web request will come into the 31 00:01:18,168 --> 00:01:20,222 LoginController and the presentation layer. 32 00:01:20,222 --> 00:01:21,863 That controller will then delegate to the 33 00:01:21,863 --> 00:01:24,079 AuthenticationService in the service layer that's 34 00:01:24,079 --> 00:01:26,346 responsible for implementing the business logic 35 00:01:26,346 --> 00:01:29,746 of the application. And the business logic here in this 36 00:01:29,746 --> 00:01:31,817 case is knowing how to authenticate 37 00:01:31,817 --> 00:01:33,924 the user by expecting that the password of a 38 00:01:33,924 --> 00:01:37,478 user is equal to the password ended by a user. 39 00:01:37,478 --> 00:01:39,336 That's the business logic there. 40 00:01:39,336 --> 00:01:42,072 And then in turn, because this service class 41 00:01:42,072 --> 00:01:43,836 shouldn't know anything about the database or the 42 00:01:43,836 --> 00:01:47,196 persistent aspect of the application, there'll be a 43 00:01:47,196 --> 00:01:50,256 UserRepository object or class rather, which is 44 00:01:50,256 --> 00:01:53,064 in the data layer, and that specializes in 45 00:01:53,064 --> 00:01:56,054 knowing how to retrieve users from whatever persistent 46 00:01:56,054 --> 00:01:57,920 store that happens to be in the application. 47 00:01:57,920 --> 00:01:59,546 So here we're just using a map, and that's 48 00:01:59,546 --> 00:02:02,124 fine for demo purposes, but in general, you'd have 49 00:02:02,124 --> 00:02:05,070 some form of relational database system there, so. 50 00:02:05,070 --> 00:02:08,340 So for example, some JDBC logic to access 51 00:02:08,340 --> 00:02:11,066 my SQL or H2, or a Spring 52 00:02:11,078 --> 00:02:13,548 based JPArepository, that kind of thing. 53 00:02:13,548 --> 00:02:15,131 But let's not get into that now, 54 00:02:15,131 --> 00:02:17,219 all we're concerned with is the fact that we've got 55 00:02:17,219 --> 00:02:22,452 these three classes in separate layers, each one doing 56 00:02:22,452 --> 00:02:25,248 their little bit to be able to code this particular 57 00:02:25,248 --> 00:02:28,014 scenario, this particular use case of logging a user 58 00:02:28,014 --> 00:02:30,744 in. So now we've got that set up, and thanks 59 00:02:30,744 --> 00:02:31,992 for bearing with us while we did that. 60 00:02:31,992 --> 00:02:33,744 But I think it's important to go through the 61 00:02:33,744 --> 00:02:35,724 classes that we have and how they're related, because 62 00:02:35,724 --> 00:02:37,584 it relates to how we'll interact with them from 63 00:02:37,584 --> 00:02:38,688 a Mockito point of view. 64 00:02:38,688 --> 00:02:40,236 Now we've got set up, we're going to look at 65 00:02:40,236 --> 00:02:42,386 how we can actually start writing unit tests 66 00:02:42,386 --> 00:02:44,700 in Mockito itself, which will be in the next videos.