import junit.framework.TestCase; import com.nurey.ObservableCollection.*; import java.util.*; /** * <> * * @author Ilia Lobsanov <> * @version $Rev$ */ public class ObservableListTest extends TestCase implements ListListener { private ObservableList list; private TestListListener listener; private Enum expectedAction; private ArrayList expectedElements; /** * Sets up the test fixture. * * Called before every test case method. */ protected void setUp() { expectedElements = new ArrayList(); String bar = "bar"; String baz = "baz"; list = new ObservableList(); list.add(bar); list.add(baz); listener = new TestListListener(); list.register(listener); list.register(this); } /** * Tears down the test fixture. * * Called after every test case method. */ protected void tearDown() { // release objects under test here, if necessary list.unregister(this); list.unregister(listener); } public void update(ObservableList list, Enum action, ArrayList affectedElements) { assertEquals(this.expectedAction, action); assertEquals(this.expectedElements.toString(), affectedElements.toString()); } /** * Tests adding an item to the list */ public void testAdd() { String foo = "foo"; this.expectedAction = ObservableList.Action.ADDED; this.expectedElements.add(foo); list.add(foo); } /** * Tests adding an item to the list via an index */ public void testAddIndex() { String foo = "foo"; this.expectedAction = ObservableList.Action.ADDED; this.expectedElements.add(foo); list.add(0, foo); //add foo as the first element } /** * Tests removing an item from the list. * */ public void testRemove() { String bar = "bar"; this.expectedAction = ObservableList.Action.REMOVED; this.expectedElements.add(bar); list.remove(bar); } /** * Tests removing an item from the list via an index * */ public void testRemoveIndex() { String bar = "bar"; this.expectedAction = ObservableList.Action.REMOVED; this.expectedElements.add(bar); list.remove(0); } /** * Tests removing items from the list by specifying fromIndex, toIndex * */ public void testRemoveRange() { String bar = "bar"; String baz = "baz"; this.expectedAction = ObservableList.Action.REMOVED; this.expectedElements.add(bar); this.expectedElements.add(baz); list.removeRange(0, 2); } }