gpt4 book ai didi

java - mock - 意外的期望 - 不知道我做错了什么

转载 作者:行者123 更新时间:2023-12-02 13:37:00 25 4
gpt4 key购买 nike

我有一个具有以下接口(interface)的服务:

public interface accountsService {

public accountRemovalModel purgeAccounts();
}

我必须遵循测试类(class):

我有一个具有以下接口(interface)的服务:

public interface AccountsService {

public accountRemovalModel purgeAccounts();
}

我必须遵循测试类(class):

public class AccountsServiceTest extends BaseTestClass {

private Mockery _m = new Mockery() {
{
setImposteriser(ClassImposteriser.INSTANCE);
}};


private accountsService _accountsService;

@Before
public void beforeTests() throws Exception {

accountsService = _m.mock(AccountsService.class);
}

@Test
public void testNoItemsToDeleteSuccess() throws Exception {

// Return a simple AccountsRemovalModel
// APPARENTLY THIS EXPECTATION IS UNEXPECTED?
_m.checking(new Expectations() {{

allowing(accountsService.purgeAccounts());
will(returnValue(new accountRemovalModel(0,0)));
}});

accountsRemovalModel result = accountsService.purgeAccounts();

Assert.assertEquals(0, result.getDeleteCount());
Assert.assertEquals(0, result.getTotalCount());
}
}

我收到以下错误:

AccountsServiceTest.testNoItemsToDeleteSuccess:23 » 预期意外...

非常感谢任何有关此问题的帮助 - 因为我在使其正常工作方面遇到了很大的问题!

最佳答案

您的语法稍有偏差 - 您需要在被模拟的对象周围加上括号(accountsService):

    _m.checking(new Expectations() {{

allowing(accountsService).purgeAccounts();
will(returnValue(new accountRemovalModel(0,0)));
}});

关于java - mock - 意外的期望 - 不知道我做错了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42937153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com