ActiveFilePersistenceComponent implements PersistenceComponent { @Override public List<ActionDescriptor> getActions(String projectPath) { EditorAgent editorAgent = editorAgentProvider.get(); EditorPartPresenter activeEditor = editorAgent.getActiveEditor(); final List<ActionDescriptor> actions = new ArrayList<>(); if (activeEditor == null) { return Collections.emptyList(); } VirtualFile virtualFile = activeEditor.getEditorInput().getFile(); String openNodeActionId = actionManager.getId(openFileAction); actions.add(dtoFactory.createDto(ActionDescriptor.class) .withId(openNodeActionId) .withParameters(Collections.singletonMap(FILE_PARAM_ID, virtualFile.getPath()))); return actions; } @Inject  ActiveFilePersistenceComponent(Provider<EditorAgent> editorAgentProvider,
                                          ActionManager actionManager,
                                          OpenFileAction openFileAction,
                                          DtoFactory dtoFactory); @Override List<ActionDescriptor> getActions(String projectPath);  }
@Test public void shouldGetActions() { configureOpenedEditors(); configureActiveEditor(FILE2_PATH); ActionDescriptor action = mock(ActionDescriptor.class); when(action.withId(anyString())).thenReturn(action); when(action.withParameters(anyMapOf(String.class, String.class))).thenReturn(action); when(dtoFactory.createDto(eq(ActionDescriptor.class))).thenReturn(action); List<ActionDescriptor> actionDescriptors = component.getActions(PROJECT_PATH); verify(action).withId(anyString()); verify(action).withParameters(eq(Collections.singletonMap(FILE_PARAM_ID, FILE2_PATH))); assertEquals(1, actionDescriptors.size()); assertTrue(actionDescriptors.contains(action)); }
@Test public void shouldGetNoActionsWhenLastOpenedFileIsActive() { configureOpenedEditors(); List<ActionDescriptor> actionDescriptors = component.getActions(PROJECT_PATH); assertTrue(actionDescriptors.isEmpty()); }