use of tests.support.Support_UnmodifiableCollectionTest in project j2objc by google.
the class TreeMapTest method test_values.
/**
* @tests java.util.TreeMap#values()
*/
public void test_values() {
// Test for method java.util.Collection java.util.TreeMap.values()
Collection vals = tm.values();
vals.iterator();
assertTrue("Returned collection of incorrect size", vals.size() == objArray.length);
for (Object element : objArray) {
assertTrue("Collection contains incorrect elements", vals.contains(element));
}
TreeMap myTreeMap = new TreeMap();
for (int i = 0; i < 100; i++) {
myTreeMap.put(objArray[i], objArray[i]);
}
Collection values = myTreeMap.values();
new Support_UnmodifiableCollectionTest("Test Returned Collection From TreeMap.values()", values).runTest();
values.remove(new Integer(0));
assertTrue("Removing from the values collection should remove from the original map", !myTreeMap.containsValue(new Integer(0)));
}
use of tests.support.Support_UnmodifiableCollectionTest in project robovm by robovm.
the class CollectionsTest method test_unmodifiableSetLjava_util_Set.
/**
* java.util.Collections#unmodifiableSet(java.util.Set)
*/
public void test_unmodifiableSetLjava_util_Set() {
// Test for method java.util.Set
// java.util.Collections.unmodifiableSet(java.util.Set)
boolean exception = false;
Set c = Collections.unmodifiableSet(s);
assertTrue("Returned set is of incorrect size", c.size() == s.size());
Iterator i = ll.iterator();
while (i.hasNext()) assertTrue("Returned set missing elements", c.contains(i.next()));
try {
c.add(new Object());
} catch (UnsupportedOperationException e) {
exception = true;
// Correct
}
if (!exception) {
fail("Allowed modification of set");
}
try {
c.remove(new Object());
fail("Allowed modification of set");
} catch (UnsupportedOperationException e) {
// Correct
}
Set mySet = Collections.unmodifiableSet(new HashSet());
assertTrue("Should not contain null", !mySet.contains(null));
mySet = Collections.unmodifiableSet(Collections.singleton(null));
assertTrue("Should contain null", mySet.contains(null));
mySet = new TreeSet();
for (int counter = 0; counter < 100; counter++) {
mySet.add(objArray[counter]);
}
new Support_UnmodifiableCollectionTest("", Collections.unmodifiableSet(mySet)).runTest();
}
use of tests.support.Support_UnmodifiableCollectionTest in project robovm by robovm.
the class CollectionsTest method test_unmodifiableListLjava_util_List.
/**
* java.util.Collections#unmodifiableList(java.util.List)
*/
public void test_unmodifiableListLjava_util_List() {
// Test for method java.util.List
// java.util.Collections.unmodifiableList(java.util.List)
// test with a Sequential Access List
boolean exception = false;
List c = Collections.unmodifiableList(ll);
// Ensure a NPE is thrown if the list is NULL
try {
Collections.unmodifiableList(null);
fail("Expected NullPointerException for null list parameter");
} catch (NullPointerException e) {
}
assertTrue("Returned list is of incorrect size", c.size() == ll.size());
assertTrue("Returned List should not implement Random Access interface", !(c instanceof RandomAccess));
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 list");
}
try {
c.remove(new Object());
fail("Allowed modification of list");
} catch (UnsupportedOperationException e) {
// Correct
}
// test with a Random Access List
List smallList = new ArrayList();
smallList.add(null);
smallList.add("yoink");
c = Collections.unmodifiableList(smallList);
assertNull("First element should be null", c.get(0));
assertTrue("List should contain null", c.contains(null));
assertTrue("T1. Returned List should implement Random Access interface", c instanceof RandomAccess);
smallList = new ArrayList();
for (int counter = 0; counter < 100; counter++) {
smallList.add(objArray[counter]);
}
List myList = Collections.unmodifiableList(smallList);
assertTrue("List should not contain null", !myList.contains(null));
assertTrue("T2. Returned List should implement Random Access interface", myList instanceof RandomAccess);
assertTrue("get failed on unmodifiable list", myList.get(50).equals(new Integer(50)));
ListIterator listIterator = myList.listIterator();
for (int counter = 0; listIterator.hasNext(); counter++) {
assertTrue("List has wrong elements", ((Integer) listIterator.next()).intValue() == counter);
}
new Support_UnmodifiableCollectionTest("", smallList).runTest();
}
use of tests.support.Support_UnmodifiableCollectionTest in project robovm by robovm.
the class HashMapTest method test_values.
/**
* java.util.HashMap#values()
*/
public void test_values() {
// Test for method java.util.Collection java.util.HashMap.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]));
HashMap myHashMap = new HashMap();
for (int i = 0; i < 100; i++) myHashMap.put(objArray2[i], objArray[i]);
Collection values = myHashMap.values();
new Support_UnmodifiableCollectionTest("Test Returned Collection From HashMap.values()", values).runTest();
values.remove(new Integer(0));
assertTrue("Removing from the values collection should remove from the original map", !myHashMap.containsValue(new Integer(0)));
}
use of tests.support.Support_UnmodifiableCollectionTest in project robovm by robovm.
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)));
}
Aggregations