Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ScannerFactoryTest.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SonarQube Scanner
  3. * Copyright (C) 2011-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.sonarsource.scanner.cli;
  21. import java.util.Properties;
  22. import org.junit.Test;
  23. import org.sonarsource.scanner.api.EmbeddedScanner;
  24. import org.sonarsource.scanner.api.LogOutput;
  25. import org.sonarsource.scanner.api.LogOutput.Level;
  26. import static org.assertj.core.api.Assertions.assertThat;
  27. import static org.mockito.Mockito.mock;
  28. import static org.mockito.Mockito.reset;
  29. import static org.mockito.Mockito.verify;
  30. import static org.mockito.Mockito.verifyNoMoreInteractions;
  31. public class ScannerFactoryTest {
  32. private Properties props = new Properties();
  33. private Logs logs = mock(Logs.class);
  34. @Test
  35. public void should_create_embedded_runner() {
  36. props.setProperty("foo", "bar");
  37. EmbeddedScanner runner = new ScannerFactory(logs).create(props);
  38. assertThat(runner).isInstanceOf(EmbeddedScanner.class);
  39. assertThat(runner.globalProperties().get("foo")).isEqualTo("bar");
  40. assertThat(runner.app()).isEqualTo("ScannerCli");
  41. assertThat(runner.appVersion()).isNotNull();
  42. }
  43. @Test
  44. public void should_fwd_logs() {
  45. LogOutput logOutput = new ScannerFactory(logs).new DefaultLogOutput();
  46. String msg = "test";
  47. logOutput.log(msg, Level.DEBUG);
  48. verify(logs).debug(msg);
  49. verifyNoMoreInteractions(logs);
  50. reset(logs);
  51. logOutput.log(msg, Level.INFO);
  52. verify(logs).info(msg);
  53. verifyNoMoreInteractions(logs);
  54. reset(logs);
  55. logOutput.log(msg, Level.ERROR);
  56. verify(logs).error(msg);
  57. verifyNoMoreInteractions(logs);
  58. reset(logs);
  59. logOutput.log(msg, Level.WARN);
  60. verify(logs).warn(msg);
  61. verifyNoMoreInteractions(logs);
  62. reset(logs);
  63. logOutput.log(msg, Level.TRACE);
  64. verify(logs).debug(msg);
  65. verifyNoMoreInteractions(logs);
  66. reset(logs);
  67. }
  68. }