/** Tests if entries in DEQUQUED or DELETED state are not returned by getNext method. */ public void testGetNext() { int numberOfEntries = 5; QueueEntryImpl[] entries = new QueueEntryImpl[numberOfEntries]; SimpleQueueEntryList queueEntryList = new SimpleQueueEntryList(new MockAMQQueue("test")); // create test entries for (int i = 0; i < numberOfEntries; i++) { AMQMessage message = null; ; try { message = new MockAMQMessage(i); } catch (AMQException e) { fail("Failure to create a mock message:" + e.getMessage()); } QueueEntryImpl entry = (QueueEntryImpl) queueEntryList.add(message); entries[i] = entry; } // test getNext for not acquired entries for (int i = 0; i < numberOfEntries; i++) { QueueEntryImpl queueEntry = entries[i]; QueueEntryImpl next = queueEntry.getNext(); if (i < numberOfEntries - 1) { assertEquals("Unexpected entry from QueueEntryImpl#getNext()", entries[i + 1], next); } else { assertNull("The next entry after the last should be null", next); } } // delete second entries[1].acquire(); entries[1].delete(); // dequeue third entries[2].acquire(); entries[2].dequeue(); QueueEntryImpl next = entries[0].getNext(); assertEquals("expected forth entry", entries[3], next); next = next.getNext(); assertEquals("expected fifth entry", entries[4], next); next = next.getNext(); assertNull("The next entry after the last should be null", next); }