/** Tests hasNextElement() method. */
  @Test
  public void testHasNextElement() {
    TrasnactionGroupByCommandAndTypeIterator iterator =
        new TrasnactionGroupByCommandAndTypeIterator();
    iterator.initialize(Collections.<TransactionJobDescriptorEntry>emptyList(), null);
    Assert.assertFalse(iterator.hasNextElement());

    List<TransactionJobDescriptorEntry> list = new ArrayList<TransactionJobDescriptorEntry>();
    list.add(new TransactionJobDescriptorEntryImpl());
    list.add(new TransactionJobDescriptorEntryImpl());
    iterator.initialize(list, null);
    Assert.assertTrue(iterator.hasNextElement());
  }
  /** Tests TrasnactionGroupByCommandAndTypeIterator.nextElement() method. */
  @Test
  public void testNextElementCommandAndType() {
    TrasnactionGroupByCommandAndTypeIterator iterator =
        new TrasnactionGroupByCommandAndTypeIterator();

    final TransactionJobDescriptorEntryImpl descriptorEntry1 =
        new TransactionJobDescriptorEntryImpl();
    descriptorEntry1.setCommand(Command.REMOVE);
    descriptorEntry1.setGuid("dd1");
    descriptorEntry1.setType(ProductImpl.class);

    final TransactionJobDescriptorEntryImpl descriptorEntry2 =
        new TransactionJobDescriptorEntryImpl();
    descriptorEntry2.setCommand(Command.REMOVE);
    descriptorEntry2.setGuid("dd2");
    descriptorEntry2.setType(ProductImpl.class);

    final TransactionJobDescriptorEntryImpl descriptorEntry3 =
        new TransactionJobDescriptorEntryImpl();
    descriptorEntry3.setCommand(Command.UPDATE);
    descriptorEntry3.setGuid("dd3");
    descriptorEntry3.setType(ProductImpl.class);

    final TransactionJobDescriptorEntryImpl descriptorEntry4 =
        new TransactionJobDescriptorEntryImpl();
    descriptorEntry4.setCommand(Command.UPDATE);
    descriptorEntry4.setGuid("dd4");
    descriptorEntry4.setType(CategoryImpl.class);

    final TransactionJobDescriptorEntryImpl descriptorEntry5 =
        new TransactionJobDescriptorEntryImpl();
    descriptorEntry5.setCommand(Command.UPDATE);
    descriptorEntry5.setGuid("dd5");
    descriptorEntry5.setType(CategoryImpl.class);

    List<TransactionJobDescriptorEntry> entryList = new ArrayList<TransactionJobDescriptorEntry>();
    entryList.add(descriptorEntry1);
    entryList.add(descriptorEntry2);
    entryList.add(descriptorEntry3);
    entryList.add(descriptorEntry4);
    entryList.add(descriptorEntry5);

    iterator.initialize(entryList, null);
    Assert.assertTrue(iterator.hasNextElement());

    final List<TransactionJobDescriptorEntry> nextElement1 = iterator.nextElement();
    Assert.assertEquals(2, nextElement1.size());

    Assert.assertEquals(descriptorEntry1, nextElement1.get(0));
    Assert.assertEquals(descriptorEntry2, nextElement1.get(1));
    Assert.assertTrue(iterator.hasNextElement());

    final List<TransactionJobDescriptorEntry> nextElement2 = iterator.nextElement();
    Assert.assertEquals(1, nextElement2.size());

    Assert.assertEquals(descriptorEntry3, nextElement2.get(0));
    Assert.assertTrue(iterator.hasNextElement());

    final List<TransactionJobDescriptorEntry> nextElement3 = iterator.nextElement();
    Assert.assertEquals(2, nextElement3.size());

    Assert.assertEquals(descriptorEntry4, nextElement3.get(0));
    Assert.assertEquals(descriptorEntry5, nextElement3.get(1));
    Assert.assertFalse(iterator.hasNextElement());
  }