ReleaseJsonToObject extends AbstractJsonToObject<Release> { @Override public Release toObject() throws IOException { if (release == null) { release = this.mapper.readValue(this.jsonObject, Release.class); } return release; } ReleaseJsonToObject(final String jsonObject);  ReleaseJsonToObject(final InputStream inputStream);  ReleaseJsonToObject(final File file); @Override Release toObject();  }
@Test public void toObject() throws Exception { final String jsonRelease = "{\n" + " id: \"123\",\n" + " tag: [\"tender\"],\n" + " planning: {\n" + " budget: {\n" + " description: \"budget desc...\",\n" + " amount: {\n" + " amount: 10000,\n" + " currency: \"USD\"\n" + " }\n" + " }\n" + " }\n" + "}"; final JsonToObject releaseJsonToObject = new ReleaseJsonToObject(jsonRelease); Assert.assertTrue("Object is a Release", releaseJsonToObject.toObject() instanceof Release); final Release release = (Release) releaseJsonToObject.toObject(); Assert.assertEquals("IDs are the same", "123", release.getId()); Assert.assertEquals("Check budget amount", new BigDecimal(10000), release.getPlanning().getBudget().getAmount().getAmount()); Assert.assertEquals("Check budget currency", Amount.Currency.USD, release.getPlanning().getBudget().getAmount().getCurrency()); }
@Test(expected = IOException.class) public void toObjectInvalidJson() throws Exception { final String invalidJsonRelease = "{\n" + " id: \"123\",\n" + " tag: [\"tenderrrrrr\"],\n" + " tag: [\"award\"],\n" + "}"; final JsonToObject invalidJsonToObject = new ReleaseJsonToObject(invalidJsonRelease); invalidJsonToObject.toObject(); }
@Test public void toObjectFromFile() throws Exception { final ClassLoader classLoader = getClass().getClassLoader(); final File file = new File(classLoader.getResource("json/release-json-to-object-test.json").getFile()); final JsonToObject releaseJsonToObject = new ReleaseJsonToObject(file); Assert.assertTrue("Object is a Release", releaseJsonToObject.toObject() instanceof Release); final Release release = (Release) releaseJsonToObject.toObject(); Assert.assertEquals("IDs are the same", "12345", release.getId()); Assert.assertEquals("Check budget amount", new BigDecimal(10000), release.getPlanning().getBudget().getAmount().getAmount()); Assert.assertEquals("Check budget currency", Amount.Currency.RON, release.getPlanning().getBudget().getAmount().getCurrency()); }