@Test
public void getMessageUnitsForPModesInState() throws PersistenceException {

    Set<String> pmodeIds = new HashSet<>();
    // Just one result
    pmodeIds.add(TestData.userMsg5.getPModeId());
    List<IMessageUnitEntity>   result =  queryManager.getMessageUnitsForPModesInState(IUserMessage.class
                                                                                     , pmodeIds
                                                                                     , ProcessingState.DELIVERED);
    assertFalse(Utils.isNullOrEmpty(result));
    assertEquals(1 , result.size());
    assertTrue(result.get(0) instanceof IUserMessageEntity);
    // No result
    result =  queryManager.getMessageUnitsForPModesInState(IUserMessage.class, pmodeIds,
                                                            ProcessingState.READY_TO_PUSH);
    assertTrue(Utils.isNullOrEmpty(result));
    // Multiple results from one P-Mode
    result =  queryManager.getMessageUnitsForPModesInState(IMessageUnit.class, pmodeIds, ProcessingState.DELIVERED);
    assertFalse(Utils.isNullOrEmpty(result));
    assertEquals(3 , result.size());
    assertSorted(result);
    // One result from multiple P-Modes
    pmodeIds.add(TestData.error3.getPModeId());
    result =  queryManager.getMessageUnitsForPModesInState(IMessageUnit.class, pmodeIds, ProcessingState.CREATED);
    assertFalse(Utils.isNullOrEmpty(result));
    assertEquals(1 , result.size());
    assertEquals(TestData.error3.getMessageId(), result.get(0).getMessageId());
    // Multiple result from multiple P-Modes
    pmodeIds.add(TestData.userMsg2.getPModeId());
    result =  queryManager.getMessageUnitsForPModesInState(IUserMessage.class, pmodeIds, ProcessingState.DELIVERED);
    assertFalse(Utils.isNullOrEmpty(result));
    assertEquals(2 , result.size());
    assertEquals(TestData.userMsg2.getMessageId(), result.get(0).getMessageId());
    assertEquals(TestData.userMsg5.getMessageId(), result.get(1).getMessageId());
}