GetEnvironmentsUtilImpl implements GetEnvironmentsUtil { @NotNull @Override public List<Environment> getEnvironmentsFromNodes(@NotNull List<RunnerEnvironmentLeaf> leaves, @NotNull Scope scope) { Set<Environment> sortEnvironment = new TreeSet<>(); for (RunnerEnvironmentLeaf environmentLeaf : leaves) { Environment environment = modelsFactory.createEnvironment(environmentLeaf.getEnvironment(), scope); sortEnvironment.add(environment); } return new ArrayList<>(sortEnvironment); } @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 environmentsFromNodeShouldBeReturned() { Environment environment1 = mock(Environment.class); Environment environment2 = mock(Environment.class); RunnerEnvironment runnerEnv1 = mock(RunnerEnvironment.class); RunnerEnvironment runnerEnv2 = mock(RunnerEnvironment.class); when(runnerEnvLeaf1.getEnvironment()).thenReturn(runnerEnv1); when(runnerEnvLeaf2.getEnvironment()).thenReturn(runnerEnv2); when(modelsFactory.createEnvironment(runnerEnv1, SYSTEM)).thenReturn(environment1); when(modelsFactory.createEnvironment(runnerEnv2, SYSTEM)).thenReturn(environment2); when(environment1.compareTo(environment2)).thenReturn(1); when(environment2.compareTo(environment1)).thenReturn(2); List<Environment> result = util.getEnvironmentsFromNodes(Arrays.asList(runnerEnvLeaf1, runnerEnvLeaf2), SYSTEM); assertThat(result.size(), is(2)); assertThat(result, hasItems(environment1, environment2)); verify(modelsFactory).createEnvironment(runnerEnv1, SYSTEM); verify(modelsFactory).createEnvironment(runnerEnv2, SYSTEM); }