如何解决在EasyMock中模拟期望值的参数失败
我有一个实现接口的类和一个采用另一个接口的方法。我想从该参数模拟方法调用;但是,结果为空。
public class LoginAction implements IServerAction {
private static final int HTTP_OK_STATUS = 200;
@Override
public void execute(IServerExchange exchange) throws Exception {
URI uri = exchange.getRequestURI();
exchange.setStatus(HTTP_OK_STATUS);
GeneralHelper.encrypt('some text');
}
这是我的考试:
@PrepareForTest({GeneralHelper.class})
@RunWith(powermockrunner.class)
public class LoginActionTest {
@Before
public void setUp() throws Exception {
loginAction = new LoginAction();
iServerExchange = createMock(IServerExchange.class);
}
@Test
public void testExecute_userExistsInscoreList_success() throws Exception {
expect(iServerExchange.getRequestURI()).andReturn(new URI("/254/login"));
expect(GeneralHelper.encrypt('some text').andReturn('my test');
loginAction.execute(iServerExchange);
}
在测试中uri为空。另外,作为最终类的GeneralHelper并没有完全被嘲笑,因为我希望返回一个值。
解决方法
在调用main方法之前,我应该已经考虑过重播方法。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。