diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-25 23:29:55 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-25 23:29:55 +0200 |
commit | 9654662b48c918b55383846c6575b7f809437108 (patch) | |
tree | f9e52606b25e3ea61e18fe2dd411feb789d18a79 /server/sonar-process/src/test/java/org/sonar/process/PropsTest.java | |
parent | 4a5a256eefb9dd6173b2155bb6994d88da612d5f (diff) | |
download | sonarqube-9654662b48c918b55383846c6575b7f809437108.tar.gz sonarqube-9654662b48c918b55383846c6575b7f809437108.zip |
SONAR-4898 add missing tests
Diffstat (limited to 'server/sonar-process/src/test/java/org/sonar/process/PropsTest.java')
-rw-r--r-- | server/sonar-process/src/test/java/org/sonar/process/PropsTest.java | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java b/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java index 5d283b44f8f..25feeef39b8 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java @@ -19,8 +19,12 @@ */ package org.sonar.process; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import java.io.File; +import java.io.IOException; import java.util.Properties; import static org.fest.assertions.Assertions.assertThat; @@ -28,8 +32,11 @@ import static org.fest.assertions.Fail.fail; public class PropsTest { + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + @Test - public void of() throws Exception { + public void value() throws Exception { Properties p = new Properties(); p.setProperty("foo", "bar"); Props props = new Props(p); @@ -38,10 +45,18 @@ public class PropsTest { assertThat(props.value("foo", "default value")).isEqualTo("bar"); assertThat(props.value("unknown")).isNull(); assertThat(props.value("unknown", "default value")).isEqualTo("default value"); + + assertThat(props.nonNullValue("foo")).isEqualTo("bar"); + try { + props.nonNullValue("other"); + fail(); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessage("Missing property: other"); + } } @Test - public void intOf() throws Exception { + public void valueAsInt() throws Exception { Properties p = new Properties(); p.setProperty("foo", "33"); p.setProperty("blank", ""); @@ -56,7 +71,7 @@ public class PropsTest { } @Test - public void intOf_not_integer() throws Exception { + public void valueAsInt_not_integer() throws Exception { Properties p = new Properties(); p.setProperty("foo", "bar"); Props props = new Props(p); @@ -130,6 +145,21 @@ public class PropsTest { // do not decrypt assertThat(props.rawProperties().get("encrypted_prop")).isEqualTo("{aes}abcde"); assertThat(props.rawProperties().get("clear_prop")).isEqualTo("foo"); + } + @Test + public void nonNullValueAsFile() throws IOException { + File file = temp.newFile(); + Props props = new Props(new Properties()); + props.set("path", file.getAbsolutePath()); + + assertThat(props.nonNullValueAsFile("path")).isEqualTo(file); + + try { + props.nonNullValueAsFile("other_path"); + fail(); + } catch (IllegalArgumentException e) { + assertThat(e).hasMessage("Property other_path is not set"); + } } } |