@Test
public void getMessageUnitsInState() throws PersistenceException {

    // First test query on one state and one result
    List<IUserMessageEntity> usrMsgOnlyResult = queryManager.getMessageUnitsInState(IUserMessage.class,
                                                            Direction.OUT,
                                                            new ProcessingState[] { ProcessingState.SUBMITTED });
    assertFalse(Utils.isNullOrEmpty(usrMsgOnlyResult));
    assertEquals(1 , usrMsgOnlyResult.size());
    assertTrue(usrMsgOnlyResult.get(0) instanceof IUserMessageEntity);
    // Test on one state with multiple results
    List<IMessageUnitEntity>   result =  queryManager.getMessageUnitsInState(IMessageUnit.class,
                                                            Direction.OUT,
                                                            new ProcessingState[] { ProcessingState.DELIVERED });
    assertFalse(Utils.isNullOrEmpty(result));
    assertEquals(3 , result.size());
    assertSorted(result);
    // Test no result
    result = queryManager.getMessageUnitsInState(IMessageUnit.class,
                                                 Direction.IN,
                                                 new ProcessingState[] { ProcessingState.FAILURE });
    assertTrue(Utils.isNullOrEmpty(result));
    // Test with multiple states
    result = queryManager.getMessageUnitsInState(IMessageUnit.class,
                                                 Direction.IN,
                                                 new ProcessingState[] { ProcessingState.FAILURE,
                                                                         ProcessingState.RECEIVED,
                                                                         ProcessingState.DONE
                                                                       });
    assertFalse(Utils.isNullOrEmpty(result));
    assertEquals(4 , result.size());
    assertSorted(result);
}