我有一个具有以下构造函数的类:
class Foo {
Foo (Bar bar) {
...
}
}
我正在尝试为这个类编写一个单元测试,然后模拟出对Bar的依赖。但是,我必须使用 JUnit 3 和 Bar是具体类型。有没有人有任何想法?我不能使用EasyMock类扩展(需要JUnit 4)并且没有使用Mockito。我正在考虑的一个(特别难看的)解决方案如下:
interface IBarWrapper {
void barMethod();
}
class BarWrapper implements IBarWrapper {
void barMethod() {
bar.barMethod();
}
}
class Foo {
Foo (IBarWrapper wrapper) {
...
}
}
但我不喜欢改变我的实际代码以适应测试的想法。