NSEmulatorReceiver extends BroadcastReceiver { public static BgReading bgReadingInsertFromData(long timestamp, double sgv, double slope, boolean do_notification) { Log.d(TAG, "bgReadingInsertFromData called timestamp = " + timestamp + " bg = " + sgv + " time =" + JoH.dateTimeText(timestamp)); final JSONObject faux_bgr = new JSONObject(); try { faux_bgr.put("timestamp", timestamp); faux_bgr.put("calculated_value", sgv); faux_bgr.put("filtered_calculated_value", sgv); faux_bgr.put("calculated_value_slope", slope); faux_bgr.put("raw_data", sgv); faux_bgr.put("age_adjusted_raw_value", sgv); faux_bgr.put("filtered_data", sgv); faux_bgr.put("uuid", UUID.randomUUID().toString()); } catch (JSONException e) { UserError.Log.e(TAG, "bgReadingInsertFromData Got JSON exception: " + e); return null; } Log.d(TAG, "Received NSEmulator SGV: " + faux_bgr); return bgReadingInsertFromJson(faux_bgr.toString(), do_notification, true); }  @Override void onReceive(final Context context, final Intent intent); static BgReading bgReadingInsertFromData(long timestamp, double sgv, double slope, boolean do_notification);  }
@Test public void bgReadingInsertFromDataTest() throws JSONException { final JSONObject json_object = new JSONObject(); json_object.put("date", 1526717691000.0); json_object.put("sgv", 148); json_object.put("direction", "SingleUp"); final BgReading result = NSEmulatorReceiver.bgReadingInsertFromData(json_object.getLong("date"), json_object.getDouble("sgv"), BgReading.slopefromName(json_object.getString("direction")), true); assertWithMessage("result not null").that(result).isNotNull(); assertWithMessage("direction matches").that(result.slopeName()).isEqualTo("SingleUp"); assertWithMessage("timestamp matches").that(result.timestamp).isEqualTo(1526717691000L); assertWithMessage("sgv matches 1").that(result.calculated_value).isEqualTo(148d); assertWithMessage("sgv matches 2").that(result.filtered_calculated_value).isEqualTo(148d); assertWithMessage("sgv matches 3").that(result.raw_data).isEqualTo(148d); assertWithMessage("sgv matches 4").that(result.filtered_data).isEqualTo(148d); }