Mockito: Mock object based on another
java, mocking, mockito, unit-testing
Solution
What about creating a private method in your test that sets the common expectations on a given mock object?
Problem
I have a mocked object, say `Car porsche`. It has 4 wheels, 1 windscreen,1 engine and name Porsche. This is done via `when()` and `thenReturn()`. I want to create another mocked Car instance, say trabant, that will behave (again `when()` and `thenReturn()`) exactly as the porsche instance, only will return a different name. Is it possible to create the 2nd mock based on the 1st one without repeating all the `when()` and `thenReturn()` steps?