HOW TO MOCK getProperty(string)
方法,引用是使用JMockit的私有静态字段.........
[...]
private static LWPropertyResource props = null;
props = LWSupportFactoryImpl.getInstance().getPropertyResource(VALIDATE_HANDLER_PROPS);
,
endDate = props.getProperty("endDate");
[...]
答案 0 :(得分:2)
声明所需类型的模拟字段或模拟参数,并记录您需要的期望:
@Test
public someTest(@Mocked final LWPropertyResource res)
{
final Date endDate = new Date();
new NonStrictExpectations() {{
res.getProperty("endDate"); result = endDate;
}};
// Call the code under test.
}