Beispiel #1
0
        public void TestValues()
        {
            Collection <Object> c = hm.Values();

            Assert.IsTrue(c.Size() == hm.Size(), "Returned collection of incorrect Size()");
            for (int i = 0; i < objArray.Length; i++)
            {
                Assert.IsTrue(c.Contains(objArray[i]), "Returned collection does not contain all keys");
            }

            HashMap <Object, Object> myHashMap = new HashMap <Object, Object>();

            for (int i = 0; i < 100; i++)
            {
                myHashMap.Put(objArray2[i], objArray[i]);
            }

            Collection <Object> values = myHashMap.Values();

//            new Support_UnmodifiableCollectionTest(
//                 "Test Returned Collection From HashMap.Values()", values)
//                 .runTest();
            values.Remove(0);
            Assert.IsTrue(!myHashMap.ContainsValue(0),
                          "Removing from the values collection should Remove from the original map");
        }
        public void TestValues()
        {
            AbstractMap <Object, Object> map1 = new HashMap <Object, Object>(0);

            Assert.AreSame(map1.Values(), map1.Values(), "HashMap(0)");

            AbstractMap <Object, Object> map2 = new HashMap <Object, Object>(10);

            Assert.AreSame(map2.Values(), map2.Values(), "HashMap(10)");

            Map <Object, Object> map3 = CollectionUtils.EMPTY_MAP;

            Assert.AreSame(map3.Values(), map3.Values(), "EMPTY_MAP");

            AbstractMap <Object, Object> map5 = new LinkedHashMap <Object, Object>(122);

            Assert.AreSame(map5.Values(), map5.Values(), "IdentityHashMap");
        }
        public void TestNullsOnViews()
        {
            Map <String, String> nullHostile = new HashMap <String, String>();

            nullHostile.Put("a", "apple");
            TestNullsOnView(nullHostile.EntrySet());

            nullHostile.Put("a", "apple");
            TestNullsOnView(nullHostile.KeySet());

            nullHostile.Put("a", "apple");
            TestNullsOnView(nullHostile.Values());
        }
Beispiel #4
0
        public void TestClone()
        {
            HashMap <Object, Object> hm2 = (HashMap <Object, Object>)hm.Clone();

            Assert.IsTrue(hm2 != hm, "Clone answered equivalent HashMap");
            for (int counter = 0; counter < hmSize; counter++)
            {
                Assert.IsTrue(hm.Get(objArray2[counter]) == hm2.Get(objArray2[counter]), "Clone answered unequal HashMap");
            }

            HashMap <Object, Object> map = new HashMap <Object, Object>();

            map.Put("key", "value");
            // get the KeySet() and Values() on the original Map
            Set <Object>        keys   = map.KeySet();
            Collection <Object> values = map.Values();

            Assert.AreEqual("value", values.Iterator().Next(), "Values() does not work");
            Assert.AreEqual("key", keys.Iterator().Next(), "KeySet() does not work");
            AbstractMap <Object, Object> map2 = (AbstractMap <Object, Object>)map.Clone();

            map2.Put("key", "value2");
            Collection <Object> values2 = map2.Values();

            Assert.IsTrue(values2 != values, "Values() is identical");
            // Values() and KeySet() on the Cloned() map should be different
            Assert.AreEqual("value2", values2.Iterator().Next(), "Values() was not Cloned");
            map2.Clear();
            map2.Put("key2", "value3");
            Set <Object> key2 = map2.KeySet();

            Assert.IsTrue(key2 != keys, "KeySet() is identical");
            Assert.AreEqual("key2", key2.Iterator().Next(), "KeySet() was not Cloned");

            HashMap <Object, Object> hashmap = new HashMap <Object, Object>();
            MockClonable             mock    = new MockClonable(1);

            hashmap.Put(1, mock);
            Assert.AreEqual(1, ((MockClonable)hashmap.Get(1)).i);
            HashMap <Object, Object> hm3 = (HashMap <Object, Object>)hashmap.Clone();

            Assert.AreEqual(1, ((MockClonable)hm3.Get(1)).i);
            mock.i = 0;
            Assert.AreEqual(0, ((MockClonable)hashmap.Get(1)).i);
            Assert.AreEqual(0, ((MockClonable)hm3.Get(1)).i);
        }