@Test
public void dataQualityCheckTest() {

    assertWithMessage("No sensor invalid time should fail").that(PersistentHigh.dataQualityCheck(1000, HIGH_MARK)).isFalse();
    assertWithMessage("No sensor ok time should fail").that(PersistentHigh.dataQualityCheck(START_TIME, HIGH_MARK)).isFalse();
    assertWithMessage("No sensor ok time should fail 2").that(PersistentHigh.dataQualityCheck(JoH.tsl(), HIGH_MARK)).isFalse();
    Sensor.create(1005);
    assertWithMessage("Predating sensor should fail").that(PersistentHigh.dataQualityCheck(1000, HIGH_MARK)).isFalse();
    assertWithMessage("Post sensor start no data should fail").that(PersistentHigh.dataQualityCheck(JoH.tsl(), HIGH_MARK)).isFalse();
    Sensor.create(START_TIME);
    // various all high time slices
    for (int i = 0; i < (12 * 4); i++) {
        final long timestamp = START_TIME + Constants.MINUTE_IN_MS * 5 * i;
        final BgReading bgr = BgReading.bgReadingInsertFromG5(400, timestamp);
        assertWithMessage("Test result A: " + i + " " + JoH.dateTimeText(timestamp) + " different to expected")
                .that(PersistentHigh.dataQualityCheck(START_TIME + Constants.MINUTE_IN_MS * 10, HIGH_MARK))
                .isEqualTo(i > 16);
    }
    START_TIME++;
    Sensor.create(START_TIME);
    // single dipped point in sequence after a point we might have succeeded
    for (int i = 0; i < (12 * 4); i++) {
        final long timestamp = START_TIME + Constants.MINUTE_IN_MS * 5 * i;
        final BgReading bgr = BgReading.bgReadingInsertFromG5(i == 20 ? 100 : 400, timestamp);
        assertWithMessage("Test result C: " + i + " " + JoH.dateTimeText(timestamp) + " different to expected")
                .that(PersistentHigh.dataQualityCheck(START_TIME + Constants.MINUTE_IN_MS * 10, HIGH_MARK))
                .isEqualTo(i > 16 && i < 20);
    }
    START_TIME++;
    Sensor.create(START_TIME);
    // single dipped point in sequence before we would succeed
    for (int i = 0; i < (12 * 4); i++) {
        final long timestamp = START_TIME + Constants.MINUTE_IN_MS * 5 * i;
        final BgReading bgr = BgReading.bgReadingInsertFromG5(i == 8 ? 100 : 400, timestamp);
        assertWithMessage("Test result D: " + i + " " + JoH.dateTimeText(timestamp) + " different to expected")
                .that(PersistentHigh.dataQualityCheck(START_TIME + Constants.MINUTE_IN_MS * 10, HIGH_MARK))
                .isFalse();
    }
    // Extract all log messages for tag
    List<String> logMessages = ShadowLog.getLogsForTag("PersistentHigh").stream()
            .map(log -> log.msg)
            .collect(Collectors.toList());
    // Assert on log output
    assertThat(logMessages).contains("Cannot raise persistent high alert as readings frequency is: 3 hours");
    // Print all logs
    printLogs("PersistentHigh");
}