@Test(expected = JsonParseException.class) public void testNoEventName() { mData.remove("event_name"); mNotification = new AwardsPostedNotification(mData.toString(), mWriter); mNotification.parseMessageData(); }
@Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = JSONHelper.getasJsonObject(messageData); if (!jsonData.has("event_key")) { throw new JsonParseException("Notification data does not contain 'event_key'"); } eventKey = jsonData.get("event_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("awards") || !jsonData.get("awards").isJsonArray()) { throw new JsonParseException("Notification data does not contain 'awards' list"); } JsonArray awardArray = jsonData.get("awards").getAsJsonArray(); for (JsonElement element : awardArray) { awards.add(gson.fromJson(element, Award.class)); } }
AwardsPostedNotification extends BaseNotification<AwardsPostedNotificationViewModel> { @Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = JSONHelper.getasJsonObject(messageData); if (!jsonData.has("event_key")) { throw new JsonParseException("Notification data does not contain 'event_key'"); } eventKey = jsonData.get("event_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("awards") || !jsonData.get("awards").isJsonArray()) { throw new JsonParseException("Notification data does not contain 'awards' list"); } JsonArray awardArray = jsonData.get("awards").getAsJsonArray(); for (JsonElement element : awardArray) { awards.add(gson.fromJson(element, Award.class)); } } }
AwardsPostedNotification extends BaseNotification<AwardsPostedNotificationViewModel> { @Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = JSONHelper.getasJsonObject(messageData); if (!jsonData.has("event_key")) { throw new JsonParseException("Notification data does not contain 'event_key'"); } eventKey = jsonData.get("event_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("awards") || !jsonData.get("awards").isJsonArray()) { throw new JsonParseException("Notification data does not contain 'awards' list"); } JsonArray awardArray = jsonData.get("awards").getAsJsonArray(); for (JsonElement element : awardArray) { awards.add(gson.fromJson(element, Award.class)); } } AwardsPostedNotification(String messageData, AwardListWriter writer); }
AwardsPostedNotification extends BaseNotification<AwardsPostedNotificationViewModel> { @Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = JSONHelper.getasJsonObject(messageData); if (!jsonData.has("event_key")) { throw new JsonParseException("Notification data does not contain 'event_key'"); } eventKey = jsonData.get("event_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("awards") || !jsonData.get("awards").isJsonArray()) { throw new JsonParseException("Notification data does not contain 'awards' list"); } JsonArray awardArray = jsonData.get("awards").getAsJsonArray(); for (JsonElement element : awardArray) { awards.add(gson.fromJson(element, Award.class)); } } AwardsPostedNotification(String messageData, AwardListWriter writer); String getEventName(); String getEventKey(); List<Award> getAwards(); @Override void parseMessageData(); @Override Notification buildNotification(Context context, FollowsChecker followsChecker); @Override void updateDataLocally(); @Override Intent getIntent(Context context); @Override int getNotificationId(); @Override View getView(Context c, LayoutInflater inflater, View convertView); @Nullable @Override AwardsPostedNotificationViewModel renderToViewModel(Context context, @Nullable Void aVoid); }
AwardsPostedNotification extends BaseNotification<AwardsPostedNotificationViewModel> { @Override public void parseMessageData() throws JsonParseException { JsonObject jsonData = JSONHelper.getasJsonObject(messageData); if (!jsonData.has("event_key")) { throw new JsonParseException("Notification data does not contain 'event_key'"); } eventKey = jsonData.get("event_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("awards") || !jsonData.get("awards").isJsonArray()) { throw new JsonParseException("Notification data does not contain 'awards' list"); } JsonArray awardArray = jsonData.get("awards").getAsJsonArray(); for (JsonElement element : awardArray) { awards.add(gson.fromJson(element, Award.class)); } } AwardsPostedNotification(String messageData, AwardListWriter writer); String getEventName(); String getEventKey(); List<Award> getAwards(); @Override void parseMessageData(); @Override Notification buildNotification(Context context, FollowsChecker followsChecker); @Override void updateDataLocally(); @Override Intent getIntent(Context context); @Override int getNotificationId(); @Override View getView(Context c, LayoutInflater inflater, View convertView); @Nullable @Override AwardsPostedNotificationViewModel renderToViewModel(Context context, @Nullable Void aVoid);  }