我有下面这个类:
public class MyClass {
private Apple apple;
public void myMethod() {
apple = AppleFactory.createInstance(someStringVariable);
....
....
....
}
}
还有测试类:
@RunWith(MockitoJUnitRunner.class)
public class MyClassTest {
@InjectMocks
MyClass myClass;
@Test
public void myMethod(){
...
...
...
}
}
我该如何将一个苹果实例注入到MyClass中作为模拟对象?
public abstract class AppleFactory { public abstract Apple createInstance(final String str); } public class AppleFactoryImpl extends AppleFactory { public Apple createInstance(final String str) { // Implementation } }
- ugurkocak1980