How to mock using Mockito and JUnit4

This post is about how to make a JUnit test with mocks.

The important questions are:
1. Why we need mocks?
2. Why we need to mock something?
3. What that even means?

The answers:
1. We need mocks to simulate behavior of other objects.
2. We mock something, because we need to create a specific behavior and then control it.
3. Usually, you mock an object that belong to a class and is use in another class, so in our example, a specific Service will use a specific DAO, but we try to test the service, so actually seems that we don’t need the DAO, but we can’t test the Service without it, so the solution is Mock it. In other words, fake the behavior of DAO and tell him to do/return what you want.

Now, let’s mock something!

Read More »

Hello World!

This is my very first post. I use it to tell that this blog is about coding, mainly java and frameworks that works quite well with Java. Why I started this ?! The answer is easy, I was looking for some tutorials about newest frameworks and I didn’t find some useful. So, somehow, I manage to make and test some didactic programs and I don’t want anyone else to spend so much time like me to find how some new versions of frameworks can be implemented and integrated with what you want.

Happy coding!