GetEnvironmentsUtilImpl implements GetEnvironmentsUtil { @NotNull @Override public RunnerEnvironmentTree getRunnerCategoryByProjectType(@NotNull RunnerEnvironmentTree tree, @NotNull String projectType) { ProjectTypeDefinition definition = projectTypeRegistry.getProjectType(projectType); List<String> categories = definition.getRunnerCategories(); if (categories == null || categories.isEmpty()) { return tree; } String category = categories.get(0); tree.setDisplayName(category); RunnerEnvironmentTree categoryNode = tree.getNode(category.toLowerCase()); if (categoryNode == null) { return tree; } return categoryNode; } @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 allTreeShouldBeReturnedByProjectTypeIfThisProjectTypeIsNotExist() { when(tree.getNode(CATEGORY1.toLowerCase())).thenReturn(null); RunnerEnvironmentTree result = util.getRunnerCategoryByProjectType(tree, PROJECT_TYPE); verify(projectTypeRegistry).getProjectType(PROJECT_TYPE); verify(definition).getRunnerCategories(); verify(tree).setDisplayName(CATEGORY1); verify(tree).getNode(CATEGORY1.toLowerCase()); assertThat(result, is(tree)); }
@Test public void nodeForProjectTypeShouldBeReturned() { RunnerEnvironmentTree result = util.getRunnerCategoryByProjectType(tree, PROJECT_TYPE); verify(projectTypeRegistry).getProjectType(PROJECT_TYPE); verify(definition).getRunnerCategories(); verify(tree).setDisplayName(CATEGORY1); verify(tree).getNode(CATEGORY1.toLowerCase()); assertThat(result, is(runnerEnvTree6)); }