mardi 27 novembre 2018

Superclass method is invoked by Mockito mocked object

I have the following classes:

class A {
    protected void methodA() {
    }
}

class B extends A {
    void methodB() {}
}

class C {
    private B b;

    C(B b) {
        this.b = b;
    }

    void someMethod() {
        b.methodA();
    }
}

I am writing a test for C where B is mocked.

@Mock
B b;

@Test
public void testSomeMethod() {
    C c = new C(b);
    c.someMethod();
}

Strangely, the methodA is called during this test. I even tried doNothing on the call but invocation still happens. I would like to mock B and all its inherited methods. How can I do that?

Aucun commentaire:

Enregistrer un commentaire