### Question:
AccountJsonSerializer implements JsonSerializer<Account> { public Account deserialize(JSONObject response) throws JSONException { Account account = new Account(); Quota quota = new Quota(); Term term = new Term(); int quotaUsed = response.getJSONObject("quota").getInt("quotaUsed"); int quotaRemaining = response.getJSONObject("quota").getInt("quotaRemaining"); int quotaTotal = response.getJSONObject("quota").getInt("quotaTotal"); String startAt = response.getJSONObject("term").getString("startAt"); String endAt = response.getJSONObject("term").getString("endAt"); quota.setQuotaUsed(quotaUsed); quota.setQuotaRemaining(quotaRemaining); quota.setQuotaTotal(quotaTotal); term.setStartAt(startAt); term.setEndAt(endAt); account.setQuota(quota); account.setTerm(term); return account; }  Account deserialize(JSONObject response); List<Account> deserialize(JSONArray data); JSONObject serialize(Account object);  }### Answer:
@Test(expected = JSONException.class) public void deserializeFailure() throws JSONException { accountJsonSerializer.deserialize(new JSONObject()); }
@Test(expected = RuntimeException.class) public void deserializeAllFailure() throws JSONException { accountJsonSerializer.deserialize(new JSONArray()); }
@Test public void deserializeSuccess() throws JSONException { Map<Object, Object> jsonParams = new HashMap<>(); Map<Object, Object> quotaParams = new HashMap<>(); Map<Object, Object> termParams = new HashMap<>(); quotaParams.put("quotaUsed", 0); quotaParams.put("quotaRemaining", 3000); quotaParams.put("quotaTotal", 3000); termParams.put("startAt", "2019-09-05"); termParams.put("endAt", "2019-09-05"); jsonParams.put("quota", new JSONObject(quotaParams)); jsonParams.put("term", new JSONObject(termParams)); Account account = accountJsonSerializer.deserialize(new JSONObject(jsonParams)); assertEquals(0, account.getQuota().getQuotaUsed()); assertEquals(3000, account.getQuota().getQuotaRemaining()); assertEquals(3000, account.getQuota().getQuotaTotal()); assertEquals("2019-09-05", account.getTerm().getStartAt()); assertEquals("2019-09-05", account.getTerm().getEndAt()); }