I have the following code:
public Object parse(){
....
VTDGen vg = new VTDGen();
boolean parsed = vg.parseFile(myFile.getAbsolutePath(), false);
}
I am writing a unit test for this method. When I run the method without mocking VTDGen
the parseFile
method returns true
. However, when I mock it with a spy, it returns false
.
My test is as follows:
@Before
public void setup(){
VTDGen vtgGen = new VTDGen();
VTDGen vtgGenSpy = PowerMockito.spy(vtdGen);
PowerMockito.whenNew(VTDGen.class).withNoArguments().thenReturn(vtdGenSpy);
}
@Test
public void myTest(){
// when I run the test parseFile returns false
// if I remove the mocking in the setup, parseFile returns true
}
I was under the impression that Mockito's spy objects should not change the behavior of wrapped objects, so why am I getting false instead of true?