I am writing JUnit for a class that references a legacy class via constructor. The legacy class is in a third party jar, so I can't refactor it to make life easier....
This is the class being tested...
public MyClass {
public String methodToTest(String param) {
LegacyClass legacy = new LegacyClass(param);
*..... etc ........*
}
}
This is what I am trying to do in the mockito JUnit.
public MyClassTest {
@Test
public void testMethodToTest() throws Exception {
LegacyClass legacyMock = mock(LegacyClass.class);
when(*the LegacyClass constructor with param is called*).thenReturn(legacyMock);
*.... etc.....*
}
}
Any ideas on how I can do this ?????