Skip to Main Content
MOCKITO COOKBOOK
book

MOCKITO COOKBOOK

by Marcin Grzejszczak
June 2014
Intermediate to advanced content levelIntermediate to advanced
284 pages
6h 9m
English
Packt Publishing
Content preview from MOCKITO COOKBOOK

Creating partial mocks of final classes with delegatesTo()

The previous recipe showed an example of working with code that is not very trivial to mock. The obstacles might be as follows:

  • There are cases where the classes to mock are final
  • The object to be mocked is an already proxied object (Mockito will have issues with dealing with those)

The main feature described in this recipe focuses on the process of delegation of a method execution from a method of the implemented interface to the instantiated class (as you can see, there is a catch – the class to be mocked needs to implement an interface). As a reminder, you should have very legitimate reasons to use a partial mock in your code. Otherwise, it most likely signifies that there is something ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mockito Essentials

Mockito Essentials

Sujoy Acharya
Mockito for Spring

Mockito for Spring

Sujoy Acharya
SPRING COOKBOOK

SPRING COOKBOOK

Jerome Jaglale, Murat Yilmaz

Publisher Resources

ISBN: 9781783982745Supplemental Content