Java – how to simulate object getClass?
I'm developing a java project and want to create one for dto Write a unit test using the equals method Yes In the equals method, called by the tested object Getclass() method I want to laugh at this, but I don't know what type of object it wants I tried,
. When (mockroominv. Getclass()) thenreturn (roominv.class);
But I didn't do anything What is the return type of getClass and how to operate it?
Solution
Object. GetClass () is the final method, so you can't simulate it with mockito
You can simulate static and final methods (so on), and even use powermock's private method (which is a very cool tool);
http://code.google.com/p/powermock/
You can use it with mockito as follows:
http://code.google.com/p/powermock/wiki/MockitoUsage13
You will find some useful examples there