【发布时间】:2015-04-25 10:22:40
【问题描述】:
考虑这个例子
resp.getWriter().write(Collections.singletonMap("path", file.getAbsolutePath()).toString());
其中resp 是HttpServletResponse 并被模拟。
我正在使用 JMock Mockery 来模拟这些
我的代码看起来像
try {
atLeast(1).of(resp).getWriter().write(String.valueOf(any(String.class)));
} catch (IOException e) {
e.printStackTrace();
}
will(returnValue("Hello"));
当我运行它时,我得到了
java.lang.NullPointerException
我相信这是因为 getWriter() 没有发回任何东西
我该如何处理这种情况?
【问题讨论】:
-
只是你的模拟的 getWriter() 应该返回一个作家的模拟
标签: java unit-testing junit mockito jmock