Search in sources :

Example 1 with Support_UnmodifiableCollectionTest

use of tests.support.Support_UnmodifiableCollectionTest in project robovm by robovm.

the class CollectionsTest method test_unmodifiableCollectionLjava_util_Collection.

/**
     * java.util.Collections#unmodifiableCollection(java.util.Collection)
     */
public void test_unmodifiableCollectionLjava_util_Collection() {
    // Test for method java.util.Collection
    // java.util.Collections.unmodifiableCollection(java.util.Collection)
    boolean exception = false;
    Collection c = Collections.unmodifiableCollection(ll);
    assertTrue("Returned collection is of incorrect size", c.size() == ll.size());
    Iterator i = ll.iterator();
    while (i.hasNext()) assertTrue("Returned list missing elements", c.contains(i.next()));
    try {
        c.add(new Object());
    } catch (UnsupportedOperationException e) {
        exception = true;
    // Correct
    }
    if (!exception) {
        fail("Allowed modification of collection");
    }
    try {
        c.remove(new Object());
        fail("Allowed modification of collection");
    } catch (UnsupportedOperationException e) {
    // Correct
    }
    Collection myCollection = new ArrayList();
    myCollection.add(new Integer(20));
    myCollection.add(null);
    c = Collections.unmodifiableCollection(myCollection);
    assertTrue("Collection should contain null", c.contains(null));
    assertTrue("Collection should contain Integer(20)", c.contains(new Integer(20)));
    myCollection = new ArrayList();
    for (int counter = 0; counter < 100; counter++) {
        myCollection.add(objArray[counter]);
    }
    new Support_UnmodifiableCollectionTest("", Collections.unmodifiableCollection(myCollection)).runTest();
}
Also used : Support_UnmodifiableCollectionTest(tests.support.Support_UnmodifiableCollectionTest) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 2 with Support_UnmodifiableCollectionTest

use of tests.support.Support_UnmodifiableCollectionTest in project robovm by robovm.

the class ArraysTest method test_asList$Ljava_lang_Object.

/**
     * java.util.Arrays#asList(java.lang.Object[])
     */
public void test_asList$Ljava_lang_Object() {
    // Test for method java.util.List
    // java.util.Arrays.asList(java.lang.Object [])
    List convertedList = Arrays.asList(objectArray);
    for (int counter = 0; counter < arraySize; counter++) {
        assertTrue("Array and List converted from array do not contain identical elements", convertedList.get(counter) == objectArray[counter]);
    }
    convertedList.set(50, new Integer(1000));
    assertTrue("set/get did not work on coverted list", convertedList.get(50).equals(new Integer(1000)));
    convertedList.set(50, new Integer(50));
    new Support_UnmodifiableCollectionTest("", convertedList).runTest();
    Object[] myArray = (Object[]) (objectArray.clone());
    myArray[30] = null;
    myArray[60] = null;
    convertedList = Arrays.asList(myArray);
    for (int counter = 0; counter < arraySize; counter++) {
        assertTrue("Array and List converted from array do not contain identical elements", convertedList.get(counter) == myArray[counter]);
    }
    try {
        Arrays.asList((Object[]) null);
        fail("asList with null arg didn't throw NPE");
    } catch (NullPointerException e) {
    // Expected
    }
}
Also used : Support_UnmodifiableCollectionTest(tests.support.Support_UnmodifiableCollectionTest) List(java.util.List) LinkedList(java.util.LinkedList)

Example 3 with Support_UnmodifiableCollectionTest

use of tests.support.Support_UnmodifiableCollectionTest in project robovm by robovm.

the class HashtableTest method test_values.

/**
     * java.util.Hashtable#values()
     */
