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.

PostJobExtensionDictionnaryTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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.scanner.bootstrap;
  21. import org.junit.Before;
  22. import org.junit.Test;
  23. import org.sonar.api.batch.Phase;
  24. import org.sonar.api.batch.postjob.PostJob;
  25. import org.sonar.api.batch.postjob.PostJobContext;
  26. import org.sonar.api.batch.postjob.PostJobDescriptor;
  27. import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor;
  28. import org.sonar.api.batch.sensor.Sensor;
  29. import org.sonar.api.batch.sensor.SensorContext;
  30. import org.sonar.api.batch.sensor.SensorDescriptor;
  31. import org.sonar.core.platform.ComponentContainer;
  32. import org.sonar.scanner.postjob.PostJobOptimizer;
  33. import static org.assertj.core.api.Assertions.assertThat;
  34. import static org.mockito.ArgumentMatchers.any;
  35. import static org.mockito.Mockito.mock;
  36. import static org.mockito.Mockito.when;
  37. public class PostJobExtensionDictionnaryTest {
  38. private PostJobOptimizer postJobOptimizer = mock(PostJobOptimizer.class);
  39. @Before
  40. public void setUp() {
  41. when(postJobOptimizer.shouldExecute(any(DefaultPostJobDescriptor.class))).thenReturn(true);
  42. }
  43. private PostJobExtensionDictionnary newSelector(Object... extensions) {
  44. ComponentContainer iocContainer = new ComponentContainer();
  45. for (Object extension : extensions) {
  46. iocContainer.addSingleton(extension);
  47. }
  48. return new PostJobExtensionDictionnary(iocContainer, postJobOptimizer, mock(PostJobContext.class));
  49. }
  50. @Test
  51. public void dependsUponPhaseForPostJob() {
  52. PrePostJob pre = new PrePostJob();
  53. NormalPostJob normal = new NormalPostJob();
  54. PostJobExtensionDictionnary selector = newSelector(normal, pre);
  55. assertThat(selector.selectPostJobs()).extracting("wrappedPostJob").containsExactly(pre, normal);
  56. }
  57. interface Marker {
  58. }
  59. @Phase(name = Phase.Name.POST)
  60. class PostSensor implements Sensor {
  61. @Override
  62. public void describe(SensorDescriptor descriptor) {
  63. }
  64. @Override
  65. public void execute(SensorContext context) {
  66. }
  67. }
  68. class PostSensorSubclass extends PostSensor {
  69. }
  70. class NormalPostJob implements PostJob {
  71. @Override
  72. public void describe(PostJobDescriptor descriptor) {
  73. }
  74. @Override
  75. public void execute(PostJobContext context) {
  76. }
  77. }
  78. @Phase(name = Phase.Name.PRE)
  79. class PrePostJob implements PostJob {
  80. @Override
  81. public void describe(PostJobDescriptor descriptor) {
  82. }
  83. @Override
  84. public void execute(PostJobContext context) {
  85. }
  86. }
  87. }