public void testFindFirstPivotAfter_WhenPivot() {
    Date date = new GregorianCalendar(2015, Calendar.DECEMBER, 8).getTime();
    logTest(
        "testFindFirstPivotAfter_WhenPivot: %s, which: %s",
        Util.SIMPLE_DATE_FORMAT.format(date), ss.pkez().getName());

    TTransaction e = ts.findFirstPivotAfter(date, ss.pkez());
    log("Target pivot element is: %s", e);

    e = ts.findFirstPivotAfter(e);
    log("Pivot found: %s", e);
  }
  public void testFindLastPivotBefore() {
    Date date = new GregorianCalendar(2015, Calendar.DECEMBER, 8).getTime();
    logTest(
        "testFindLastPivotBefore: %s, which: %s",
        Util.SIMPLE_DATE_FORMAT.format(date), ss.pkez().getName());

    TTransaction e = ts.findLastPivotBefore(date, ss.pkez());
    log("Pivot found: %s", e);
  }
  public void testFindFirstPivotAfter_WhenNoPivot() {
    Date date = new GregorianCalendar(2016, Calendar.APRIL, 22).getTime();
    logTest(
        "testFindFirstPivotAfter_WhenNoPivot: %s, which: %s",
        Util.SIMPLE_DATE_FORMAT.format(date), ss.pkez().getName());

    TTransaction fromPivot = ts.findLastPivotBefore(date, ss.pkez());
    log("Pivot found before: %s", fromPivot);

    TTransaction toPivot = ts.findFirstPivotAfter(date, ss.pkez());
    log("Pivot found after : %s [should be null]", toPivot);

    List<TTransaction> dirtyElements =
        ts.findElementsBetween(
            fromPivot == null ? date : fromPivot.getDate(),
            toPivot == null ? null : toPivot.getDate(),
            ss.pkez());

    log("The dirty list is as follows:");
    for (TTransaction t : dirtyElements) log("dirty: %s", t);
  }
  public void testFindElementsBetween() {
    Date from = new GregorianCalendar(2015, Calendar.DECEMBER, 8).getTime();
    Date to = new GregorianCalendar(2016, Calendar.FEBRUARY, 20).getTime();

    logTest(
        "testFindElementsBetween: %s, %s, which: %s",
        Util.SIMPLE_DATE_FORMAT.format(from),
        Util.SIMPLE_DATE_FORMAT.format(to),
        ss.pkez().getName());

    List<TTransaction> list = ts.findElementsBetween(from, to, ss.pkez());

    for (TTransaction e : list) log("tr: %s", e);
  }
  private List<TTransaction> findDirtyElements(Date from, Date to, TChargeAccount ca) {
    TTransaction fromPivot = service.findLastPivotBefore(from, ca);
    TTransaction toPivot = service.findFirstPivotAfter(to, ca);

    info("from, to PIVOT elements [can be null as well]: ");
    info("%s", fromPivot);
    info("%s", toPivot);

    Assert.assertTrue(
        fromPivot == null
            || toPivot == null
            || fromPivot.getDate().getTime() <= toPivot.getDate().getTime());

    List<TTransaction> dirtyElements =
        service.findElementsBetween(
            fromPivot == null ? from : fromPivot.getDate(),
            toPivot == null ? null : toPivot.getDate(),
            ca);

    info("the dirty list is as follows:");
    for (TTransaction t : dirtyElements) info("%s", t);

    return dirtyElements;
  }