sujan duminda
sujan duminda

Reputation: 31

Java constructor mockup

Could you please any one tell me How to mock up Java Constructor ? I tried as below. But it doesn't work.

new MockUp<UserCompanyDivision>()
{ 
    @Mock
    public UserCompanyDivision(String com, String div)
    {
    }    
};

Upvotes: 0

Views: 982

Answers (1)

Rog&#233;rio
Rog&#233;rio

Reputation: 16380

Since constructors don't have names like methods do, JMockit uses the special name "$init" for the corresponding @Mock methods. For example:

new MockUp<UserCompanyDivision>() {
    @Mock // matches a constructor having the same parameters
    void $init(String com, String div) {
        // ...
    }
};

Note that this is described in the API documentation for @Mock.

Upvotes: 2

Related Questions