日期:2014-05-20 浏览次数:21182 次
public interface MyInterface {
public String getName();
}
public class B implements MyInterface {
...
}
public class BB implements MyInterface {
...
}
------解决方案--------------------
mockito http://mockito.org/
//You can mock concrete classes, not only interfaces
LinkedList mockedList = mock(LinkedList.class);
//stubbing
when(mockedList.get(0)).thenReturn("first");
when(mockedList.get(1)).thenThrow(new RuntimeException());
------解决方案--------------------
可以通过classloader来加载Mock类B,让Mock类B屏蔽掉实际的类B
------解决方案--------------------
new A(new B())...