2
我知道我有過最具異國情調的用例,但我非常喜歡測試,所以我想測試一下IHandler
是否按我的設想進行測試。問題是我無法弄清楚如何以編程方式調用它:從集成測試中調用處理程序
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
IWorkbenchWindow site = workbenchPage.getWorkbenchWindow();
Command command = ((ICommandService) site.getService(ICommandService.class)).getCommand(commandId);
final IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
final Event trigger = new Event(); // or trigger = null
ExecutionEvent executionEvent = service.createExecutionEvent(command, trigger);
command.executeWithChecks(executionEvent);
處理程序被調用,但ExecutionEvent
沒有正確填寫(例如返回空,即使我只是打開一個編輯器)。
如何以正確的方式以編程方式調用IHandler
?
你可以很明顯地從IHandlerService.getCurrentState()得到'IEvaluationContext' ...或者至少現在我的測試工作。 –