Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

GlobalContainerTest.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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 com.google.common.collect.ImmutableMap;
  22. import com.google.common.collect.Lists;
  23. import java.util.Collections;
  24. import java.util.List;
  25. import java.util.Map;
  26. import org.junit.Rule;
  27. import org.junit.Test;
  28. import org.junit.rules.TemporaryFolder;
  29. import org.sonar.api.CoreProperties;
  30. import org.sonar.api.batch.ScannerSide;
  31. import org.sonar.api.utils.TempFolder;
  32. import org.sonar.batch.bootstrapper.EnvironmentInformation;
  33. import org.sonar.core.util.UuidFactory;
  34. import static org.assertj.core.api.Assertions.assertThat;
  35. public class GlobalContainerTest {
  36. @Rule
  37. public TemporaryFolder temp = new TemporaryFolder();
  38. private GlobalContainer createContainer(List<Object> extensions) {
  39. Map<String, String> props = ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, temp.getRoot().getAbsolutePath(),
  40. CoreProperties.GLOBAL_WORKING_DIRECTORY, temp.getRoot().getAbsolutePath());
  41. GlobalContainer container = GlobalContainer.create(props, extensions);
  42. container.doBeforeStart();
  43. return container;
  44. }
  45. @Test
  46. public void should_add_components() {
  47. GlobalContainer container = createContainer(Collections.singletonList(new EnvironmentInformation("maven", "3.1.0")));
  48. assertThat(container.getComponentByType(UuidFactory.class)).isNotNull();
  49. assertThat(container.getComponentByType(TempFolder.class)).isNotNull();
  50. }
  51. @Test
  52. public void should_add_bootstrap_extensions() {
  53. GlobalContainer container = createContainer(Lists.newArrayList(Foo.class, new Bar()));
  54. assertThat(container.getComponentByType(Foo.class)).isNotNull();
  55. assertThat(container.getComponentByType(Bar.class)).isNotNull();
  56. }
  57. @Test
  58. public void shouldFormatTime() {
  59. assertThat(GlobalContainer.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("1:02:03.400 s");
  60. assertThat(GlobalContainer.formatTime(2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("2:03.400 s");
  61. assertThat(GlobalContainer.formatTime(3 * 1000 + 400)).isEqualTo("3.400 s");
  62. assertThat(GlobalContainer.formatTime(400)).isEqualTo("0.400 s");
  63. }
  64. @ScannerSide
  65. public static class Foo {
  66. }
  67. @ScannerSide
  68. public static class Bar {
  69. }
  70. }