diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-09-09 13:33:24 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-09-09 13:33:24 +0200 |
commit | e7d218f5d4bae169f3a66d31170a670254efbf10 (patch) | |
tree | 99d48d6f3c383f87e116e6a4e6a572c4e90d896b /sonar-runner-api/src/test | |
parent | 90e1ce60e73d65efeded917f896b1526b89401d4 (diff) | |
download | sonar-scanner-cli-e7d218f5d4bae169f3a66d31170a670254efbf10.tar.gz sonar-scanner-cli-e7d218f5d4bae169f3a66d31170a670254efbf10.zip |
Improvie tests and quality
Diffstat (limited to 'sonar-runner-api/src/test')
-rw-r--r-- | sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java b/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java index 653f61f..3b1239f 100644 --- a/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java +++ b/sonar-runner-api/src/test/java/org/sonar/runner/api/UtilsTest.java @@ -19,19 +19,27 @@ */ package org.sonar.runner.api; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; + import java.io.Closeable; +import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Properties; -import org.junit.Test; +import org.junit.Test; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; public class UtilsTest { + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + @Test public void should_join_strings() { assertThat(Utils.join(new String[] {}, ",")).isEqualTo(""); @@ -49,6 +57,15 @@ public class UtilsTest { } @Test + public void write_properties() throws IOException { + File f = temp.newFile(); + Properties p = new Properties(); + p.put("key", "value"); + Utils.writeProperties(f, p); + assertThat(Files.readAllLines(f.toPath(), StandardCharsets.UTF_8)).contains("key=value"); + } + + @Test public void task_should_not_require_project() { Properties props = new Properties(); props.setProperty("sonar.task", "views"); @@ -56,7 +73,7 @@ public class UtilsTest { } @Test - public void close_quietly() throws IOException { + public void close_quietly_error() throws IOException { Closeable c = mock(Closeable.class); doThrow(IOException.class).when(c).close(); Utils.closeQuietly(c); @@ -69,6 +86,20 @@ public class UtilsTest { } @Test + public void close_quietly() throws IOException { + Closeable c = mock(Closeable.class); + Utils.closeQuietly(c); + verify(c).close(); + } + + @Test + public void delete_quietly() { + File f = mock(File.class); + doThrow(IOException.class).when(f).toPath(); + Utils.deleteQuietly(f); + } + + @Test public void delete_non_empty_directory() throws IOException { /*- * Create test structure: |