Source:
<code>private void verifyModelParsing(CourseComponent component) { JSONObject jsonObj; try { jsonObj = new JSONObject(MockDataUtil.getMockResponse("get_course_structure")); jsonObj = jsonObj.getJSONObject("blocks"); jsonObj = jsonObj.getJSONObject(component.getId()); assertNotNull(jsonObj); assertEquals(jsonObj.getString("display_name"), component.getInternalName()); assertEquals(jsonObj.getBoolean("graded"), component.isGraded()); assertEquals(jsonObj.getString("student_view_url"), component.getBlockUrl()); assertEquals(jsonObj.getBoolean("student_view_multi_device"), component.isMultiDevice()); assertEquals(jsonObj.getString("lms_web_url"), component.getWebUrl()); Gson gson = new Gson(); switch (component.getType()) { case VIDEO: { String dataRawJson = jsonObj.getJSONObject("student_view_data").toString(); <START> assertTrue(component instanceof VideoBlockModel); <END> VideoBlockModel model = (VideoBlockModel) component; VideoData expected = gson.fromJson(dataRawJson, VideoData.class); assertEquals(expected, model.getData()); break; } case DISCUSSION: { String dataRawJson = jsonObj.getJSONObject("student_view_data").toString(); assertTrue(component instanceof DiscussionBlockModel); DiscussionBlockModel model = (DiscussionBlockModel) component; DiscussionData expected = gson.fromJson(dataRawJson, DiscussionData.class); assertEquals(expected, model.getData()); break; } } } catch (JSONException e) { fail("Error while converting raw json to JSONObject: " + e.getMessage()); } catch (IOException e) { fail("Error reading raw json: " + e.getMessage()); } }</code><technical_language>Technically, current implementation, this assertion performed if assume unique properties of video present in original JSON i.e "encoded_videos" "transcripts". improve parser some point guarantees. In meanwhile, check conditions coincide other checking raw data in this assertion, if check instead of assertion here</technical_language>

Target:
private void verifyModelParsing(CourseComponent component) throws IOException, JSONException { JSONObject jsonObj; jsonObj = new JSONObject(MockDataUtil.getMockResponse("get_course_structure")); jsonObj = jsonObj.getJSONObject("blocks"); jsonObj = jsonObj.getJSONObject(component.getId()); assertNotNull(jsonObj); assertEquals(jsonObj.getString("display_name"), component.getInternalName()); assertEquals(jsonObj.getBoolean("graded"), component.isGraded()); assertEquals(jsonObj.getString("student_view_url"), component.getBlockUrl()); assertEquals(jsonObj.getBoolean("student_view_multi_device"), component.isMultiDevice()); assertEquals(jsonObj.getString("lms_web_url"), component.getWebUrl()); Gson gson = new Gson(); switch (component.getType()) { case VIDEO: { JSONObject dataObj = jsonObj.getJSONObject("student_view_data"); assertTrue(dataObj.has("encoded_videos") || dataObj.has("transcripts")); String dataRawJson = dataObj.toString(); assertTrue(component instanceof VideoBlockModel); VideoBlockModel model = (VideoBlockModel) component; VideoData expected = gson.fromJson(dataRawJson, VideoData.class); assertEquals(expected, model.getData()); break; } case DISCUSSION: { JSONObject dataObj = jsonObj.getJSONObject("student_view_data"); assertTrue(dataObj.has("topic_id")); String dataRawJson = dataObj.toString(); assertTrue(component instanceof DiscussionBlockModel); DiscussionBlockModel model = (DiscussionBlockModel) component; DiscussionData expected = gson.fromJson(dataRawJson, DiscussionData.class); assertEquals(expected, model.getData()); break; } } }