I can't get Mockito to override a method in the class I am testing.
@Test
public void test_classToTest() throws Exception {
DependencyA dependencyA = mock(DependencyA.class);
DependencyB dependencyB = mock(DependencyB.class);
DependencyC dependencyC = mock(DependencyC.class);
ClassToTest classToTest = ClassToTest.builder().dependencyA(dependencyA)
.dependencyB(dependencyB).dependencyC(dependencyC).build();
classToTest= Mockito.spy(classToTest);
Mockito.doReturn("This is not the method you are looking for").when(classToTest).storeContent(null, null, null);
String result = classToTest.copyContent(someVariable, SOME_CONSTANT);
The method I am trying to override is classToTest.storeContent() which is called from inside classToTest.copyContent(). I am aware that this class is a little smelly, but I am not in a position to refactor it. However, this is not a very complicated setup and I am not sure why the actual .storeContent() method is getting called.
Aucun commentaire:
Enregistrer un commentaire