aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java13
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java26
-rw-r--r--sonar-ws-client/src/test/resources/timemachine/many.json5
-rw-r--r--sonar-ws-client/src/test/resources/timemachine/timemachine.json3
4 files changed, 38 insertions, 9 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java
index b9d5eb60be7..8887da9abd2 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshaller.java
@@ -5,10 +5,7 @@ import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.sonar.wsclient.services.TimeMachineData;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class TimeMachineUnmarshaller implements Unmarshaller<TimeMachineData> {
@@ -17,7 +14,13 @@ public class TimeMachineUnmarshaller implements Unmarshaller<TimeMachineData> {
Map<Date, List<String>> data = new HashMap<Date, List<String>>();
for (Object key : map.keySet()) {
JSONArray array = (JSONArray) map.get(key);
- data.put(JsonUtils.parseDateTime((String) key), array);
+ List<String> values = new ArrayList<String>();
+ for (int i = 0; i < array.size(); i++) {
+ Object elem = array.get(i);
+ String value = elem == null ? null : elem.toString();
+ values.add(value);
+ }
+ data.put(JsonUtils.parseDateTime((String) key), values);
}
return new TimeMachineData().setData(data);
}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java
index e722c1120ad..a05319884a2 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/TimeMachineUnmarshallerTest.java
@@ -5,17 +5,39 @@ import org.junit.Test;
import org.sonar.wsclient.services.TimeMachineData;
import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
public class TimeMachineUnmarshallerTest {
@Test
- public void toModel() throws IOException {
+ public void toModel() throws Exception {
TimeMachineData data = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/timemachine.json"));
- assertThat(data.getData().size(), is(2));
+ Map<Date, List<String>> map = data.getData();
+ assertThat(map.size(), is(1));
+ Date date = map.keySet().iterator().next();
+ final Date expectedDate = new SimpleDateFormat("yyyy-MM-dd'T'kk:mm:ssZZZZ").parse("2010-12-04T15:59:23+0000");
+ assertThat(date, is(expectedDate));
+ List<String> values = map.values().iterator().next();
+ assertThat(values.size(), is(3));
+ assertThat(values.get(0), is("20.0"));
+ assertThat(values.get(1), nullValue());
+ assertThat(values.get(2), is("12.8"));
+ }
+
+ @Test
+ public void many() throws Exception {
+ TimeMachineData data = new TimeMachineUnmarshaller().toModel(loadFile("/timemachine/many.json"));
+
+ Map<Date, List<String>> map = data.getData();
+ assertThat(map.size(), is(3));
}
private static String loadFile(String path) throws IOException {
diff --git a/sonar-ws-client/src/test/resources/timemachine/many.json b/sonar-ws-client/src/test/resources/timemachine/many.json
new file mode 100644
index 00000000000..a65a8daa255
--- /dev/null
+++ b/sonar-ws-client/src/test/resources/timemachine/many.json
@@ -0,0 +1,5 @@
+{
+ "2010-10-10T00:00:00+0000": [25.0, null, 14.6],
+ "2010-11-15T00:00:00+0000": [23.0, null, 10.3],
+ "2010-12-04T00:00:00+0000": [20.0, null, 12.8]
+}
diff --git a/sonar-ws-client/src/test/resources/timemachine/timemachine.json b/sonar-ws-client/src/test/resources/timemachine/timemachine.json
index e4777958df8..03130cc0286 100644
--- a/sonar-ws-client/src/test/resources/timemachine/timemachine.json
+++ b/sonar-ws-client/src/test/resources/timemachine/timemachine.json
@@ -1,4 +1,3 @@
{
- "2010-10-04T00:00:00+0000": ["18.0", null, "13.1"],
- "2010-12-04T00:00:00+0000": ["20.0", null, "12.8"]
+ "2010-12-04T15:59:23+0000": [20.0, null, 12.8]
}