mercredi 27 mai 2015

JUnit - Return a mocked object from a type cast

My code looks something like this:

ClassB objB = (ClassB) objA;
int z = objB.ClassBMethod();

int y = objA.ClassAMethod();

Currently my unit test looks like this:

ClassA mockClassA = mock(ClassA.class);
when(mockClassA.ClassAMethod()).thenReturn(1);

How would I mock objA's cast to ClassB so that I can mock the ClassBMethod()?

Aucun commentaire:

Enregistrer un commentaire