You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProjectExportComputationStepsTest.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  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.
  10. *
  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.
  15. *
  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.
  19. */
  20. package org.sonar.ce.task.projectexport;
  21. import com.google.common.collect.Lists;
  22. import org.junit.Test;
  23. import org.sonar.ce.task.container.TaskContainer;
  24. import org.sonar.ce.task.container.TaskContainerImpl;
  25. import org.sonar.ce.task.projectanalysis.step.ComplexityMeasuresStep;
  26. import org.sonar.ce.task.projectexport.steps.LoadProjectStep;
  27. import org.sonar.core.platform.ComponentContainer;
  28. import static com.google.common.collect.ImmutableList.copyOf;
  29. import static org.assertj.core.api.Assertions.assertThat;
  30. import static org.assertj.core.api.Assertions.assertThatThrownBy;
  31. import static org.mockito.Mockito.mock;
  32. public class ProjectExportComputationStepsTest {
  33. private TaskContainer container = mock(TaskContainer.class);
  34. private ProjectExportComputationSteps underTest = new ProjectExportComputationSteps(container);
  35. @Test
  36. public void count_step_classes() {
  37. assertThat(copyOf(underTest.orderedStepClasses())).hasSize(20);
  38. }
  39. @Test
  40. public void instances_throws_ISE_if_steps_do_not_exist_in_container() {
  41. assertThatThrownBy(() -> copyOf(underTest.instances()))
  42. .isInstanceOf(IllegalStateException.class)
  43. .hasMessage("Component not found: " + LoadProjectStep.class);
  44. }
  45. @Test
  46. public void instances_throws_ISE_if_container_does_not_have_second_step() {
  47. assertThatThrownBy(() -> {
  48. final ComplexityMeasuresStep reportExtractionStep = mock(ComplexityMeasuresStep.class);
  49. ComponentContainer componentContainer = new ComponentContainer() {
  50. {
  51. addSingleton(reportExtractionStep);
  52. }
  53. };
  54. TaskContainerImpl computeEngineContainer = new TaskContainerImpl(componentContainer, container -> {
  55. // do nothing
  56. });
  57. Lists.newArrayList(new ProjectExportComputationSteps(computeEngineContainer).instances());
  58. })
  59. .isInstanceOf(IllegalStateException.class)
  60. .hasMessage("Component not found: class org.sonar.ce.task.projectexport.steps.LoadProjectStep");
  61. }
  62. }