use of java.util.Iterator in project j2objc by google.
the class LinkedListTest method test_toArray$Ljava_lang_Object.
/**
* @tests java.util.LinkedList#toArray(java.lang.Object[])
*/
public void test_toArray$Ljava_lang_Object() {
// Test for method java.lang.Object []
// java.util.LinkedList.toArray(java.lang.Object [])
Integer[] argArray = new Integer[100];
Object[] retArray;
retArray = ll.toArray(argArray);
assertTrue("Returned different array than passed", retArray == argArray);
List retList = new LinkedList(Arrays.asList(retArray));
Iterator li = ll.iterator();
Iterator ri = retList.iterator();
while (li.hasNext()) assertTrue("Lists are not equal", li.next() == ri.next());
argArray = new Integer[1000];
retArray = ll.toArray(argArray);
assertNull("Failed to set first extra element to null", argArray[ll.size()]);
for (int i = 0; i < ll.size(); i++) assertTrue("Returned incorrect array: " + i, retArray[i] == objArray[i]);
ll.add(50, null);
argArray = new Integer[101];
retArray = ll.toArray(argArray);
assertTrue("Returned different array than passed", retArray == argArray);
retArray = ll.toArray(argArray);
assertTrue("Returned different array than passed", retArray == argArray);
retList = new LinkedList(Arrays.asList(retArray));
li = ll.iterator();
ri = retList.iterator();
while (li.hasNext()) assertTrue("Lists are not equal", li.next() == ri.next());
}
use of java.util.Iterator in project j2objc by google.
the class HashSetTest method test_clear.
/**
* @tests java.util.HashSet#clear()
*/
public void test_clear() {
// Test for method void java.util.HashSet.clear()
Set orgSet = (Set) hs.clone();
hs.clear();
Iterator i = orgSet.iterator();
assertEquals("Returned non-zero size after clear", 0, hs.size());
while (i.hasNext()) assertTrue("Failed to clear set", !hs.contains(i.next()));
}
use of java.util.Iterator in project j2objc by google.
the class CollectionsTest method test_reverseLjava_util_List.
/**
* @tests java.util.Collections#reverse(java.util.List)
*/
public void test_reverseLjava_util_List() {
// Test for method void java.util.Collections.reverse(java.util.List)
try {
Collections.reverse(null);
fail("Expected NullPointerException for null list parameter");
} catch (NullPointerException e) {
//Expected
}
Collections.reverse(ll);
Iterator i = ll.iterator();
int count = objArray.length - 1;
while (i.hasNext()) {
assertEquals("Failed to reverse collection", objArray[count], i.next());
--count;
}
ArrayList myList = new ArrayList();
myList.add(null);
myList.add(new Integer(20));
Collections.reverse(myList);
assertEquals("Did not reverse correctly--first element is: " + myList.get(0), new Integer(20), myList.get(0));
assertNull("Did not reverse correctly--second element is: " + myList.get(1), myList.get(1));
}
use of java.util.Iterator in project j2objc by google.
the class CollectionsTest method test_unmodifiableSortedMapLjava_util_SortedMap.
/**
* @tests java.util.Collections#unmodifiableSortedMap(java.util.SortedMap)
*/
public void test_unmodifiableSortedMapLjava_util_SortedMap() {
// Test for method java.util.SortedMap
// java.util.Collections.unmodifiableSortedMap(java.util.SortedMap)
boolean exception = false;
TreeMap tm = new TreeMap();
tm.putAll(hm);
Map c = Collections.unmodifiableSortedMap(tm);
assertTrue("Returned map is of incorrect size", c.size() == tm.size());
Iterator i = hm.keySet().iterator();
while (i.hasNext()) {
Object x = i.next();
assertTrue("Returned map missing elements", c.get(x).equals(tm.get(x)));
}
try {
c.put(new Object(), "");
} catch (UnsupportedOperationException e) {
exception = true;
// Correct
}
if (!exception) {
fail("Allowed modification of map");
}
try {
c.remove(new Object());
} catch (UnsupportedOperationException e) {
// Correct
return;
}
fail("Allowed modification of map");
}
use of java.util.Iterator in project j2objc by google.
the class LinkedHashSetTest method test_iterator.
/**
* @tests java.util.LinkedHashSet#iterator()
*/
public void test_iterator() {
// Test for method java.util.Iterator java.util.LinkedHashSet.iterator()
Iterator i = hs.iterator();
int x = 0;
int j;
for (j = 0; i.hasNext(); j++) {
Object oo = i.next();
if (oo != null) {
Integer ii = (Integer) oo;
assertTrue("Incorrect element found", ii.intValue() == j);
} else {
assertTrue("Cannot find null", hs.contains(oo));
}
++x;
}
assertTrue("Returned iteration of incorrect size", hs.size() == x);
LinkedHashSet s = new LinkedHashSet();
s.add(null);
assertNull("Cannot handle null", s.iterator().next());
}
Aggregations