TimeTrackingJsonParser implements JsonParser<TimeTracking> { @Override public TimeTracking parse(JSONObject json) throws JSONException { final Integer originalEstimateMinutes = JsonParseUtil.parseOptionInteger(json, "timeoriginalestimate"); final Integer timeRemainingMinutes = JsonParseUtil.parseOptionInteger(json, "timeestimate"); final Integer timeSpentMinutes = JsonParseUtil.parseOptionInteger(json, "timespent"); return new TimeTracking(originalEstimateMinutes, timeRemainingMinutes, timeSpentMinutes); }  @Override TimeTracking parse(JSONObject json);  }
@Test public void testParse() throws Exception { final TimeTrackingJsonParser parser = new TimeTrackingJsonParser(); final TimeTracking timeTracking = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/timeTracking/valid.json").getJSONObject("value")); assertEquals(new TimeTracking(1500, 70, 190), timeTracking); }
@Test public void testParseNoEstimation() throws Exception { final TimeTrackingJsonParser parser = new TimeTrackingJsonParser(); final TimeTracking timeTracking = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/timeTracking/valid-no-estimation.json").getJSONObject("value")); assertEquals(new TimeTracking(null, 170, 9), timeTracking); }
@Test public void testParseJustLoggedTime() throws Exception { final TimeTrackingJsonParser parser = new TimeTrackingJsonParser(); final TimeTracking timeTracking = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/timeTracking/valid-just-timespent.json").getJSONObject("value")); assertEquals(new TimeTracking(null, null, 840), timeTracking); }