Introduction
As presented in previous chapters, Mockito is all about creating mocks and stubbing their behavior. In comparison to the previous chapter, which focused on mocks, in this chapter we will take a look at partial mocks, also known as spies. Spies are mocks that by default call real implementations. Additionally, you can also perform verification on such objects.
Remember that usually you shouldn't have the need to create a spy. You might want to create a spy as an exception to the rule because partial mocks do not fit into the paradigm of single responsibility—the S from SOLID principles that we described in depth in Chapter 2, Creating Mocks. In other words, you should only use that technique when there is no other option. If you need to create a partial mock and stub a part of its logic, it most likely means that your architecture is wrong. In the vast majority of cases, for a new, well designed, test-driven system, there should be no need to create spies. I encourage...