GetEnvironmentsUtilImpl implements GetEnvironmentsUtil { @Override @NotNull public String getType() { CurrentProject currentProject = appContext.getCurrentProject(); if (currentProject == null) { return ""; } ProjectDescriptor descriptor = currentProject.getProjectDescription(); String defaultRunner = currentProject.getRunner(); if (defaultRunner == null || defaultRunner.startsWith(DEFAULT_RUNNER_PROJECT_TYPE)) { ProjectTypeDefinition definition = projectTypeRegistry.getProjectType(descriptor.getType()); List<String> categories = definition.getRunnerCategories(); if (categories == null || categories.isEmpty()) { return BLANK_TYPE; } return categories.get(0); } else { return getCorrectCategoryName(defaultRunner); } } @Inject  GetEnvironmentsUtilImpl(ModelsFactory modelsFactory, ProjectTypeRegistry projectTypeRegistry, AppContext appContext); @NotNull @Override List<RunnerEnvironmentLeaf> getAllEnvironments(@NotNull RunnerEnvironmentTree tree); @NotNull @Override List<Environment> getEnvironmentsFromNodes(@NotNull List<RunnerEnvironmentLeaf> leaves, @NotNull Scope scope); @NotNull @Override List<Environment> getEnvironmentsByProjectType(@NotNull RunnerEnvironmentTree tree,
                                                          @NotNull String projectType,
                                                          @NotNull Scope scope); @Override @NotNull String getType(); @NotNull @Override String getCorrectCategoryName(@NotNull String defaultRunner); @NotNull @Override RunnerEnvironmentTree getRunnerCategoryByProjectType(@NotNull RunnerEnvironmentTree tree, @NotNull String projectType);  }
@Test public void emptyStringShouldBeReturnedWhenCurrentProjectIsNull() throws Exception { when(appContext.getCurrentProject()).thenReturn(null); String projectType = util.getType(); assertThat(projectType.isEmpty(), is(true)); }
@Test public void blankTypeShouldBeReturnedForBlank() throws Exception { when(currentProject.getRunner()).thenReturn(null); when(descriptor.getType()).thenReturn(BLANK_TYPE); when(projectTypeRegistry.getProjectType(BLANK_TYPE)).thenReturn(definition); when(definition.getRunnerCategories()).thenReturn(Collections.<String>emptyList()); String projectType = util.getType(); assertEquals("blank", projectType); }
@Test public void typeFromRunnerCategoryShouldBeReturnedWhenDefaultRunnerIsNull() throws Exception { when(definition.getRunnerCategories()).thenReturn(Arrays.asList(SOME_TEXT)); when(descriptor.getType()).thenReturn(SOME_TEXT); when(projectTypeRegistry.getProjectType(SOME_TEXT)).thenReturn(definition); when(currentProject.getRunner()).thenReturn(null); String type = util.getType(); assertThat(type, equalTo(SOME_TEXT)); }
@Test public void typeFromRunnerCategoryShouldBeReturnedWhenDefaultRunnerIsNotNull() throws Exception { when(currentProject.getRunner()).thenReturn("text/text/text"); String type = util.getType(); assertThat(type, equalTo("text")); }