axn7975
axn7975

Reputation: 107

Mock interface in the test class

// Dao Interface
public Interface IDao {
    public void foo()
}

Mock interface in test class

Upvotes: 1

Views: 165

Answers (1)

Maciej Kowalski
Maciej Kowalski

Reputation: 26512

The myDao is a package level field so its available in the child class. In that case you can go for the standard Mockito injection of a mock:

@Mock
IDao daoMock;

@InjectMocks
MySubClass subclass;

@Before
public void init(){
  MockitoAnnotations.initMocks(this);
}

@Test
public void test(){
    subclass.toCreate();

    Mockito.verify(daoMock).create();
}

Upvotes: 1

Related Questions