Reputation: 1376
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?
Upvotes: 12
Views: 4568
Reputation: 3694
What about creating a private method in your test that sets the common expectations on a given mock object?
Upvotes: 7