### Question:
LiveStreamJsonSerializer implements JsonSerializer<LiveStream> { public LiveStream deserialize(JSONObject response) throws JSONException { LiveStream liveStream = new LiveStream(); Assets assets = new Assets(); if (response.has("liveStreamId")) { liveStream.setLiveStreamId(response.getString("liveStreamId")); } if (response.has("streamKey")) { liveStream.setStreamKey(response.getString("streamKey")); } if (response.has("name")) { liveStream.setName(response.getString("name")); } if (response.has("record")) { liveStream.setRecord(response.getBoolean("record")); } if (response.has("broadcasting")) { liveStream.setBroadcasting(response.getBoolean("broadcasting")); } if (response.has("assets")) { JSONObject asset = response.getJSONObject("assets"); assets.setIframe(asset.getString("iframe")); assets.setPlayer(asset.getString("player")); assets.setHls(asset.getString("hls")); assets.setThumbnail(asset.getString("thumbnail")); liveStream.setAssets(assets); } if (response.has("playerId")) { liveStream.setPlayerId(response.getString("playerId")); } return liveStream; }  LiveStream deserialize(JSONObject response); List<LiveStream> deserialize(JSONArray data); JSONObject serialize(LiveStream liveStream);  }### Answer:
@Test public void deserializeEmpty() throws JSONException { assertNull(liveJsonSerializer.deserialize(new JSONObject()).getLiveStreamId()); }
@Test public void deserializeAllEmpty() throws JSONException { assertTrue(liveJsonSerializer.deserialize(new JSONArray()).isEmpty()); }
@Test public void deserializeMinimalSuccess() throws JSONException { Map<String, String> jsonParams = new HashMap<>(); jsonParams.put("liveStreamId", "id"); LiveStream liveStream = liveJsonSerializer.deserialize(new JSONObject(jsonParams)); assertEquals("id", liveStream.getLiveStreamId()); }
@Test public void deserializeMaximalSuccess() throws JSONException { Map<Object, Object> jsonParams = new HashMap<>(); jsonParams.put("liveStreamId", "id"); jsonParams.put("streamKey", "streamKey"); jsonParams.put("name", "name"); jsonParams.put("record", true); jsonParams.put("broadcasting", true); LiveStream liveStream = liveJsonSerializer.deserialize(new JSONObject(jsonParams)); assertEquals("id", liveStream.getLiveStreamId()); assertEquals("streamKey", liveStream.getStreamKey()); assertEquals("name", liveStream.getName()); assertEquals(true, liveStream.isRecord()); assertTrue(liveStream.isBroadcasting()); }
@Test public void deserializeAllSuccess() throws JSONException { Map<String, String> jsonLive1 = new HashMap<>(); jsonLive1.put("liveStreamId", "live1"); Map<String, String> jsonLive2 = new HashMap<>(); jsonLive2.put("liveStreamId", "live2"); Map<String, String> jsonLive3 = new HashMap<>(); jsonLive3.put("liveStreamId", "live3"); List<LiveStream> liveStreamList = liveJsonSerializer.deserialize(new JSONArray() {{ put(new JSONObject(jsonLive1)); put(new JSONObject(jsonLive2)); put(new JSONObject(jsonLive3)); }}); assertEquals("live1", liveStreamList.get(0).getLiveStreamId()); assertEquals("live2", liveStreamList.get(1).getLiveStreamId()); assertEquals("live3", liveStreamList.get(2).getLiveStreamId()); }