ServerInfoJsonParser implements JsonParser<ServerInfo> { @Override public ServerInfo parse(JSONObject json) throws JSONException { final URI baseUri = JsonParseUtil.parseURI(json.getString("baseUrl")); final String version = json.getString("version"); final int buildNumber = json.getInt("buildNumber"); final DateTime buildDate = JsonParseUtil.parseDateTime(json, "buildDate"); final DateTime serverTime = JsonParseUtil.parseOptionalDateTime(json, "serverTime"); final String scmInfo = json.getString("scmInfo"); final String serverTitle = json.getString("serverTitle"); return new ServerInfo(baseUri, version, buildNumber, buildDate, serverTime, scmInfo, serverTitle); }  @Override ServerInfo parse(JSONObject json);  }
@Test public void testParse() throws Exception { final ServerInfoJsonParser parser = new ServerInfoJsonParser(); final ServerInfo serverInfo = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/serverInfo/valid.json")); Assert.assertEquals(new ServerInfo(TestUtil.toUri("http: 580, TestUtil.toDateTime("2010-09-23T00:00:00.000+0200"), TestUtil.toDateTime("2010-09-30T16:11:09.767+0200"), "abc128082", "Your Company JIRA"), serverInfo); }
@Test public void testParseAnonymous() throws Exception { final ServerInfoJsonParser parser = new ServerInfoJsonParser(); final ServerInfo serverInfo = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/serverInfo/valid-for-anonymous.json")); Assert.assertEquals(new ServerInfo(TestUtil.toUri("http: 580, TestUtil.toDateTime("2010-09-23T00:00:00.000+0200"), null, "128082", "Your Company JIRA"), serverInfo); }