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.

SonarRunnerUtilsTest.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Sonar 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.internal.batch;
  21. import org.apache.commons.io.IOUtils;
  22. import org.junit.Test;
  23. import org.sonar.test.TestUtils;
  24. import java.io.FileInputStream;
  25. import java.io.IOException;
  26. import java.util.Properties;
  27. import static org.fest.assertions.Assertions.assertThat;
  28. public class SonarRunnerUtilsTest {
  29. @Test
  30. public void shouldGetList() {
  31. Properties props = new Properties();
  32. props.put("prop", " foo , bar , \n\ntoto,tutu");
  33. assertThat(SonarRunnerUtils.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
  34. }
  35. @Test
  36. public void shouldGetListFromFile() throws IOException {
  37. String filePath = "shouldGetList/foo.properties";
  38. Properties props = loadPropsFromFile(filePath);
  39. assertThat(SonarRunnerUtils.getListFromProperty(props, "prop")).containsOnly("foo", "bar", "toto", "tutu");
  40. }
  41. private Properties loadPropsFromFile(String filePath) throws IOException {
  42. Properties props = new Properties();
  43. FileInputStream fileInputStream = null;
  44. try {
  45. fileInputStream = new FileInputStream(TestUtils.getResource(this.getClass(), filePath));
  46. props.load(fileInputStream);
  47. } finally {
  48. IOUtils.closeQuietly(fileInputStream);
  49. }
  50. return props;
  51. }
  52. }