@Test
public void getMessageUnitsWithLastStateChangedBefore() throws PersistenceException {

    // Test no result
    Collection<IMessageUnitEntity>   result =  queryManager.getMessageUnitsWithLastStateChangedBefore(daysBack(15));
    assertTrue(Utils.isNullOrEmpty(result));
    // Test one result
    result = queryManager.getMessageUnitsWithLastStateChangedBefore(daysBack(10));
    assertFalse(Utils.isNullOrEmpty(result));
    assertEquals(1 , result.size());
    IMessageUnit mu = result.iterator().next();
    assertEquals(TestData.userMsg1.getMessageId(), mu.getMessageId());
    // Check boundary case with max allowed time equal to time stamp of state
    result = queryManager.getMessageUnitsWithLastStateChangedBefore(mu.getCurrentProcessingState().getStartTime());
    assertFalse(Utils.isNullOrEmpty(result));
    assertEquals(1 , result.size());
    assertEquals(TestData.userMsg1.getMessageId(), result.iterator().next().getMessageId());
    // And now just off
    Calendar currentStateTime = Calendar.getInstance();
    currentStateTime.setTime(mu.getCurrentProcessingState().getStartTime());
    currentStateTime.add(Calendar.MINUTE, -1);
    result = queryManager.getMessageUnitsWithLastStateChangedBefore(currentStateTime.getTime());
    assertTrue(Utils.isNullOrEmpty(result));
    // Multiple results
    result = queryManager.getMessageUnitsWithLastStateChangedBefore(daysBack(6));
    assertFalse(Utils.isNullOrEmpty(result));
    assertEquals(5 , result.size());
}