3 * Copyright (C) 2009-2022 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.ce.task.projectexport;
22 import com.google.common.base.Predicate;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.stream.Collectors;
27 import java.util.stream.StreamSupport;
28 import org.junit.Test;
29 import org.picocontainer.PicoContainer;
30 import org.sonar.ce.task.container.TaskContainer;
31 import org.sonar.ce.task.projectexport.taskprocessor.ProjectDescriptor;
32 import org.sonar.ce.task.setting.SettingsLoader;
33 import org.sonar.ce.task.step.ComputationStep;
34 import org.sonar.core.platform.ComponentContainer;
36 import static org.assertj.core.api.Assertions.assertThat;
38 public class ProjectExportContainerPopulatorTest {
40 private static final int COMPONENTS_BY_DEFAULT_IN_CONTAINER = 2;
42 private final ProjectDescriptor descriptor = new ProjectDescriptor("project_uuid", "project_key", "Project Name");
43 private final ProjectExportContainerPopulator underTest = new ProjectExportContainerPopulator(descriptor);
46 public void test_populateContainer() {
47 RecorderTaskContainer container = new RecorderTaskContainer();
48 underTest.populateContainer(container);
49 assertThat(container.addedComponents)
50 .hasSize(COMPONENTS_BY_DEFAULT_IN_CONTAINER + 8)
51 .contains(descriptor, SettingsLoader.class);
54 private static class RecorderTaskContainer implements TaskContainer {
55 private final List<Object> addedComponents = new ArrayList<>();
58 public ComponentContainer add(Object... objects) {
59 addedComponents.addAll(Arrays.asList(objects));
65 public ComponentContainer addSingletons(Iterable<?> components) {
66 List<Object> filteredComponents = StreamSupport.stream(components.spliterator(), false)
67 .filter((Predicate<Object>) input -> !(input instanceof Class) || !ComputationStep.class.isAssignableFrom((Class<?>) input))
68 .collect(Collectors.toList());
70 addedComponents.addAll(filteredComponents);
76 public ComponentContainer getParent() {
77 throw new UnsupportedOperationException("getParent is not implemented");
81 public void bootup() {
82 throw new UnsupportedOperationException("bootup is not implemented");
87 throw new UnsupportedOperationException("close is not implemented");
91 public PicoContainer getPicoContainer() {
92 throw new UnsupportedOperationException("getParent is not implemented");
96 public <T> T getComponentByType(Class<T> type) {
97 throw new UnsupportedOperationException("getParent is not implemented");
101 public <T> List<T> getComponentsByType(final Class<T> type) {
102 throw new UnsupportedOperationException("getParent is not implemented");