@Test public void serializeAsJson_withAllErrorEventFieldsPopulated_shouldCorrectJsonRepresentation() throws Exception { ArrayList<BaseEvent> events = new ArrayList<BaseEvent>(); events.add(mockErrorEvent); JSONArray jsonArray = subject.serializeAsJson(events); assertThat(jsonArray.length()).isEqualTo(1); JSONObject jsonObject = jsonArray.getJSONObject(0); validateBaseEventFields(jsonObject); assertThat(jsonObject.getString("error_exception_class_name")).isEqualTo("error_exception_class_name"); assertThat(jsonObject.getString("error_message")).isEqualTo("error_message"); assertThat(jsonObject.getString("error_stack_trace")).isEqualTo("error_stack_trace"); assertThat(jsonObject.getString("error_file_name")).isEqualTo("error_file_name"); assertThat(jsonObject.getString("error_class_name")).isEqualTo("error_class_name"); assertThat(jsonObject.getString("error_method_name")).isEqualTo("error_method_name"); assertThat(jsonObject.getInt("error_line_number")).isEqualTo(123); }
@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);  }