我Action
在单元测试代码中有一些匿名类。匿名类没有名字。Class#getSimpleName
返回""
。IndexOutOfBoundException
它在初始化约定插件时
导致。PackageBasedActionConfigBuilder#buildConfiguration
跳过所有接口、枚举、注释和抽象类。它也应该跳过匿名类。添加actionClass.isAnonymous()
到跳过条件。我的单元测试代码中有一些匿名的 Action 类。这不是好的设计。
private PageAction action;
@Before
public void beforeEach() {
action = new PageAction() {};
}
@Test
public void shouldAcceptAndPublicPageId() {
action.setPageId(1);
assertEquals(1, action.getRequestedPageId());
}
...
// To bypass complex logic in ViewPageAction
@Before
public void beforeEach() {
action = new ViewPageAction() {
boolean isPageBookmarkedByUser(Page page, User user) { return true; }
VisitPage visitPage() { return null; }
};
coreService = mockery.mock(CoreService.class);
action.setCoreService(coreService);
uiService = mockery.mock(UiService.class);
action.setUiService(uiService);
pageRepository = mockery.mock(PageRepository.class);
action.setPageRepository(pageRepository);
pageAttachmentRepository = mockery.mock(PageAttachmentRepository.class);
action.setPageAttachmentRepository(pageAttachmentRepository);
wiki = WikiTest.publicWiki();
action.setWiki(wiki);
User user = UserTest.FOO;
action.setUser(user);
}
@Test
public void success() {
final Page page = PageTest.FOO_PAGE;
final String text = "Content of the page";
final PageRevision latestRevision = MockPageRevision.FOO_REV2;
}
谢谢你的帮助