VersionJsonParser implements JsonParser<Version> { @Override public Version parse(JSONObject json) throws JSONException { final URI self = JsonParseUtil.getSelfUri(json); final String name = json.getString("name"); final String description = JsonParseUtil.getOptionalString(json, "description"); final boolean isArchived = json.getBoolean("archived"); final boolean isReleased = json.getBoolean("released"); final String releaseDateStr = JsonParseUtil.getOptionalString(json, "releaseDate"); final DateTime releaseDate = parseReleaseDate(releaseDateStr); return new Version(self, name, description, isArchived, isReleased, releaseDate); }  @Override Version parse(JSONObject json);  }
@Test public void testParse() throws JSONException, URISyntaxException { VersionJsonParser parser = new VersionJsonParser(); final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid.json")); assertEquals(new URI("http: assertEquals("1.1", version.getName()); assertEquals("Some version", version.getDescription()); Assert.assertFalse(version.isReleased()); Assert.assertTrue(version.isArchived()); Assert.assertThat(version.getReleaseDate(), DateTimeMatcher.isEqual( new DateTime(2010, 8, 25, 0, 0, 0, 0, DateTimeZone.forOffsetHours(2)))); }
@Test public void testParse2() throws JSONException, URISyntaxException { VersionJsonParser parser = new VersionJsonParser(); final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid2-no-releaseDate.json")); assertEquals(new URI("http: assertEquals("1.1abc", version.getName()); Assert.assertNull(version.getDescription()); Assert.assertTrue(version.isReleased()); Assert.assertFalse(version.isArchived()); Assert.assertNull(version.getReleaseDate()); }
@Test public void testParseNoDescription() throws JSONException, URISyntaxException { VersionJsonParser parser = new VersionJsonParser(); final Version version = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/version/valid-no-description.json")); assertEquals(new URI("http: assertEquals("1.1", version.getName()); Assert.assertNull(version.getDescription()); Assert.assertFalse(version.isReleased()); Assert.assertTrue(version.isArchived()); Assert.assertThat(version.getReleaseDate(), DateTimeMatcher.isEqual( new DateTime(2010, 8, 25, 0, 0, 0, 0, DateTimeZone.forOffsetHours(2)))); }