### Question:
CaptionJsonSerializer implements JsonSerializer<Caption> { public Caption deserialize(JSONObject response) throws JSONException { Caption caption = new Caption(); if (response.has("uri")) { caption.setUri(response.getString("uri")); } if (response.has("src")) { caption.setSrc(response.getString("src")); } if (response.has("srclang")) { caption.setSrclang(response.getString("srclang")); } if (response.has("default")) { caption.setDefaut(response.getBoolean("default")); } return caption; }  Caption deserialize(JSONObject response); List<Caption> deserialize(JSONArray data); JSONObject serialize(Caption caption);  }### Answer:
@Test public void deserializeEmpty() throws JSONException { assertNull(captionJsonSerializer.deserialize(new JSONObject()).getSrc()); }
@Test public void deserializeAllEmpty() throws JSONException { assertTrue(captionJsonSerializer.deserialize(new JSONArray()).isEmpty()); }
@Test public void deserializeSuccess() throws JSONException { Map<Object, Object> jsonParams = new HashMap<>(); jsonParams.put("uri", "uri"); jsonParams.put("src", "src"); jsonParams.put("srclang", "srclang"); jsonParams.put("default", false); Caption caption = captionJsonSerializer.deserialize(new JSONObject(jsonParams)); assertEquals("uri", caption.getUri()); assertEquals("src", caption.getSrc()); assertEquals("srclang", caption.getSrclang()); assertEquals(false, caption.isDefaut()); }
@Test public void deserializeAllSuccess() throws JSONException { Map<String, String> jsonCaption1 = new HashMap<>(); jsonCaption1.put("uri", "uri1"); Map<String, String> jsonCaption2 = new HashMap<>(); jsonCaption2.put("uri", "uri2"); Map<String, String> jsonCaption3 = new HashMap<>(); jsonCaption3.put("uri", "uri3"); List<Caption> captionList = captionJsonSerializer.deserialize(new JSONArray() {{ put(new JSONObject(jsonCaption1)); put(new JSONObject(jsonCaption2)); put(new JSONObject(jsonCaption3)); }}); assertEquals("uri1", captionList.get(0).getUri()); assertEquals("uri2", captionList.get(1).getUri()); assertEquals("uri3", captionList.get(2).getUri()); }