Book Image

Learning Modular Java Programming

By : Tejaswini Mandar Jog
Book Image

Learning Modular Java Programming

By: Tejaswini Mandar Jog

Overview of this book

Modular programming means dividing an application into small parts and then developing it. It is an approach taken by developers to build applications and helps them add efficiency in their development process, thus making it more effective. The book starts with the fundamentals of Modular Programming. Then we move on to the actual implementation, where we teach developers how to divide an application into different modules or layers (such as presentation, execution, security, lifecycle, services, and so on) for better management. Once readers are well-versed in these modules and their development, the book shows how to create bindings in order to join these different modules and form a complete application. Next, the readers will learn how to manage these modules through dependency injection. Later, we move on to testing; readers will learn how to test the different modules of an application. The book ends by teaching readers how to maintain different versions of their application and how to modify it. By the end of the book, readers will have a good understanding of modular programming and will be able to use it to build applications with Java.
Table of Contents (15 chapters)

Mockito testing


Mockito is an open source framework used in conjunction with JUnit for testing. Mockito helps in creating Mock objects to be used while testing. Mockito tests help in reducing the tight coupling by removing the requirement of the expectation specification. Mockito creates mock objects with the static method mock() provided by the org.mockito.Mockito class. In Mockito, the when() method defines the action to be taken and then Return() returns the result of the action. When() can define a method call and thenReturn() is expected to return from the method. The when() accepts the argument of the method to be invoked and the result to be returned will be the argument of thenReturn(). when() accepts the method under testing and thenReturn() returns the result which we use for assertion. Methods such as anyString(), anyInt() are used to define independent values from the methods. Mockito can be used for behavioral testing as well. In behavior testing, a certain result is expected...