Skip to main content

Posts

Showing posts from April, 2013

JMockit : passing the mock variable

We had a really long interface, that needed to be mocked. One class's contructor had this interface object as an argument. With my traditional mocking approach, I would have written a @Mockclass that implements this interface, @Mock only the required method, and leave other methods unimplemented. Create a new instance of this mocked class. But that looked like BIG non required code. @Injectable to rescue JMockit have @Injectable annotation that you pass to test method as a parameter and define the Expectation. And thats it. Here is the code snippet