diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-06 14:42:40 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-07-06 14:57:13 +0200 |
commit | 4843622503247b75f04cd061a7825350d0ffe99b (patch) | |
tree | f7c4bef107232b992cc7433a2b2daf9a3efb9fbb /sonar-plugin-api/src/test/java/org | |
parent | 321ee8c584cc938b262393a7de3be88fa04d17df (diff) | |
download | sonarqube-4843622503247b75f04cd061a7825350d0ffe99b.tar.gz sonarqube-4843622503247b75f04cd061a7825350d0ffe99b.zip |
API: add Settings#getStringLines(String key)
Diffstat (limited to 'sonar-plugin-api/src/test/java/org')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java index fe01f365560..e821ff6a8c0 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/SettingsTest.java @@ -32,12 +32,13 @@ public class SettingsTest { private PropertyDefinitions definitions; @Properties({ - @Property(key = "hello", name = "Hello", defaultValue = "world"), - @Property(key = "date", name = "Date", defaultValue = "2010-05-18"), - @Property(key = "boolean", name = "Boolean", defaultValue = "true"), - @Property(key = "falseboolean", name = "False Boolean", defaultValue = "false"), - @Property(key = "integer", name = "Integer", defaultValue = "12345"), - @Property(key = "array", name = "Array", defaultValue = "one,two,three") + @Property(key = "hello", name = "Hello", defaultValue = "world"), + @Property(key = "date", name = "Date", defaultValue = "2010-05-18"), + @Property(key = "datetime", name = "DateTime", defaultValue = "2010-05-18T15:50:45+0100"), + @Property(key = "boolean", name = "Boolean", defaultValue = "true"), + @Property(key = "falseboolean", name = "False Boolean", defaultValue = "false"), + @Property(key = "integer", name = "Integer", defaultValue = "12345"), + @Property(key = "array", name = "Array", defaultValue = "one,two,three") }) static class Init { } @@ -95,6 +96,14 @@ public class SettingsTest { } @Test + public void testGetDateTime() { + Settings settings = new Settings(definitions); + assertThat(settings.getDateTime("datetime").getDate()).isEqualTo(18); + assertThat(settings.getDateTime("datetime").getMonth()).isEqualTo(4); + assertThat(settings.getDateTime("datetime").getMinutes()).isEqualTo(50); + } + + @Test public void testGetArray() { Settings settings = new Settings(definitions); String[] array = settings.getStringArray("array"); @@ -162,4 +171,56 @@ public class SettingsTest { assertThat(target.getString("foo")).isEqualTo("bar"); assertThat(target.getString("new")).isNull(); } + + @Test + public void getStringLines_no_value() { + assertThat(new Settings().getStringLines("foo")).hasSize(0); + } + + @Test + public void getStringLines_single_line() { + Settings settings = new Settings(); + settings.setProperty("foo", "the line"); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"the line"}); + } + + @Test + public void getStringLines_linux() { + Settings settings = new Settings(); + settings.setProperty("foo", "one\ntwo"); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"}); + + settings.setProperty("foo", "one\ntwo\n"); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"}); + } + + @Test + public void getStringLines_windows() { + Settings settings = new Settings(); + settings.setProperty("foo", "one\r\ntwo"); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"}); + + settings.setProperty("foo", "one\r\ntwo\r\n"); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two"}); + } + + @Test + public void getStringLines_mix() { + Settings settings = new Settings(); + settings.setProperty("foo", "one\r\ntwo\nthree"); + assertThat(settings.getStringLines("foo")).isEqualTo(new String[]{"one", "two", "three"}); + } + + @Test + public void getKeysStartingWith() { + Settings settings = new Settings(); + settings.setProperty("sonar.jdbc.url", "foo"); + settings.setProperty("sonar.jdbc.username", "bar"); + settings.setProperty("sonar.security", "admin"); + + assertThat(settings.getKeysStartingWith("sonar")).containsOnly("sonar.jdbc.url", "sonar.jdbc.username", "sonar.security"); + assertThat(settings.getKeysStartingWith("sonar.jdbc")).containsOnly("sonar.jdbc.url", "sonar.jdbc.username"); + assertThat(settings.getKeysStartingWith("other")).hasSize(0); + + } } |