aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test/java/org/sonar
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-04-17 10:29:24 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-04-17 16:46:14 +0200
commit62ad128a8caeae516ccbbe6d92547a3ff213a6eb (patch)
tree1ee68d5aeddf732a156428d53eddb4d312471b63 /sonar-plugin-api/src/test/java/org/sonar
parent58495187b8991249e3c203430178c21f101bb115 (diff)
downloadsonarqube-62ad128a8caeae516ccbbe6d92547a3ff213a6eb.tar.gz
sonarqube-62ad128a8caeae516ccbbe6d92547a3ff213a6eb.zip
SONAR-3676 add flag to not serialize empty strings to JSON
Diffstat (limited to 'sonar-plugin-api/src/test/java/org/sonar')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/text/JsonWriterTest.java24
1 files changed, 24 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 f0de3de0434..e0b945ddbe6 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
@@ -39,6 +39,8 @@ import static org.mockito.Mockito.when;
public class JsonWriterTest {
+ private static final String EMPTY_STRING = "";
+
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -128,6 +130,28 @@ public class JsonWriterTest {
}
@Test
+ public void serialize_empty_strings_by_default() throws Exception {
+ writer.beginObject()
+ .prop("emptyString", EMPTY_STRING)
+ .name("emptyStringAsObject").valueObject(EMPTY_STRING)
+ .endObject().close();
+ expect("{" +
+ "\"emptyString\":\"\"," +
+ "\"emptyStringAsObject\":\"\"" +
+ "}");
+ }
+
+ @Test
+ public void ignore_empty_strings_when_requested() throws Exception {
+ writer.setSerializeEmptys(false)
+ .beginObject()
+ .prop("emptyString", EMPTY_STRING)
+ .name("emptyStringAsObject").valueObject(EMPTY_STRING)
+ .endObject().close();
+ expect("{}");
+ }
+
+ @Test
public void escape_values() throws Exception {
writer.beginObject()
.prop("foo", "<hello \"world\">")