### Question:
BeanItemContainer extends
        AbstractBeanContainer<BEANTYPE, BEANTYPE> { @Override @SuppressWarnings("unchecked") public BeanItem<BEANTYPE> addItem(Object itemId) { return super.addBean((BEANTYPE) itemId); } BeanItemContainer(Class<? super BEANTYPE> type); @SuppressWarnings("unchecked") @Deprecated  BeanItemContainer(Collection<? extends BEANTYPE> collection);  BeanItemContainer(Class<? super BEANTYPE> type,
            Collection<? extends BEANTYPE> collection); @Override void addAll(Collection<? extends BEANTYPE> collection); @Override @SuppressWarnings("unchecked") BeanItem<BEANTYPE> addItemAfter(Object previousItemId,
            Object newItemId); @Override @SuppressWarnings("unchecked") BeanItem<BEANTYPE> addItemAt(int index, Object newItemId); @Override @SuppressWarnings("unchecked") BeanItem<BEANTYPE> addItem(Object itemId); @Override BeanItem<BEANTYPE> addBean(BEANTYPE bean);  }### Answer:
@Test public void testItemAddedEvent() { BeanItemContainer<Person> container = new BeanItemContainer<Person>( Person.class); Person bean = new Person("John"); ItemSetChangeListener addListener = createListenerMockFor(container); addListener.containerItemSetChange(EasyMock.isA(ItemAddEvent.class)); EasyMock.replay(addListener); container.addItem(bean); EasyMock.verify(addListener); }
@Test public void testItemAddedEvent_AddedItem() { BeanItemContainer<Person> container = new BeanItemContainer<Person>( Person.class); Person bean = new Person("John"); ItemSetChangeListener addListener = createListenerMockFor(container); Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener); EasyMock.replay(addListener); container.addItem(bean); assertEquals(bean, capturedEvent.getValue().getFirstItemId()); }
@Test public void testItemRemovedEvent() { BeanItemContainer<Person> container = new BeanItemContainer<Person>( Person.class); Person bean = new Person("John"); container.addItem(bean); ItemSetChangeListener removeListener = createListenerMockFor(container); removeListener.containerItemSetChange(EasyMock .isA(ItemRemoveEvent.class)); EasyMock.replay(removeListener); container.removeItem(bean); EasyMock.verify(removeListener); }
@Test public void testItemRemovedEvent_RemovedItem() { BeanItemContainer<Person> container = new BeanItemContainer<Person>( Person.class); Person bean = new Person("John"); container.addItem(bean); ItemSetChangeListener removeListener = createListenerMockFor(container); Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent( removeListener); EasyMock.replay(removeListener); container.removeItem(bean); assertEquals(bean, capturedEvent.getValue().getFirstItemId()); }
@Test public void testItemRemovedEvent_indexOfRemovedItem() { BeanItemContainer<Person> container = new BeanItemContainer<Person>( Person.class); container.addItem(new Person("Jack")); Person secondBean = new Person("John"); container.addItem(secondBean); ItemSetChangeListener removeListener = createListenerMockFor(container); Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent( removeListener); EasyMock.replay(removeListener); container.removeItem(secondBean); assertEquals(1, capturedEvent.getValue().getFirstIndex()); }
@Test public void testItemRemovedEvent_amountOfRemovedItems() { BeanItemContainer<Person> container = new BeanItemContainer<Person>( Person.class); container.addItem(new Person("Jack")); container.addItem(new Person("John")); ItemSetChangeListener removeListener = createListenerMockFor(container); Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent( removeListener); EasyMock.replay(removeListener); container.removeAllItems(); assertEquals(2, capturedEvent.getValue().getRemovedItemsCount()); }