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();
}
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
}
}
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)));
}
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)));
}
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
}
}
Aggregations