@Test(expected = JsonParseException.class) public void testParseNoTeams() { mData.remove("team_keys"); mNotification = new UpcomingMatchNotification(mData.toString()); mNotification.parseMessageData(); }
@Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = new JsonParser().parse(messageData).getAsJsonObject(); if (!jsonData.has("match_key")) { throw new JsonParseException("Notification data does not contain 'match_key'"); } matchKey = jsonData.get("match_key").getAsString(); if (!jsonData.has("event_name")) { throw new JsonParseException("Notification data does not contain 'event_name'"); } eventName = jsonData.get("event_name").getAsString(); if (!jsonData.has("team_keys")) { throw new JsonParseException("Notification data does not contain 'team_keys"); } eventKey = MatchHelper.getEventKeyFromMatchKey(matchKey); teamKeys = jsonData.get("team_keys").getAsJsonArray(); ArrayList<String> teamKeyList = gson.fromJson(teamKeys, new TypeToken<List<String>>(){}.getType()); int allianceSize = teamKeyList.size() / 2; redTeams = new String[allianceSize]; blueTeams = new String[allianceSize]; for (int i = 0; i < allianceSize; ++i) { redTeams[i] = teamKeyList.get(i).substring(3); blueTeams[i] = teamKeyList.get(i + allianceSize).substring(3); } if (jsonData.has("scheduled_time")) { matchTime = jsonData.get("scheduled_time"); } else { matchTime = JsonNull.INSTANCE; } if (jsonData.has("webcast")) { webcast = jsonData.get("webcast").getAsJsonObject(); } else { webcast = JsonNull.INSTANCE; } }
UpcomingMatchNotification extends BaseNotification<UpcomingMatchNotificationViewModel> { @Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = new JsonParser().parse(messageData).getAsJsonObject(); if (!jsonData.has("match_key")) { throw new JsonParseException("Notification data does not contain 'match_key'"); } matchKey = jsonData.get("match_key").getAsString(); if (!jsonData.has("event_name")) { throw new JsonParseException("Notification data does not contain 'event_name'"); } eventName = jsonData.get("event_name").getAsString(); if (!jsonData.has("team_keys")) { throw new JsonParseException("Notification data does not contain 'team_keys"); } eventKey = MatchHelper.getEventKeyFromMatchKey(matchKey); teamKeys = jsonData.get("team_keys").getAsJsonArray(); ArrayList<String> teamKeyList = gson.fromJson(teamKeys, new TypeToken<List<String>>(){}.getType()); int allianceSize = teamKeyList.size() / 2; redTeams = new String[allianceSize]; blueTeams = new String[allianceSize]; for (int i = 0; i < allianceSize; ++i) { redTeams[i] = teamKeyList.get(i).substring(3); blueTeams[i] = teamKeyList.get(i + allianceSize).substring(3); } if (jsonData.has("scheduled_time")) { matchTime = jsonData.get("scheduled_time"); } else { matchTime = JsonNull.INSTANCE; } if (jsonData.has("webcast")) { webcast = jsonData.get("webcast").getAsJsonObject(); } else { webcast = JsonNull.INSTANCE; } } }
UpcomingMatchNotification extends BaseNotification<UpcomingMatchNotificationViewModel> { @Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = new JsonParser().parse(messageData).getAsJsonObject(); if (!jsonData.has("match_key")) { throw new JsonParseException("Notification data does not contain 'match_key'"); } matchKey = jsonData.get("match_key").getAsString(); if (!jsonData.has("event_name")) { throw new JsonParseException("Notification data does not contain 'event_name'"); } eventName = jsonData.get("event_name").getAsString(); if (!jsonData.has("team_keys")) { throw new JsonParseException("Notification data does not contain 'team_keys"); } eventKey = MatchHelper.getEventKeyFromMatchKey(matchKey); teamKeys = jsonData.get("team_keys").getAsJsonArray(); ArrayList<String> teamKeyList = gson.fromJson(teamKeys, new TypeToken<List<String>>(){}.getType()); int allianceSize = teamKeyList.size() / 2; redTeams = new String[allianceSize]; blueTeams = new String[allianceSize]; for (int i = 0; i < allianceSize; ++i) { redTeams[i] = teamKeyList.get(i).substring(3); blueTeams[i] = teamKeyList.get(i + allianceSize).substring(3); } if (jsonData.has("scheduled_time")) { matchTime = jsonData.get("scheduled_time"); } else { matchTime = JsonNull.INSTANCE; } if (jsonData.has("webcast")) { webcast = jsonData.get("webcast").getAsJsonObject(); } else { webcast = JsonNull.INSTANCE; } } UpcomingMatchNotification(String messageData); }
UpcomingMatchNotification extends BaseNotification<UpcomingMatchNotificationViewModel> { @Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = new JsonParser().parse(messageData).getAsJsonObject(); if (!jsonData.has("match_key")) { throw new JsonParseException("Notification data does not contain 'match_key'"); } matchKey = jsonData.get("match_key").getAsString(); if (!jsonData.has("event_name")) { throw new JsonParseException("Notification data does not contain 'event_name'"); } eventName = jsonData.get("event_name").getAsString(); if (!jsonData.has("team_keys")) { throw new JsonParseException("Notification data does not contain 'team_keys"); } eventKey = MatchHelper.getEventKeyFromMatchKey(matchKey); teamKeys = jsonData.get("team_keys").getAsJsonArray(); ArrayList<String> teamKeyList = gson.fromJson(teamKeys, new TypeToken<List<String>>(){}.getType()); int allianceSize = teamKeyList.size() / 2; redTeams = new String[allianceSize]; blueTeams = new String[allianceSize]; for (int i = 0; i < allianceSize; ++i) { redTeams[i] = teamKeyList.get(i).substring(3); blueTeams[i] = teamKeyList.get(i + allianceSize).substring(3); } if (jsonData.has("scheduled_time")) { matchTime = jsonData.get("scheduled_time"); } else { matchTime = JsonNull.INSTANCE; } if (jsonData.has("webcast")) { webcast = jsonData.get("webcast").getAsJsonObject(); } else { webcast = JsonNull.INSTANCE; } } UpcomingMatchNotification(String messageData); String getEventName(); String getEventKey(); String getMatchKey(); String[] getRedTeams(); String[] getBlueTeams(); JsonElement getMatchTime(); JsonArray getTeamKeys(); JsonElement getWebcast(); @Override void parseMessageData(); @Override Notification buildNotification(Context context, FollowsChecker followsChecker); @Override void updateDataLocally(); @Override Intent getIntent(Context c); @Override int getNotificationId(); @Override View getView(Context c, LayoutInflater inflater, View convertView); @Nullable @Override UpcomingMatchNotificationViewModel renderToViewModel(Context context, @Nullable Void aVoid); }
UpcomingMatchNotification extends BaseNotification<UpcomingMatchNotificationViewModel> { @Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = new JsonParser().parse(messageData).getAsJsonObject(); if (!jsonData.has("match_key")) { throw new JsonParseException("Notification data does not contain 'match_key'"); } matchKey = jsonData.get("match_key").getAsString(); if (!jsonData.has("event_name")) { throw new JsonParseException("Notification data does not contain 'event_name'"); } eventName = jsonData.get("event_name").getAsString(); if (!jsonData.has("team_keys")) { throw new JsonParseException("Notification data does not contain 'team_keys"); } eventKey = MatchHelper.getEventKeyFromMatchKey(matchKey); teamKeys = jsonData.get("team_keys").getAsJsonArray(); ArrayList<String> teamKeyList = gson.fromJson(teamKeys, new TypeToken<List<String>>(){}.getType()); int allianceSize = teamKeyList.size() / 2; redTeams = new String[allianceSize]; blueTeams = new String[allianceSize]; for (int i = 0; i < allianceSize; ++i) { redTeams[i] = teamKeyList.get(i).substring(3); blueTeams[i] = teamKeyList.get(i + allianceSize).substring(3); } if (jsonData.has("scheduled_time")) { matchTime = jsonData.get("scheduled_time"); } else { matchTime = JsonNull.INSTANCE; } if (jsonData.has("webcast")) { webcast = jsonData.get("webcast").getAsJsonObject(); } else { webcast = JsonNull.INSTANCE; } } UpcomingMatchNotification(String messageData); String getEventName(); String getEventKey(); String getMatchKey(); String[] getRedTeams(); String[] getBlueTeams(); JsonElement getMatchTime(); JsonArray getTeamKeys(); JsonElement getWebcast(); @Override void parseMessageData(); @Override Notification buildNotification(Context context, FollowsChecker followsChecker); @Override void updateDataLocally(); @Override Intent getIntent(Context c); @Override int getNotificationId(); @Override View getView(Context c, LayoutInflater inflater, View convertView); @Nullable @Override UpcomingMatchNotificationViewModel renderToViewModel(Context context, @Nullable Void aVoid);  }