UserNotification extends Model { public static UserNotification create(String message, String type, long timestamp) { UserNotification userNotification = new UserNotification(); userNotification.timestamp = timestamp; userNotification.message = message; switch (type) { case "bg_alert": userNotification.bg_alert = true; break; case "calibration_alert": userNotification.calibration_alert = true; break; case "double_calibration_alert": userNotification.double_calibration_alert = true; break; case "extra_calibration_alert": userNotification.extra_calibration_alert = true; break; case "bg_unclear_readings_alert": userNotification.bg_unclear_readings_alert = true; break; case "bg_missed_alerts": userNotification.bg_missed_alerts = true; break; case "bg_rise_alert": userNotification.bg_rise_alert = true; break; case "bg_fall_alert": userNotification.bg_fall_alert = true; break; default: Log.d(TAG, "Saving workaround for: " + type + " " + message); PersistentStore.setString("UserNotification:timestamp:" + type, String.format(Locale.US, "%d", (long) timestamp)); PersistentStore.setString("UserNotification:message:" + type, message); return null; } userNotification.save(); return userNotification; }  static UserNotification lastBgAlert(); static UserNotification lastCalibrationAlert(); static UserNotification lastDoubleCalibrationAlert(); static UserNotification lastExtraCalibrationAlert(); static UserNotification GetNotificationByType(String type); static void DeleteNotificationByType(String type); static void snoozeAlert(String type, long snoozeMinutes); static UserNotification create(String message, String type, long timestamp); @Column(name = "timestamp", index = true)
    public double timestamp; @Column(name = "message")
    public String message; @Column(name = "bg_alert")
    public boolean bg_alert; @Column(name = "calibration_alert")
    public boolean calibration_alert; @Column(name = "double_calibration_alert")
    public boolean double_calibration_alert; @Column(name = "extra_calibration_alert")
    public boolean extra_calibration_alert; @Column(name = "bg_unclear_readings_alert")
    public boolean bg_unclear_readings_alert; @Column(name = "bg_missed_alerts")
    public boolean bg_missed_alerts; @Column(name = "bg_rise_alert")
    public boolean bg_rise_alert; @Column(name = "bg_fall_alert")
    public boolean bg_fall_alert; }
@Test public void createBgAlertNotification() { long timestamp = System.currentTimeMillis(); String message = "testMessage"; UserNotification userNotification = UserNotification .create(message, "bg_alert", timestamp); assertThat(userNotification).isNotNull(); assertThat(userNotification.timestamp).isWithin(0).of(timestamp); assertThat(userNotification.bg_alert).isTrue(); assertThat(userNotification.message).isEqualTo(message); }
@Test public void createCalibrationAlertNotification() { long timestamp = System.currentTimeMillis(); String message = "testMessage"; UserNotification userNotification = UserNotification .create(message, "calibration_alert", timestamp); assertThat(userNotification).isNotNull(); assertThat(userNotification.timestamp).isWithin(0).of(timestamp); assertThat(userNotification.calibration_alert).isTrue(); assertThat(userNotification.message).isEqualTo(message); }
@Test public void createDoubleCalibrationAlertNotification() { long timestamp = System.currentTimeMillis(); String message = "testMessage"; UserNotification userNotification = UserNotification .create(message, "double_calibration_alert", timestamp); assertThat(userNotification).isNotNull(); assertThat(userNotification.timestamp).isWithin(0).of(timestamp); assertThat(userNotification.double_calibration_alert).isTrue(); assertThat(userNotification.message).isEqualTo(message); }
@Test public void createExtraCalibrationAlertNotification() { long timestamp = System.currentTimeMillis(); String message = "testMessage"; UserNotification userNotification = UserNotification .create(message, "extra_calibration_alert", timestamp); assertThat(userNotification).isNotNull(); assertThat(userNotification.timestamp).isWithin(0).of(timestamp); assertThat(userNotification.extra_calibration_alert).isTrue(); assertThat(userNotification.message).isEqualTo(message); }
@Test public void createBgUnclearReadingsAlertNotification() { long timestamp = System.currentTimeMillis(); String message = "testMessage"; UserNotification userNotification = UserNotification .create(message, "bg_unclear_readings_alert", timestamp); assertThat(userNotification).isNotNull(); assertThat(userNotification.timestamp).isWithin(0).of(timestamp); assertThat(userNotification.bg_unclear_readings_alert).isTrue(); assertThat(userNotification.message).isEqualTo(message); }
@Test public void createBgMissedAlertsNotification() { long timestamp = System.currentTimeMillis(); String message = "testMessage"; UserNotification userNotification = UserNotification .create(message, "bg_missed_alerts", timestamp); assertThat(userNotification).isNotNull(); assertThat(userNotification.timestamp).isWithin(0).of(timestamp); assertThat(userNotification.bg_missed_alerts).isTrue(); assertThat(userNotification.message).isEqualTo(message); }
@Test public void createBgRiseAlertNotification() { long timestamp = System.currentTimeMillis(); String message = "testMessage"; UserNotification userNotification = UserNotification .create(message, "bg_rise_alert", timestamp); assertThat(userNotification).isNotNull(); assertThat(userNotification.timestamp).isWithin(0).of(timestamp); assertThat(userNotification.bg_rise_alert).isTrue(); assertThat(userNotification.message).isEqualTo(message); }
@Test public void createBgFallAlertNotification() { long timestamp = System.currentTimeMillis(); String message = "testMessage"; UserNotification userNotification = UserNotification .create(message, "bg_fall_alert", timestamp); assertThat(userNotification).isNotNull(); assertThat(userNotification.timestamp).isWithin(0).of(timestamp); assertThat(userNotification.bg_fall_alert).isTrue(); assertThat(userNotification.message).isEqualTo(message); }
@Test public void createNewTypeNotification() { long timestamp = System.currentTimeMillis(); String message = "testMessage"; String type = "testAlert"; UserNotification userNotification = UserNotification .create(message, type, timestamp); assertThat(userNotification).isNull(); assertThat(PersistentStore.getString("UserNotification:timestamp:" + type)) .isEqualTo(JoH.qs(timestamp)); assertThat(PersistentStore.getString("UserNotification:message:" + type)) .isEqualTo(message); }