mardi 3 janvier 2017

Creating mock with Mockito for class that extends generic class

Hi guys I'm having trouble creating a mock. Here is the code:

The class that I am trying to mock:

public class MyClass extends BaseClass<ClassView>{
    //code goes here
}

On the test:

MyClass mockMyClass;

@Test
public void setUp(){
    mockMyClass = mock(MyClass.class);
}

Also tried:

@Mock MyClass mockMyClass;

@Test
public void setUp(){
    MockitoAnnotations.initMocks(this)
}

The error:

org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class com.packageName.MyClass

Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.

I'm thinking there is an issue when creating a mock for a class that extends a class with generic parameters. Can someone point me in the right direction?

Aucun commentaire:

Enregistrer un commentaire