Book Image

Mastering Unit Testing Using Mockito and JUnit

By : Sujoy Acharya
Book Image

Mastering Unit Testing Using Mockito and JUnit

By: Sujoy Acharya

Overview of this book

Table of Contents (17 chapters)
Mastering Unit Testing Using Mockito and JUnit
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Dummy


An example of a dummy would be a movie scene where the double doesn't perform anything but is only present on the screen. They are used when the actual actor is not present, but their presence is needed for a scene, such as watching the tennis finale of a US Open match.

Similarly, dummy objects are passed to avoid NullPointerException for mandatory parameter objects as follows:

Book javaBook = new Book("Java 101", "123456");
Member dummyMember = new DummyMember());
javaBook.issueTo(dummyMember);
assertEquals(javaBook.numberOfTimesIssued(),1);

In the preceding code snippet, a dummy member was created and passed to a book object to test whether a book can report the number of times it was issued. Here, a member object is not used anywhere but it's needed to issue a book.