@Test public void serializeAsJson_withAllEventFieldsPopulated_shouldCorrectJsonRepresentation() throws Exception { ArrayList<BaseEvent> events = new ArrayList<BaseEvent>(); events.add(mockEvent); JSONArray jsonArray = subject.serializeAsJson(events); assertThat(jsonArray.length()).isEqualTo(1); JSONObject jsonObject = jsonArray.getJSONObject(0); validateBaseEventFields(jsonObject); }
@NonNull public JSONArray serializeAsJson(@NonNull List<BaseEvent> events) { Preconditions.checkNotNull(events); JSONArray jsonArray = new JSONArray(); for (BaseEvent event : events) { try { jsonArray.put(serializeAsJson(event)); } catch (JSONException e) { MoPubLog.d("Failed to serialize event \"" + event.getName() + "\" to JSON: ", e); } } return jsonArray; }
EventSerializer { @NonNull public JSONArray serializeAsJson(@NonNull List<BaseEvent> events) { Preconditions.checkNotNull(events); JSONArray jsonArray = new JSONArray(); for (BaseEvent event : events) { try { jsonArray.put(serializeAsJson(event)); } catch (JSONException e) { MoPubLog.d("Failed to serialize event \"" + event.getName() + "\" to JSON: ", e); } } return jsonArray; } }
EventSerializer { @NonNull public JSONArray serializeAsJson(@NonNull List<BaseEvent> events) { Preconditions.checkNotNull(events); JSONArray jsonArray = new JSONArray(); for (BaseEvent event : events) { try { jsonArray.put(serializeAsJson(event)); } catch (JSONException e) { MoPubLog.d("Failed to serialize event \"" + event.getName() + "\" to JSON: ", e); } } return jsonArray; }  }
EventSerializer { @NonNull public JSONArray serializeAsJson(@NonNull List<BaseEvent> events) { Preconditions.checkNotNull(events); JSONArray jsonArray = new JSONArray(); for (BaseEvent event : events) { try { jsonArray.put(serializeAsJson(event)); } catch (JSONException e) { MoPubLog.d("Failed to serialize event \"" + event.getName() + "\" to JSON: ", e); } } return jsonArray; }  @NonNull JSONArray serializeAsJson(@NonNull List<BaseEvent> events); @NonNull JSONObject serializeAsJson(@NonNull BaseEvent event); }
EventSerializer { @NonNull public JSONArray serializeAsJson(@NonNull List<BaseEvent> events) { Preconditions.checkNotNull(events); JSONArray jsonArray = new JSONArray(); for (BaseEvent event : events) { try { jsonArray.put(serializeAsJson(event)); } catch (JSONException e) { MoPubLog.d("Failed to serialize event \"" + event.getName() + "\" to JSON: ", e); } } return jsonArray; }  @NonNull JSONArray serializeAsJson(@NonNull List<BaseEvent> events); @NonNull JSONObject serializeAsJson(@NonNull BaseEvent event);  }