BeanContainer<String, String> container = new BeanContainer<String, String>(
String.class);
String id = "test1";
Item item = container.addItem(id, "value");
assertNotNull(item);
assertEquals(id, container.firstItemId());
assertEquals(id, container.lastItemId());
// isFirstId
assertTrue(container.isFirstId(id));
assertTrue(container.isFirstId(container.firstItemId()));
// isLastId
assertTrue(container.isLastId(id));
assertTrue(container.isLastId(container.lastItemId()));
// Add a new item before the first
// addItemAfter
String newFirstId = "newFirst";
item = container.addItemAfter(null, newFirstId, "newFirstValue");
assertNotNull(item);
assertNotNull(container.getItem(newFirstId));
// isFirstId
assertTrue(container.isFirstId(newFirstId));
assertTrue(container.isFirstId(container.firstItemId()));
// isLastId
assertTrue(container.isLastId(id));
assertTrue(container.isLastId(container.lastItemId()));
// nextItemId
assertEquals(id, container.nextItemId(newFirstId));
assertNull(container.nextItemId(id));
assertNull(container.nextItemId("not-in-container"));
// prevItemId
assertEquals(newFirstId, container.prevItemId(id));
assertNull(container.prevItemId(newFirstId));
assertNull(container.prevItemId("not-in-container"));
// addItemAfter(IDTYPE, IDTYPE, BT)
String newSecondItemId = "newSecond";
item = container.addItemAfter(newFirstId, newSecondItemId,
"newSecondValue");
// order is now: newFirstId, newSecondItemId, id
assertNotNull(item);
assertNotNull(container.getItem(newSecondItemId));
assertEquals(id, container.nextItemId(newSecondItemId));
assertEquals(newFirstId, container.prevItemId(newSecondItemId));
// addItemAfter(IDTYPE, IDTYPE, BT)
String fourthId = "id of the fourth item";
Item fourth = container.addItemAfter(newFirstId, fourthId,
"fourthValue");
// order is now: newFirstId, fourthId, newSecondItemId, id
assertNotNull(fourth);
assertEquals(fourth, container.getItem(fourthId));
assertEquals(newSecondItemId, container.nextItemId(fourthId));
assertEquals(newFirstId, container.prevItemId(fourthId));
// addItemAfter(IDTYPE, IDTYPE, BT)
String fifthId = "fifth";
Item fifth = container.addItemAfter(null, fifthId, "fifthValue");
// order is now: fifthId, newFirstId, fourthId, newSecondItemId, id
assertNotNull(fifth);
assertEquals(fifth, container.getItem(fifthId));
assertEquals(newFirstId, container.nextItemId(fifthId));
assertNull(container.prevItemId(fifthId));