ProjectProblemDialogPresenter implements ProjectProblemDialogView.ActionDelegate { public void showDialog(@Nullable List<SourceEstimation> sourceEstimationList, @NotNull ProjectProblemDialogCallback callback) { this.callback = callback; if (sourceEstimationList == null || sourceEstimationList.isEmpty()) { estimatedTypes = null; view.showDialog(null); return; } estimatedTypes = new ArrayList<>(sourceEstimationList.size()); List<String> estimatedTypeNames = new ArrayList<>(sourceEstimationList.size()); for (SourceEstimation estimatedType : sourceEstimationList) { ProjectTypeDefinition projectType = projectTypeRegistry.getProjectType(estimatedType.getType()); if (estimatedType.isPrimaryable() && projectType != null) { this.estimatedTypes.add(estimatedType); estimatedTypeNames.add(projectType.getDisplayName()); } } view.showDialog(estimatedTypeNames); } @Inject  ProjectProblemDialogPresenter(final @NotNull ProjectProblemDialogView view,
                                         final ProjectTypeRegistry projectTypeRegistry,
                                         final CoreLocalizationConstant localizedConstant); void showDialog(@Nullable List<SourceEstimation> sourceEstimationList, @NotNull ProjectProblemDialogCallback callback); @Override void onOpenAsIs(); @Override void onOpenAs(); @Override void onConfigure(); @Override void onEnterClicked(); @Override void onSelectedTypeChanged(String projectType);  }
@Test public void setCallbackTest() throws Exception { presenter.showDialog(null, callback); assertNotNull(presenter.callback); }
@Test public void showDialogWhenProjectTypesListIsNull() throws Exception { presenter.showDialog(null, callback); verify(view).showDialog(isNull(List.class)); verify(projectTypeRegistry, never()).getProjectType(anyString()); }
@Test public void showDialogWhenProjectTypeIsNotPrimaryable() throws Exception { List<SourceEstimation> list = new ArrayList<>(1); SourceEstimation sourceEstimation = mock(SourceEstimation.class); list.add(sourceEstimation); when(sourceEstimation.getType()).thenReturn(MAVEN_PROJECT_TYPE); presenter.showDialog(list, callback); verify(view).showDialog(isNotNull(List.class)); assertTrue(presenter.estimatedTypes.isEmpty()); verify(projectTypeRegistry).getProjectType(eq(MAVEN_PROJECT_TYPE)); }
@Test public void showDialogWhenProjectTypeIsPrimaryable() throws Exception { List<SourceEstimation> list = new ArrayList<>(1); SourceEstimation sourceEstimation = mock(SourceEstimation.class); list.add(sourceEstimation); when(sourceEstimation.getType()).thenReturn(MAVEN_PROJECT_TYPE); when(sourceEstimation.isPrimaryable()).thenReturn(true); when(projectTypeRegistry.getProjectType(MAVEN_PROJECT_TYPE)).thenReturn(mock(ProjectTypeDefinition.class)); presenter.showDialog(list, callback); verify(projectTypeRegistry).getProjectType(eq(MAVEN_PROJECT_TYPE)); verify(view).showDialog(isNotNull(List.class)); assertFalse(presenter.estimatedTypes.isEmpty()); assertEquals(1, presenter.estimatedTypes.size()); }