Is it possible to both mock an abstract class and inject it with mocked classes using Mockito annotations. I now have the following situation:
@Mock private MockClassA mockClassA;
@Mock private MockClassB mockClassB;
@Mock(answer = Answers.CALLS_REAL_METHODS) private AbstractClassUnderTest abstractClassUnderTest;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
Whitebox.setInternalState(abstractClassUnderTest, mockClassA);
Whitebox.setInternalState(abstractClassUnderTest, mockClassB);
}
I'd like to use something like @InjectMocks on AbstractClassUnderTest but it can't be used in combination with @Mock. The current situation, with Whitebox from Powermock, works but I'm curious if it's possible to solve it with just annotations. I couldn't find any solutions or examples.
(I know about the objections to test abstract classes and I'd personally rather test a concrete implementation and just use @InjectMocks.)
Aucun commentaire:
Enregistrer un commentaire