Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

BatchLauncherMainTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * SonarQube Runner - Implementation
  3. * Copyright (C) 2011 SonarSource
  4. * dev@sonar.codehaus.org
  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
  17. * License along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package org.sonar.runner.impl;
  21. import org.sonar.runner.batch.IsolatedLauncher;
  22. import org.junit.Test;
  23. import org.mockito.ArgumentMatcher;
  24. import java.io.File;
  25. import java.net.URL;
  26. import java.util.Properties;
  27. import static org.mockito.Matchers.any;
  28. import static org.mockito.Mockito.when;
  29. import static org.fest.assertions.Fail.fail;
  30. import static org.mockito.Matchers.argThat;
  31. import static org.mockito.Mockito.mock;
  32. import static org.mockito.Mockito.verify;
  33. public class BatchLauncherMainTest {
  34. IsolatedLauncherFactory launcherFactory = mock(IsolatedLauncherFactory.class);
  35. @Test
  36. public void should_load_properties_and_execute() throws Exception {
  37. URL url = getClass().getResource("/org/sonar/runner/impl/BatchLauncherMainTest/props.properties");
  38. when(launcherFactory.createLauncher(any(Properties.class))).thenReturn(mock(IsolatedLauncher.class));
  39. BatchLauncherMain main = new BatchLauncherMain(launcherFactory);
  40. new File(url.toURI()).getAbsolutePath();
  41. main.execute(new String[] {new File(url.toURI()).getAbsolutePath()});
  42. verify(launcherFactory).createLauncher(argThat(new ArgumentMatcher<Properties>() {
  43. @Override
  44. public boolean matches(Object o) {
  45. return ((Properties) o).get("sonar.login").equals("foo");
  46. }
  47. }));
  48. }
  49. @Test
  50. public void should_fail_if_missing_path_to_properties_file() {
  51. try {
  52. BatchLauncherMain main = new BatchLauncherMain(launcherFactory);
  53. main.execute(new String[0]);
  54. fail();
  55. } catch (Exception e) {
  56. // success
  57. }
  58. }
  59. @Test
  60. public void should_fail_if_properties_file_does_not_exist() {
  61. try {
  62. BatchLauncherMain main = new BatchLauncherMain(launcherFactory);
  63. main.execute(new String[] {"unknown/file.properties"});
  64. fail();
  65. } catch (Exception e) {
  66. // success
  67. }
  68. }
  69. }