Ejemplo n.º 1
0
        public void TestListIterator()
        {
            Object        tempValue;
            List <Object> list = new ArrayList <Object>();

            list.Add(3);
            list.Add(5);
            list.Add(5);
            list.Add(1);
            list.Add(7);
            ListIterator <Object> lit = list.ListIterator();

            Assert.IsTrue(!lit.HasPrevious, "Should not have previous");
            Assert.IsTrue(lit.HasNext, "Should have next");
            tempValue = lit.Next();
            Assert.IsTrue(tempValue.Equals(3),
                          "next returned wrong value.  Wanted 3, got: " + tempValue);
            tempValue = lit.Previous();

            SimpleList <Object> list2 = new SimpleList <Object>();

            list2.Add(new Object());
            ListIterator <Object> lit2 = list2.ListIterator();

            lit2.Add(new Object());
            lit2.Next();

            list = new MockArrayList <Object>();
            ListIterator <Object> it = list.ListIterator();

            it.Add("one");
            it.Add("two");
            Assert.AreEqual(2, list.Size());
        }
Ejemplo n.º 2
0
        public void TestOverrideSize()
        {
            ArrayList <Object> testlist = new MockArrayList();

            // though size is overriden, it should passed without exception
            testlist.Add("test_0");
            testlist.Add("test_1");
            testlist.Add("test_2");
            testlist.Add(1, "test_3");
            testlist.Get(1);
            testlist.Remove(2);
            testlist.Set(1, "test_4");
        }
Ejemplo n.º 3
0
        public void TestLastIndexOf()
        {
            AbstractList <String> list = new MockArrayList <String>();

            String[] array = { "1", "2", "3", "4", "5", "5", "4", "3", "2", "1" };
            list.AddAll(Arrays.AsList <String>(array));

            Assert.AreEqual(-1, list.LastIndexOf(6.ToString()), "find 6 in the list do not contain 6");
            Assert.AreEqual(6, list.LastIndexOf(4.ToString()), "did not return the right location of element 4");
            Assert.AreEqual(-1, list.LastIndexOf(null), "find null in the list do not contain null element");
            list.Add(null);
            Assert.AreEqual(10, list.LastIndexOf(null), "did not return the right location of element null");
        }
Ejemplo n.º 4
0
        public void TestIteratorNext()
        {
            MockArrayList <String> t = new MockArrayList <String>();

            t.list.Add("a");
            t.list.Add("b");

            Iterator <String> it = t.Iterator();

            while (it.HasNext)
            {
                it.Next();
            }

            try
            {
                it.Next();
                Assert.Fail("Should throw NoSuchElementException");
            }
            catch (NoSuchElementException)
            {
            }

            t.Add("c");
            try
            {
                it.Remove();
                Assert.Fail("Should throw NoSuchElementException");
            }
            catch (ConcurrentModificationException)
            {
            }

            it = t.Iterator();
            try
            {
                it.Remove();
                Assert.Fail("Should throw IllegalStateException");
            }
            catch (IllegalStateException)
            {
            }

            Object value = it.Next();

            Assert.AreEqual("a", value);
        }