public void test_values() {
    // Test for method java.util.Collection java.util.Hashtable.values()
    Collection c = ht10.values();
    Enumeration e = elmVector.elements();
    while (e.hasMoreElements()) assertTrue("Returned incorrect values", c.contains(e.nextElement()));
    // BEGIN android-removed
    // implementation dependent
    //        assertEquals("Not synchronized",
    //                "java.util.Collections$SynchronizedCollection", c.getClass().getName());
    // END android-removed
    Hashtable myHashtable = new Hashtable();
    for (int i = 0; i < 100; i++) myHashtable.put(new Integer(i), new Integer(i));
    Collection values = myHashtable.values();
    new Support_UnmodifiableCollectionTest("Test Returned Collection From Hashtable.values()", values).runTest();
    values.remove(new Integer(0));
    assertTrue("Removing from the values collection should remove from the original map", !myHashtable.containsValue(new Integer(0)));
}
Also used : Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) Support_UnmodifiableCollectionTest(tests.support.Support_UnmodifiableCollectionTest) Collection(java.util.Collection)

Example 4 with Support_UnmodifiableCollectionTest

use of tests.support.Support_UnmodifiableCollectionTest in project j2objc by google.

the class LinkedHashMapTest method test_values.

/**
     * java.util.LinkedHashMap#values()
     */
public void test_values() {
    // Test for method java.util.Collection java.util.LinkedHashMap.values()
    Collection c = hm.values();
    assertTrue("Returned collection of incorrect size()", c.size() == hm.size());
    for (int i = 0; i < objArray.length; i++) assertTrue("Returned collection does not contain all keys", c.contains(objArray[i]));
    LinkedHashMap myLinkedHashMap = new LinkedHashMap();
    for (int i = 0; i < 100; i++) myLinkedHashMap.put(objArray2[i], objArray[i]);
    Collection values = myLinkedHashMap.values();
    new Support_UnmodifiableCollectionTest("Test Returned Collection From LinkedHashMap.values()", values).runTest();
    values.remove(new Integer(0));
    assertTrue("Removing from the values collection should remove from the original map", !myLinkedHashMap.containsValue(new Integer(0)));
}
Also used : Support_UnmodifiableCollectionTest(tests.support.Support_UnmodifiableCollectionTest) Collection(java.util.Collection) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with Support_UnmodifiableCollectionTest

use of tests.support.Support_UnmodifiableCollectionTest in project j2objc by google.

the class ArraysTest method test_asList$Ljava_lang_Object.

/**
	 * @tests java.util.Arrays#asList(java.lang.Object[])
	 */
public void test_asList$Ljava_lang_Object() {
    // Test for method java.util.List
    // java.util.Arrays.asList(java.lang.Object [])
    List convertedList = Arrays.asList(objectArray);
    for (int counter = 0; counter < arraySize; counter++) {
        assertTrue("Array and List converted from array do not contain identical elements", convertedList.get(counter) == objectArray[counter]);
    }
    convertedList.set(50, new Integer(1000));
    assertTrue("set/get did not work on coverted list", convertedList.get(50).equals(new Integer(1000)));
    convertedList.set(50, new Integer(50));
    new Support_UnmodifiableCollectionTest("", convertedList).runTest();
    Object[] myArray = (Object[]) (objectArray.clone());
    myArray[30] = null;
    myArray[60] = null;
    convertedList = Arrays.asList(myArray);
    for (int counter = 0; counter < arraySize; counter++) {
        assertTrue("Array and List converted from array do not contain identical elements", convertedList.get(counter) == myArray[counter]);
    }
    try {
        Arrays.asList((Object[]) null);
        fail("asList with null arg didn't throw NPE");
    } catch (NullPointerException e) {
    // Expected
    }
}
Also used : Support_UnmodifiableCollectionTest(tests.support.Support_UnmodifiableCollectionTest) List(java.util.List) LinkedList(java.util.LinkedList)

Aggregations

Support_UnmodifiableCollectionTest (tests.support.Support_UnmodifiableCollectionTest)15 Collection (java.util.Collection)8 Iterator (java.util.Iterator)6 ListIterator (java.util.ListIterator)6 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Enumeration (java.util.Enumeration)2 HashSet (java.util.HashSet)2 Hashtable (java.util.Hashtable)2 LinkedHashMap (java.util.LinkedHashMap)2 RandomAccess (java.util.RandomAccess)2 Set (java.util.Set)2 SortedSet (java.util.SortedSet)2 TreeSet (java.util.TreeSet)2 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1