[No Audio]
In this video, we're going to tidy things
up a little bit by separating out our classes
into packages corresponding to the different layers.
Just keep things nice and tidy.
So let's explore that now.
So in here now we've got a reasonably
fair representation of simple piece of a web
application which we might have in production.
So quick recap then, actually let's split them into
the proper packages as well while we're at it.
So there's going to be a web package,
[No Audio]
there's going to be a service package
[No Audio]
and a data package.
[No Audio]
So inside the web package, this is
going to be the presentation layer.
So our LoginController goes in there.
[No Audio]
There it is,
inside our service layer,
which is underneath the presentation layer.
Our authentication service is going to
exist, to put that in there.
And finally, underneath that, we have our data layer,
and that's where our repository class is going to exist.
[No Audio]
So web request will come into the
LoginController and the presentation layer.
That controller will then delegate to the
AuthenticationService in the service layer that's
responsible for implementing the business logic
of the application. And the business logic here in this
case is knowing how to authenticate
the user by expecting that the password of a
user is equal to the password ended by a user.
That's the business logic there.
And then in turn, because this service class
shouldn't know anything about the database or the
persistent aspect of the application, there'll be a
UserRepository object or class rather, which is
in the data layer, and that specializes in
knowing how to retrieve users from whatever persistent
store that happens to be in the application.
So here we're just using a map, and that's
fine for demo purposes, but in general, you'd have
some form of relational database system there, so.
So for example, some JDBC logic to access
my SQL or H2, or a Spring
based JPArepository, that kind of thing.
But let's not get into that now,
all we're concerned with is the fact that we've got
these three classes in separate layers, each one doing
their little bit to be able to code this particular
scenario, this particular use case of logging a user
in. So now we've got that set up, and thanks
for bearing with us while we did that.
But I think it's important to go through the
classes that we have and how they're related, because
it relates to how we'll interact with them from
a Mockito point of view.
Now we've got set up, we're going to look at
how we can actually start writing unit tests
in Mockito itself, which will be in the next videos.