aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-05-05 10:22:43 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2014-05-05 10:22:43 +0200
commit819e6501f876e8d7792d27ab5117d42bcd7671c8 (patch)
treeb79c29f67d292f0e00ab166b4621ea9f19e52728 /sonar-plugin-api/src/test
parenta2a2caeb55a26f5966368b5e2b34eced3fc444fb (diff)
downloadsonarqube-819e6501f876e8d7792d27ab5117d42bcd7671c8.tar.gz
sonarqube-819e6501f876e8d7792d27ab5117d42bcd7671c8.zip
Add JsonWriter#valueObject(Object)
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java33
1 files changed, 33 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java
index d5f2cb7b429..41ae3399029 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.utils.text;
+import com.google.common.collect.ImmutableMap;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -28,9 +29,11 @@ import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Date;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -116,7 +119,37 @@ public class JsonWriterTest {
.prop("foo", "<hello \"world\">")
.endObject().close();
expect("{\"foo\":\"<hello \\\"world\\\">\"}");
+ }
+
+ @Test
+ public void valueObject() throws Exception {
+ writer.beginObject()
+ .name("aString").valueObject("stringValue")
+ .name("aBoolean").valueObject(true)
+ .name("aInt").valueObject(42)
+ .name("aFloat").valueObject(3.14)
+ .name("aLong").valueObject(42L)
+ .name("aList").valueObject(Arrays.asList("one", 2, "three"))
+ .name("aMap").valueObject(ImmutableMap.of("hello", "world", "good", "bye"))
+ .endObject().close();
+ expect("{\"aString\":\"stringValue\",\"aBoolean\":true,\"aInt\":42,\"aFloat\":3.14,\"aLong\":42,\"aList\":[\"one\",2,\"three\"],\"aMap\":{\"hello\":\"world\",\"good\":\"bye\"}}");
+ }
+ @Test
+ public void valueObject_recursive() throws Exception {
+ Map map = ImmutableMap.of("a", ImmutableMap.of("b", "c"));
+ writer.valueObject(map).close();
+ expect("{\"a\":{\"b\":\"c\"}}");
+ }
+
+ @Test
+ public void valueObject_unsupported_type() throws Exception {
+ try {
+ writer.beginObject().valueObject(new StringWriter()).endObject().close();
+ fail();
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("class org.sonar.api.utils.text.JsonWriter does not support encoding of type: class java.io.StringWriter");
+ }
}
@Test