0

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;
}

谢谢你的帮助

4

1 回答 1

0

抱歉,这不是一个非常明确的问题,所以这是一个猜测:

您是否尝试过将您的匿名 ViewPageAction 变成一个适当的类?

// somewhere in your test class...
private static class DummyViewPageAction extends ViewPageAction {
    boolean isPageBookmarkedByUser(Page page, User user) { return true; }
    VisitPage visitPage() { return null; }
}

// start of your @Before method...
@Before
public void beforeEach() {
    action = new DummyViewPageAction();
    ...
于 2013-11-07T07:07:24.970 回答