summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2011-06-08 16:39:24 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-06-08 16:39:24 -0700
commit6abb9fbb22a2847d2cd545462c33aeb986c0402d (patch)
tree116407c5a69eaeff6c37b37b37e971ff5a074022
parentaa6f3711948885fa0690496710412148e77a0c1f (diff)
parent789c3a2e66efcf45c5b1c3cfd457dda7ce4f4ad8 (diff)
downloadlibcore-6abb9fbb22a2847d2cd545462c33aeb986c0402d.zip
libcore-6abb9fbb22a2847d2cd545462c33aeb986c0402d.tar.gz
libcore-6abb9fbb22a2847d2cd545462c33aeb986c0402d.tar.bz2
Merge "Deduplicate from Harmony's java.util tests."
-rw-r--r--luni/src/test/java/libcore/java/util/OldAbstractMapTest.java121
-rw-r--r--luni/src/test/java/libcore/java/util/OldAbstractSetTest.java (renamed from luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractSetTest.java)4
-rw-r--r--luni/src/test/java/libcore/java/util/OldCollectionsTest.java (renamed from luni/src/test/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java)4
-rw-r--r--luni/src/test/java/libcore/java/util/OldEventListenerProxyTest.java (renamed from luni/src/test/java/org/apache/harmony/luni/tests/java/util/EventListenerProxyTest.java)8
-rw-r--r--luni/src/test/java/libcore/java/util/OldFormattableTest.java (renamed from luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormattableTest.java)4
-rw-r--r--luni/src/test/java/libcore/java/util/OldLinkedHashMapTest.java68
-rw-r--r--luni/src/test/java/libcore/java/util/OldListIteratorTest.java (renamed from luni/src/test/java/org/apache/harmony/luni/tests/java/util/ListIteratorTest.java)4
-rw-r--r--luni/src/test/java/libcore/java/util/OldMapEntryTest.java (renamed from luni/src/test/java/org/apache/harmony/luni/tests/java/util/MapEntryTest.java)4
-rw-r--r--luni/src/test/java/libcore/java/util/OldObserverTest.java (renamed from luni/src/test/java/org/apache/harmony/luni/tests/java/util/ObserverTest.java)15
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractCollectionTest.java339
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractMapTest.java431
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/ArrayListTest.java1005
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/ArraysTest.java3520
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/DictionaryTest.java70
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/DuplicateFormatFlagsExceptionTest.java94
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormatFlagsConversionMismatchExceptionTest.java115
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormatterClosedExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java773
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java436
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatCodePointExceptionTest.java91
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatConversionExceptionTest.java115
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatFlagsExceptionTest.java94
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatPrecisionExceptionTest.java92
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatWidthExceptionTest.java93
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/InputMismatchExceptionTest.java67
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/InvalidPropertiesFormatExceptionTest.java50
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/LinkedHashMapTest.java694
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/MissingFormatArgumentExceptionTest.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/MissingFormatWidthExceptionTest.java95
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/UUIDTest.java457
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/UnknownFormatFlagsExceptionTest.java94
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java1308
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/util/WeakHashMapTest.java482
33 files changed, 206 insertions, 10680 deletions
diff --git a/luni/src/test/java/libcore/java/util/OldAbstractMapTest.java b/luni/src/test/java/libcore/java/util/OldAbstractMapTest.java
new file mode 100644
index 0000000..14c4dd0
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/OldAbstractMapTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util;
+
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import junit.framework.TestCase;
+
+public class OldAbstractMapTest extends TestCase {
+
+ public void test_Constructor() {
+ AMT amt = new AMT();
+ assertNotNull(amt);
+ }
+
+ public void test_equalsLjava_lang_Object() {
+ AbstractMap<String, String> amt1 = new AMT();
+ AbstractMap<String, String> amt2 = new AMT();
+ assertTrue("assert 0", amt1.equals(amt2));
+ assertTrue("assert 1", amt1.equals(amt1));
+ assertTrue("assert 2", amt2.equals(amt1));
+ amt1.put("1", "one");
+ assertFalse("assert 3", amt1.equals(amt2));
+ amt1.put("2", "two");
+ amt1.put("3", "three");
+
+ amt2.put("1", "one");
+ amt2.put("2", "two");
+ amt2.put("3", "three");
+ assertTrue("assert 4", amt1.equals(amt2));
+ assertFalse("assert 5", amt1.equals(this));
+ }
+
+ public void test_hashCode() {
+ AMT amt1 = new AMT();
+ AMT amt2 = new AMT();
+ amt1.put("1", "one");
+
+ assertNotSame(amt1.hashCode(), amt2.hashCode());
+ }
+
+ public void test_isEmpty() {
+ AMT amt = new AMT();
+ assertTrue(amt.isEmpty());
+ amt.put("1", "one");
+ assertFalse(amt.isEmpty());
+ }
+
+ public void test_put() {
+ AMT amt = new AMT();
+ assertEquals(0, amt.size());
+ amt.put("1", "one");
+ assertEquals(1, amt.size());
+ amt.put("2", "two");
+ assertEquals(2, amt.size());
+ amt.put("3", "three");
+ assertEquals(3, amt.size());
+ }
+
+ public void test_size() {
+ AMT amt = new AMT();
+ assertEquals(0, amt.size());
+ amt.put("1", "one");
+ assertEquals(1, amt.size());
+ amt.put("2", "two");
+ assertEquals(2, amt.size());
+ amt.put("3", "three");
+ assertEquals(3, amt.size());
+ }
+
+ public void test_toString() {
+ AMT amt = new AMT();
+ assertEquals("{}", amt.toString());
+ amt.put("1", "one");
+ assertEquals("{1=one}", amt.toString());
+ amt.put("2", "two");
+ assertEquals("{1=one, 2=two}", amt.toString());
+ amt.put("3", "three");
+ assertEquals("{1=one, 2=two, 3=three}", amt.toString());
+ }
+
+ static class AMT extends AbstractMap<String, String> {
+ private final List<Entry<String, String>> entries = new ArrayList<Entry<String, String>>();
+
+ @Override public String put(String key, String value) {
+ String result = remove(key);
+ entries.add(new AbstractMap.SimpleEntry<String, String>(key, value));
+ return result;
+ }
+
+ @Override public Set<Entry<String, String>> entrySet() {
+ return new AbstractSet<Entry<String, String>>() {
+ @Override public Iterator<Entry<String, String>> iterator() {
+ return entries.iterator();
+ }
+ @Override public int size() {
+ return entries.size();
+ }
+ };
+ }
+ }
+}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractSetTest.java b/luni/src/test/java/libcore/java/util/OldAbstractSetTest.java
index f990b33..26e0519 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractSetTest.java
+++ b/luni/src/test/java/libcore/java/util/OldAbstractSetTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.apache.harmony.luni.tests.java.util;
+package libcore.java.util;
import junit.framework.TestCase;
@@ -24,7 +24,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Vector;
-public class AbstractSetTest extends TestCase {
+public class OldAbstractSetTest extends TestCase {
class Mock_AbstractSet extends AbstractSet{
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java b/luni/src/test/java/libcore/java/util/OldCollectionsTest.java
index 84d498d..17dca67 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/CollectionsTest.java
+++ b/luni/src/test/java/libcore/java/util/OldCollectionsTest.java
@@ -15,7 +15,7 @@
* the License.
*/
-package org.apache.harmony.luni.tests.java.util;
+package libcore.java.util;
import junit.framework.TestCase;
@@ -44,7 +44,7 @@ import org.apache.harmony.testframework.serialization.SerializationTest.Serializ
import tests.util.SerializationTester;
-public class CollectionsTest extends TestCase {
+public class OldCollectionsTest extends TestCase {
private static final SerializableAssert comparator = new SerializableAssert() {
public void assertDeserialized(Serializable reference, Serializable test) {
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/EventListenerProxyTest.java b/luni/src/test/java/libcore/java/util/OldEventListenerProxyTest.java
index 11e8c26..8007ba6 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/EventListenerProxyTest.java
+++ b/luni/src/test/java/libcore/java/util/OldEventListenerProxyTest.java
@@ -14,25 +14,22 @@
* limitations under the License.
*/
-package org.apache.harmony.luni.tests.java.util;
+package libcore.java.util;
import junit.framework.TestCase;
import java.util.EventListener;
import java.util.EventListenerProxy;
-public class EventListenerProxyTest extends TestCase {
+public class OldEventListenerProxyTest extends TestCase {
class Mock_EventListener implements EventListener {
-
}
class Mock_EventListenerProxy extends EventListenerProxy {
-
public Mock_EventListenerProxy(EventListener listener) {
super(listener);
}
-
}
public void testEventListenerProxy() {
@@ -46,5 +43,4 @@ public class EventListenerProxyTest extends TestCase {
assertSame(el, elp.getListener());
}
-
}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormattableTest.java b/luni/src/test/java/libcore/java/util/OldFormattableTest.java
index e972bdd..c272f8d 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormattableTest.java
+++ b/luni/src/test/java/libcore/java/util/OldFormattableTest.java
@@ -14,14 +14,14 @@
* limitations under the License.
*/
-package org.apache.harmony.luni.tests.java.util;
+package libcore.java.util;
import junit.framework.TestCase;
import java.util.Formattable;
import java.util.Formatter;
-public class FormattableTest extends TestCase {
+public class OldFormattableTest extends TestCase {
class Mock_Formattable implements Formattable {
boolean flag = false;
diff --git a/luni/src/test/java/libcore/java/util/OldLinkedHashMapTest.java b/luni/src/test/java/libcore/java/util/OldLinkedHashMapTest.java
new file mode 100644
index 0000000..0cbd95d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/OldLinkedHashMapTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util;
+
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import junit.framework.TestCase;
+
+public class OldLinkedHashMapTest extends TestCase {
+
+ public void testLinkedHashMap() {
+ // we want to test the LinkedHashMap in access ordering mode.
+ LinkedHashMap map = new LinkedHashMap<String, String>(10, 0.75f, true);
+
+ map.put("key1", "value1");
+ map.put("key2", "value2");
+ map.put("key3", "value3");
+
+ Iterator iterator = map.keySet().iterator();
+ String id = (String) iterator.next();
+ map.get(id);
+ try {
+ iterator.next();
+ // A LinkedHashMap is supposed to throw this Exception when a
+ // iterator.next() Operation takes place after a get
+ // Operation. This is because the get Operation is considered
+ // a structural modification if the LinkedHashMap is in
+ // access order mode.
+ fail("expected ConcurrentModificationException was not thrown.");
+ } catch(ConcurrentModificationException expected) {
+ }
+
+ LinkedHashMap mapClone = (LinkedHashMap) map.clone();
+
+ iterator = map.keySet().iterator();
+ id = (String) iterator.next();
+ mapClone.get(id);
+ iterator.next();
+
+ try {
+ new LinkedHashMap<String, String>(-10, 0.75f, true);
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException expected) {
+ }
+
+ try {
+ new LinkedHashMap<String, String>(10, -0.75f, true);
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ListIteratorTest.java b/luni/src/test/java/libcore/java/util/OldListIteratorTest.java
index 3a1ca8d..0b3812f 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ListIteratorTest.java
+++ b/luni/src/test/java/libcore/java/util/OldListIteratorTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.apache.harmony.luni.tests.java.util;
+package libcore.java.util;
import junit.framework.TestCase;
@@ -22,7 +22,7 @@ import java.util.LinkedList;
import java.util.ListIterator;
import java.util.NoSuchElementException;
-public class ListIteratorTest extends TestCase {
+public class OldListIteratorTest extends TestCase {
ListIterator<Integer> l = null;
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/MapEntryTest.java b/luni/src/test/java/libcore/java/util/OldMapEntryTest.java
index c3e7a9c..ef8add5 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/MapEntryTest.java
+++ b/luni/src/test/java/libcore/java/util/OldMapEntryTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.apache.harmony.luni.tests.java.util;
+package libcore.java.util;
import junit.framework.TestCase;
@@ -24,7 +24,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-public class MapEntryTest extends TestCase {
+public class OldMapEntryTest extends TestCase {
Map.Entry me = null;
HashMap hm = null;
Iterator i = null;
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ObserverTest.java b/luni/src/test/java/libcore/java/util/OldObserverTest.java
index acba163..62b9161 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ObserverTest.java
+++ b/luni/src/test/java/libcore/java/util/OldObserverTest.java
@@ -14,14 +14,13 @@
* limitations under the License.
*/
-package org.apache.harmony.luni.tests.java.util;
-
-import junit.framework.TestCase;
+package libcore.java.util;
import java.util.Observable;
import java.util.Observer;
+import junit.framework.TestCase;
-public class ObserverTest extends TestCase {
+public class OldObserverTest extends TestCase {
class Mock_Observer implements Observer {
int updateCount = 0;
@@ -39,10 +38,6 @@ public class ObserverTest extends TestCase {
public void doChange() {
setChanged();
}
-
- public void clearChange() {
- clearChanged();
- }
}
public void testUpdate() {
@@ -50,9 +45,9 @@ public class ObserverTest extends TestCase {
Mock_Observer observer = null;
observable.addObserver(observer = new Mock_Observer());
observable.notifyObservers();
- assertEquals("Notified when unchnaged", 0, observer.getUpdateCount());
+ assertEquals(0, observer.getUpdateCount());
observable.doChange();
observable.notifyObservers();
- assertEquals("Failed to notify", 1, observer.getUpdateCount());
+ assertEquals(1, observer.getUpdateCount());
}
}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractCollectionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractCollectionTest.java
deleted file mode 100644
index 348a83c..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractCollectionTest.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.util.AbstractCollection;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import junit.framework.TestCase;
-
-public class AbstractCollectionTest extends TestCase {
-
- /**
- * java.util.AbstractCollection#add(java.lang.Object)
- */
- public void test_addLjava_lang_Object() {
- AbstractCollection<Object> ac = new AbstractCollection<Object>() {
-
- @Override
- public Iterator<Object> iterator() {
- fail("iterator should not get called");
- return null;
- }
-
- @Override
- public int size() {
- fail("size should not get called");
- return 0;
- }
-
- };
- try {
- ac.add(null);
- } catch (UnsupportedOperationException e) {
- }
- }
-
- /**
- * java.util.AbstractCollection#addAll(java.util.Collection)
- */
- public void test_addAllLjava_util_Collection() {
- final Collection<String> fixtures = Arrays.asList("0", "1", "2");
- AbstractCollection<String> ac = new AbstractCollection<String>() {
-
- @Override
- public boolean add(String object) {
- assertTrue(fixtures.contains(object));
- return true;
- }
-
- @Override
- public Iterator<String> iterator() {
- fail("iterator should not get called");
- return null;
- }
-
- @Override
- public int size() {
- fail("size should not get called");
- return 0;
- }
-
- };
- assertTrue(ac.addAll(fixtures));
- }
-
- /**
- * java.util.AbstractCollection#containsAll(java.util.Collection)
- */
- public void test_containsAllLjava_util_Collection() {
- final Collection<String> fixtures = Arrays.asList("0", "1", "2");
- AbstractCollection<String> ac = new AbstractCollection<String>() {
-
- @Override
- public boolean contains(Object object) {
- assertTrue(fixtures.contains(object));
- return true;
- }
-
- @Override
- public Iterator<String> iterator() {
- fail("iterator should not get called");
- return null;
- }
-
- @Override
- public int size() {
- fail("size should not get called");
- return 0;
- }
-
- };
- assertTrue(ac.containsAll(fixtures));
- }
-
- /**
- * java.util.AbstractCollection#isEmpty()
- */
- public void test_isEmpty() {
- final boolean[] sizeCalled = new boolean[1];
- AbstractCollection<Object> ac = new AbstractCollection<Object>(){
- @Override
- public Iterator<Object> iterator() {
- fail("iterator should not get called");
- return null;
- }
- @Override
- public int size() {
- sizeCalled[0] = true;
- return 0;
- }
- };
- assertTrue(ac.isEmpty());
- assertTrue(sizeCalled[0]);
- }
-
- /**
- * java.util.AbstractCollection#removeAll(java.util.Collection)
- */
- public void test_removeAllLjava_util_Collection() {
- final String[] removed = new String[3];
- AbstractCollection<String> ac = new AbstractCollection<String>() {
-
- @Override
- public Iterator<String> iterator() {
- return new Iterator<String>() {
- String[] values = new String[] {"0", "1", "2"};
- int index;
- public boolean hasNext() {
- return index < values.length;
- }
-
- public String next() {
- return values[index++];
- }
-
- public void remove() {
- removed[index - 1] = values[index - 1];
- }
-
- };
- }
-
- @Override
- public int size() {
- fail("size should not get called");
- return 0;
- }
-
- };
- assertTrue(ac.removeAll(Arrays.asList("0", "1", "2")));
- for (String r : removed) {
- if (!"0".equals(r) && !"1".equals(r) && !"2".equals(r)) {
- fail("an unexpected element was removed");
- }
- }
- }
-
- /**
- * java.util.AbstractCollection#retainAll(java.util.Collection)
- */
- public void test_retainAllLjava_util_Collection() {
- final String[] removed = new String[1];
- AbstractCollection<String> ac = new AbstractCollection<String>() {
-
- @Override
- public Iterator<String> iterator() {
- return new Iterator<String>() {
- String[] values = new String[] {"0", "1", "2"};
- int index;
- public boolean hasNext() {
- return index < values.length;
- }
-
- public String next() {
- return values[index++];
- }
-
- public void remove() {
- removed[index - 1] = values[index - 1];
- }
-
- };
- }
-
- @Override
- public int size() {
- fail("size should not get called");
- return 0;
- }
-
- };
- assertTrue(ac.retainAll(Arrays.asList("1", "2")));
- assertEquals("0", removed[0]);
- }
-
- /**
- * java.util.AbstractCollection#toArray()
- */
- public void test_toArray() {
- AbstractCollection<String> ac = new AbstractCollection<String>() {
- @Override
- public Iterator<String> iterator() {
- return new Iterator<String>() {
- String[] values = new String[] {"0", "1", "2"};
- int index;
- public boolean hasNext() {
- return index < values.length;
- }
-
- public String next() {
- return values[index++];
- }
-
- public void remove() {
- fail("remove should not get called");
- }
-
- };
- }
-
- @Override
- public int size() {
- return 3;
- }
- };
-
- Object[] array = ac.toArray();
- assertEquals(3, array.length);
- for (Object o : array) {
- if (!"0".equals(o) && !"1".equals(o) && !"2".equals(o)) {
- fail("an unexpected element was removed");
- }
- }
- }
-
- /**
- * java.util.AbstractCollection#toArray(java.lang.Object[])
- */
- public void test_toArray$Ljava_lang_Object() {
- AbstractCollection<String> ac = new AbstractCollection<String>() {
- @Override
- public Iterator<String> iterator() {
- return new Iterator<String>() {
- String[] values = new String[] {"0", "1", "2"};
- int index;
- public boolean hasNext() {
- return index < values.length;
- }
-
- public String next() {
- return values[index++];
- }
-
- public void remove() {
- fail("remove should not get called");
- }
-
- };
- }
- @Override
- public int size() {
- return 3;
- }
- };
- try {
- ac.toArray(null);
- fail("No expected NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- ac.toArray(new StringBuffer[ac.size()]);
- fail("No expected ArrayStoreException");
- } catch (ArrayStoreException e) {
- // expected
- }
-
- String[] a = new String[3];
- assertSame(a, ac.toArray(a));
-
- a = new String[0];
- assertNotSame(a, ac.toArray(a));
- a = ac.toArray(a);
- assertEquals(3, a.length);
-
- CharSequence[] csa = new CharSequence[3];
- ac.toArray(csa);
- assertEquals(3, csa.length);
- assertEquals("0", csa[0]);
- assertEquals("1", csa[1]);
- assertEquals("2", csa[2]);
- }
-
- /**
- * java.util.AbstractCollection#toString()
- */
- public void test_toString() {
- // see HARMONY-1522
- // collection that returns null iterator(this is against the spec.)
- AbstractCollection<?> c = new AbstractCollection<Object>() {
- @Override
- public int size() {
- // return non-zero value to pass 'isEmpty' check
- return 1;
- }
-
- @Override
- public Iterator<Object> iterator() {
- // this violates the spec.
- return null;
- }
- };
-
- try {
- // AbstractCollection.toString() doesn't verify
- // whether iterator() returns null value or not
- c.toString();
- fail("No expected NullPointerException");
- } catch (NullPointerException e) {
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractMapTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractMapTest.java
deleted file mode 100644
index fafc415..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/AbstractMapTest.java
+++ /dev/null
@@ -1,431 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.Vector;
-import java.util.WeakHashMap;
-
-public class AbstractMapTest extends junit.framework.TestCase {
-
- static final String specialKey = "specialKey".intern();
-
- static final String specialValue = "specialValue".intern();
-
- // The impl of MyMap is not realistic, but serves to create a type
- // that uses the default remove behavior.
- class MyMap extends AbstractMap {
- final Set mySet = new HashSet(1);
-
- MyMap() {
- mySet.add(new Map.Entry() {
- public Object getKey() {
- return specialKey;
- }
-
- public Object getValue() {
- return specialValue;
- }
-
- public Object setValue(Object object) {
- return null;
- }
- });
- }
-
- public Object put(Object key, Object value) {
- return null;
- }
-
- public Set entrySet() {
- return mySet;
- }
- }
-
- /**
- * java.util.AbstractMap#keySet()
- */
- public void test_keySet() {
- AbstractMap map1 = new HashMap(0);
- assertSame("HashMap(0)", map1.keySet(), map1.keySet());
-
- AbstractMap map2 = new HashMap(10);
- assertSame("HashMap(10)", map2.keySet(), map2.keySet());
-
- Map map3 = Collections.EMPTY_MAP;
- assertSame("EMPTY_MAP", map3.keySet(), map3.keySet());
-
- AbstractMap map4 = new IdentityHashMap(1);
- assertSame("IdentityHashMap", map4.keySet(), map4.keySet());
-
- AbstractMap map5 = new LinkedHashMap(122);
- assertSame("LinkedHashMap", map5.keySet(), map5.keySet());
-
- AbstractMap map6 = new TreeMap();
- assertSame("TreeMap", map6.keySet(), map6.keySet());
-
- AbstractMap map7 = new WeakHashMap();
- assertSame("WeakHashMap", map7.keySet(), map7.keySet());
- }
-
- /**
- * java.util.AbstractMap#remove(java.lang.Object)
- */
- public void test_removeLjava_lang_Object() {
- Object key = new Object();
- Object value = new Object();
-
- AbstractMap map1 = new HashMap(0);
- map1.put("key", value);
- assertSame("HashMap(0)", map1.remove("key"), value);
-
- AbstractMap map4 = new IdentityHashMap(1);
- map4.put(key, value);
- assertSame("IdentityHashMap", map4.remove(key), value);
-
- AbstractMap map5 = new LinkedHashMap(122);
- map5.put(key, value);
- assertSame("LinkedHashMap", map5.remove(key), value);
-
- AbstractMap map6 = new TreeMap(new Comparator() {
- // Bogus comparator
- public int compare(Object object1, Object object2) {
- return 0;
- }
- });
- map6.put(key, value);
- assertSame("TreeMap", map6.remove(key), value);
-
- AbstractMap map7 = new WeakHashMap();
- map7.put(key, value);
- assertSame("WeakHashMap", map7.remove(key), value);
-
- AbstractMap aSpecialMap = new MyMap();
- aSpecialMap.put(specialKey, specialValue);
- Object valueOut = aSpecialMap.remove(specialKey);
- assertSame("MyMap", valueOut, specialValue);
- }
-
- /**
- * java.util.AbstractMap#values()
- */
- public void test_values() {
- AbstractMap map1 = new HashMap(0);
- assertSame("HashMap(0)", map1.values(), map1.values());
-
- AbstractMap map2 = new HashMap(10);
- assertSame("HashMap(10)", map2.values(), map2.values());
-
- Map map3 = Collections.EMPTY_MAP;
- assertSame("EMPTY_MAP", map3.values(), map3.values());
-
- AbstractMap map4 = new IdentityHashMap(1);
- assertSame("IdentityHashMap", map4.values(), map4.values());
-
- AbstractMap map5 = new LinkedHashMap(122);
- assertSame("IdentityHashMap", map5.values(), map5.values());
-
- AbstractMap map6 = new TreeMap();
- assertSame("TreeMap", map6.values(), map6.values());
-
- AbstractMap map7 = new WeakHashMap();
- assertSame("WeakHashMap", map7.values(), map7.values());
- }
-
- /**
- * java.util.AbstractMap#clone()
- */
- public void test_clone() {
- class MyMap extends AbstractMap implements Cloneable {
- private Map map = new HashMap();
-
- public Set entrySet() {
- return map.entrySet();
- }
-
- public Object put(Object key, Object value) {
- return map.put(key, value);
- }
-
- public Map getMap() {
- return map;
- }
-
- public Object clone() {
- try {
- return super.clone();
- } catch (CloneNotSupportedException e) {
- throw new AssertionError(e); // android-changed
- }
- }
- }
- ;
- MyMap map = new MyMap();
- map.put("one", "1");
- Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
- assertTrue("entry not added", entry.getKey() == "one"
- && entry.getValue() == "1");
- MyMap mapClone = (MyMap) map.clone();
- assertTrue("clone not shallow", map.getMap() == mapClone.getMap());
- }
-
- class MocAbstractMap<K, V> extends AbstractMap {
-
- public Set entrySet() {
- Set set = new MySet();
- return set;
- }
-
- class MySet extends HashSet {
- public void clear() {
- throw new UnsupportedOperationException();
- }
- }
- }
-
- public void test_clear() {
- // normal clear()
- AbstractMap map = new HashMap();
- map.put(1, 1);
- map.clear();
- assertTrue(map.isEmpty());
-
- // Special entrySet return a Set with no clear method.
- AbstractMap myMap = new MocAbstractMap();
- try {
- myMap.clear();
- fail("Should throw UnsupportedOprationException");
- } catch (UnsupportedOperationException e) {
- // expected
- }
- }
-
- /**
- * java.util.AbstractMap#containsKey(Object)
- */
- public void test_containsKey() {
- AbstractMap map = new AMT();
-
- assertFalse(map.containsKey("k"));
- assertFalse(map.containsKey(null));
-
- map.put("k", "v");
- map.put("key", null);
- map.put(null, "value");
- map.put(null, null);
-
- assertTrue(map.containsKey("k"));
- assertTrue(map.containsKey("key"));
- assertTrue(map.containsKey(null));
- }
-
- /**
- * java.util.AbstractMap#containsValue(Object)
- */
- public void test_containValue() {
- AbstractMap map = new AMT();
-
- assertFalse(map.containsValue("v"));
- assertFalse(map.containsValue(null));
-
- map.put("k", "v");
- map.put("key", null);
- map.put(null, "value");
-
- assertTrue(map.containsValue("v"));
- assertTrue(map.containsValue("value"));
- assertTrue(map.containsValue(null));
- }
-
- /**
- * java.util.AbstractMap#get(Object)
- */
- public void test_get() {
- AbstractMap map = new AMT();
- assertNull(map.get("key"));
- assertNull(map.get(null));
-
- map.put("k", "v");
- map.put("key", null);
- map.put(null, "value");
-
- assertEquals("v", map.get("k"));
- assertNull(map.get("key"));
- assertEquals("value", map.get(null));
- }
-
- public class AMT extends AbstractMap {
-
- // Very crude AbstractMap implementation
- Vector values = new Vector();
-
- Vector keys = new Vector();
-
- public Set entrySet() {
- return new AbstractSet() {
- public Iterator iterator() {
- return new Iterator() {
- int index = 0;
-
- public boolean hasNext() {
- return index < values.size();
- }
-
- public Object next() {
- if (index < values.size()) {
- Map.Entry me = new Map.Entry() {
- Object v = values.elementAt(index);
-
- Object k = keys.elementAt(index);
-
- public Object getKey() {
- return k;
- }
-
- public Object getValue() {
- return v;
- }
-
- public Object setValue(Object value) {
- return null;
- }
- };
- index++;
- return me;
- }
- return null;
- }
-
- public void remove() {
- }
- };
- }
-
- public int size() {
- return values.size();
- }
- };
- }
-
- public Object put(Object k, Object v) {
- keys.add(k);
- values.add(v);
- return v;
- }
- }
-
- /**
- * {@link java.util.AbstractMap#putAll(Map)}
- */
- public void test_putAllLMap() {
- Hashtable ht = new Hashtable();
- AbstractMap amt = new AMT();
- ht.put("this", "that");
- amt.putAll(ht);
- assertEquals("Should be equal", amt, ht);
- }
-
- public void test_Constructor() {
- AMT amt = new AMT();
- assertNotNull(amt);
- }
-
- public void test_equalsLjava_lang_Object() {
- AbstractMap amt1 = new AMT();
- AbstractMap amt2 = new AMT();
- assertTrue("assert 0", amt1.equals(amt2));
- assertTrue("assert 1", amt1.equals(amt1));
- assertTrue("assert 2", amt2.equals(amt1));
- amt1.put("1", "one");
- assertFalse("assert 3", amt1.equals(amt2));
- amt1.put("2", "two");
- amt1.put("3", "three");
-
- amt2.put("1", "one");
- amt2.put("2", "two");
- amt2.put("3", "three");
- assertTrue("assert 4", amt1.equals(amt2));
- assertFalse("assert 5", amt1.equals(this));
- }
-
- public void test_hashCode() {
- AMT amt1 = new AMT();
- AMT amt2 = new AMT();
- amt1.put("1", "one");
-
- assertNotSame(amt1.hashCode(), amt2.hashCode());
- }
-
- public void test_isEmpty() {
- AMT amt = new AMT();
- assertTrue(amt.isEmpty());
- amt.put("1", "one");
- assertFalse(amt.isEmpty());
- }
-
- public void test_put() {
- AMT amt = new AMT();
- assertEquals(0, amt.size());
- amt.put("1", "one");
- assertEquals(1, amt.size());
- amt.put("2", "two");
- assertEquals(2, amt.size());
- amt.put("3", "three");
- assertEquals(3, amt.size());
- }
-
- public void test_size() {
- AMT amt = new AMT();
- assertEquals(0, amt.size());
- amt.put("1", "one");
- assertEquals(1, amt.size());
- amt.put("2", "two");
- assertEquals(2, amt.size());
- amt.put("3", "three");
- assertEquals(3, amt.size());
- }
-
- public void test_toString() {
- AMT amt = new AMT();
- assertEquals("{}", amt.toString());
- amt.put("1", "one");
- assertEquals("{1=one}", amt.toString());
- amt.put("2", "two");
- assertEquals("{1=one, 2=two}", amt.toString());
- amt.put("3", "three");
- assertEquals("{1=one, 2=two, 3=three}", amt.toString());
- }
-
- protected void setUp() {
- }
-
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ArrayListTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
deleted file mode 100644
index 8d328e7..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ArrayListTest.java
+++ /dev/null
@@ -1,1005 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.ConcurrentModificationException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.Vector;
-
-import tests.support.Support_ListTest;
-
-public class ArrayListTest extends junit.framework.TestCase {
-
- List alist;
-
- static Object[] objArray;
- {
- objArray = new Object[100];
- for (int i = 0; i < objArray.length; i++)
- objArray[i] = new Integer(i);
- }
-
- /**
- * java.util.ArrayList#ArrayList()
- */
- public void test_Constructor() {
- // Test for method java.util.ArrayList()
- new Support_ListTest("", alist).runTest();
-
- ArrayList subList = new ArrayList();
- for (int i = -50; i < 150; i++)
- subList.add(new Integer(i));
- new Support_ListTest("", subList.subList(50, 150)).runTest();
- }
-
- /**
- * java.util.ArrayList#ArrayList(int)
- */
- public void test_ConstructorI() {
- // Test for method java.util.ArrayList(int)
- ArrayList al = new ArrayList(5);
- assertEquals("Incorrect arrayList created", 0, al.size());
-
- al = new ArrayList(0);
- assertEquals("Incorrect arrayList created", 0, al.size());
-
- try {
- al = new ArrayList(-1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.ArrayList#ArrayList(java.util.Collection)
- */
- public void test_ConstructorLjava_util_Collection() {
- // Test for method java.util.ArrayList(java.util.Collection)
- ArrayList al = new ArrayList(Arrays.asList(objArray));
- assertTrue("arrayList created from collection has incorrect size", al
- .size() == objArray.length);
- for (int counter = 0; counter < objArray.length; counter++)
- assertTrue(
- "arrayList created from collection has incorrect elements",
- al.get(counter) == objArray[counter]);
-
- }
-
- public void testConstructorWithConcurrentCollection() {
- Collection<String> collection = shrinksOnSize("A", "B", "C", "D");
- ArrayList<String> list = new ArrayList<String>(collection);
- assertFalse(list.contains(null));
- }
-
- /**
- * java.util.ArrayList#add(int, java.lang.Object)
- */
- public void test_addILjava_lang_Object() {
- // Test for method void java.util.ArrayList.add(int, java.lang.Object)
- Object o;
- alist.add(50, o = new Object());
- assertTrue("Failed to add Object", alist.get(50) == o);
- assertTrue("Failed to fix up list after insert",
- alist.get(51) == objArray[50]
- && (alist.get(52) == objArray[51]));
- Object oldItem = alist.get(25);
- alist.add(25, null);
- assertNull("Should have returned null", alist.get(25));
- assertTrue("Should have returned the old item from slot 25", alist
- .get(26) == oldItem);
-
- alist.add(0, o = new Object());
- assertEquals("Failed to add Object", alist.get(0), o);
- assertEquals(alist.get(1), objArray[0]);
- assertEquals(alist.get(2), objArray[1]);
-
- oldItem = alist.get(0);
- alist.add(0, null);
- assertNull("Should have returned null", alist.get(0));
- assertEquals("Should have returned the old item from slot 0", alist
- .get(1), oldItem);
-
- try {
- alist.add(-1, new Object());
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- alist.add(-1, null);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- alist.add(alist.size() + 1, new Object());
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- alist.add(alist.size() + 1, null);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
- }
-
- /**
- * java.util.ArrayList#add(int, java.lang.Object)
- */
- public void test_addILjava_lang_Object_2() {
- Object o = new Object();
- int size = alist.size();
- alist.add(size, o);
- assertEquals("Failed to add Object", alist.get(size), o);
- assertEquals(alist.get(size - 2), objArray[size - 2]);
- assertEquals(alist.get(size - 1), objArray[size - 1]);
-
- alist.remove(size);
-
- size = alist.size();
- alist.add(size, null);
- assertNull("Should have returned null", alist.get(size));
- assertEquals(alist.get(size - 2), objArray[size - 2]);
- assertEquals(alist.get(size - 1), objArray[size - 1]);
- }
-
- /**
- * java.util.ArrayList#add(java.lang.Object)
- */
- public void test_addLjava_lang_Object() {
- // Test for method boolean java.util.ArrayList.add(java.lang.Object)
- Object o = new Object();
- alist.add(o);
- assertTrue("Failed to add Object", alist.get(alist.size() - 1) == o);
- alist.add(null);
- assertNull("Failed to add null", alist.get(alist.size() - 1));
- }
-
- /**
- * java.util.ArrayList#addAll(int, java.util.Collection)
- */
- public void test_addAllILjava_util_Collection() {
- // Test for method boolean java.util.ArrayList.addAll(int,
- // java.util.Collection)
- alist.addAll(50, alist);
- assertEquals("Returned incorrect size after adding to existing list",
- 200, alist.size());
- for (int i = 0; i < 50; i++)
- assertTrue("Manipulated elements < index",
- alist.get(i) == objArray[i]);
- for (int i = 0; i >= 50 && (i < 150); i++)
- assertTrue("Failed to ad elements properly",
- alist.get(i) == objArray[i - 50]);
- for (int i = 0; i >= 150 && (i < 200); i++)
- assertTrue("Failed to ad elements properly",
- alist.get(i) == objArray[i - 100]);
- ArrayList listWithNulls = new ArrayList();
- listWithNulls.add(null);
- listWithNulls.add(null);
- listWithNulls.add("yoink");
- listWithNulls.add("kazoo");
- listWithNulls.add(null);
- alist.addAll(100, listWithNulls);
- assertTrue("Incorrect size: " + alist.size(), alist.size() == 205);
- assertNull("Item at slot 100 should be null", alist.get(100));
- assertNull("Item at slot 101 should be null", alist.get(101));
- assertEquals("Item at slot 102 should be 'yoink'", "yoink", alist
- .get(102));
- assertEquals("Item at slot 103 should be 'kazoo'", "kazoo", alist
- .get(103));
- assertNull("Item at slot 104 should be null", alist.get(104));
- alist.addAll(205, listWithNulls);
- assertTrue("Incorrect size2: " + alist.size(), alist.size() == 210);
- }
-
- /**
- * java.util.ArrayList#addAll(int, java.util.Collection)
- */
- @SuppressWarnings("unchecked")
- public void test_addAllILjava_util_Collection_2() {
- // Regression for HARMONY-467
- ArrayList obj = new ArrayList();
- try {
- obj.addAll((int) -1, (Collection) null);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- // Regression for HARMONY-5705
- String[] data = new String[] { "1", "2", "3", "4", "5", "6", "7", "8" };
- ArrayList list1 = new ArrayList();
- ArrayList list2 = new ArrayList();
- for (String d : data) {
- list1.add(d);
- list2.add(d);
- list2.add(d);
- }
- while (list1.size() > 0)
- list1.remove(0);
- list1.addAll(list2);
- assertTrue("The object list is not the same as original list", list1
- .containsAll(list2)
- && list2.containsAll(list1));
-
- obj = new ArrayList();
- for (int i = 0; i < 100; i++) {
- if (list1.size() > 0) {
- obj.removeAll(list1);
- obj.addAll(list1);
- }
- }
- assertTrue("The object list is not the same as original list", obj
- .containsAll(list1)
- && list1.containsAll(obj));
-
- // Regression for Harmony-5799
- list1 = new ArrayList();
- list2 = new ArrayList();
- int location = 2;
-
- String[] strings = { "0", "1", "2", "3", "4", "5", "6" };
- int[] integers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- for (int i = 0; i < 7; i++) {
- list1.add(strings[i]);
- }
- for (int i = 0; i < 10; i++) {
- list2.add(integers[i]);
- }
- list1.remove(location);
- list1.addAll(location, list2);
-
- // Inserted elements should be equal to integers array
- for (int i = 0; i < integers.length; i++) {
- assertEquals(integers[i], list1.get(location + i));
- }
- // Elements after inserted location should
- // be equals to related elements in strings array
- for (int i = location + 1; i < strings.length; i++) {
- assertEquals(strings[i], list1.get(i + integers.length - 1));
- }
- }
-
- /**
- * java.util.ArrayList#addAll(int, java.util.Collection)
- */
- public void test_addAllILjava_util_Collection_3() {
- ArrayList obj = new ArrayList();
- obj.addAll(0, obj);
- obj.addAll(obj.size(), obj);
- try {
- obj.addAll(-1, obj);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- obj.addAll(obj.size() + 1, obj);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- obj.addAll(0, null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Excepted
- }
-
- try {
- obj.addAll(obj.size() + 1, null);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- obj.addAll((int) -1, (Collection) null);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
- }
-
- public void test_addAllCollectionOfQextendsE() {
- // Regression for HARMONY-539
- // https://issues.apache.org/jira/browse/HARMONY-539
- ArrayList<String> alist = new ArrayList<String>();
- ArrayList<String> blist = new ArrayList<String>();
- alist.add("a");
- alist.add("b");
- blist.add("c");
- blist.add("d");
- blist.remove(0);
- blist.addAll(0, alist);
- assertEquals("a", blist.get(0));
- assertEquals("b", blist.get(1));
- assertEquals("d", blist.get(2));
- }
-
- /**
- * java.util.ArrayList#addAll(java.util.Collection)
- */
- public void test_addAllLjava_util_Collection() {
- // Test for method boolean
- // java.util.ArrayList.addAll(java.util.Collection)
- List l = new ArrayList();
- l.addAll(alist);
- for (int i = 0; i < alist.size(); i++)
- assertTrue("Failed to add elements properly", l.get(i).equals(
- alist.get(i)));
- alist.addAll(alist);
- assertEquals("Returned incorrect size after adding to existing list",
- 200, alist.size());
- for (int i = 0; i < 100; i++) {
- assertTrue("Added to list in incorrect order", alist.get(i).equals(
- l.get(i)));
- assertTrue("Failed to add to existing list", alist.get(i + 100)
- .equals(l.get(i)));
- }
- Set setWithNulls = new HashSet();
- setWithNulls.add(null);
- setWithNulls.add(null);
- setWithNulls.add("yoink");
- setWithNulls.add("kazoo");
- setWithNulls.add(null);
- alist.addAll(100, setWithNulls);
- Iterator i = setWithNulls.iterator();
- assertTrue("Item at slot 100 is wrong: " + alist.get(100), alist
- .get(100) == i.next());
- assertTrue("Item at slot 101 is wrong: " + alist.get(101), alist
- .get(101) == i.next());
- assertTrue("Item at slot 103 is wrong: " + alist.get(102), alist
- .get(102) == i.next());
-
- try {
- alist.addAll(null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Excepted
- }
-
- // Regression test for Harmony-3481
- ArrayList<Integer> originalList = new ArrayList<Integer>(12);
- for (int j = 0; j < 12; j++) {
- originalList.add(j);
- }
-
- originalList.remove(0);
- originalList.remove(0);
-
- ArrayList<Integer> additionalList = new ArrayList<Integer>(11);
- for (int j = 0; j < 11; j++) {
- additionalList.add(j);
- }
- assertTrue(originalList.addAll(additionalList));
- assertEquals(21, originalList.size());
-
- }
-
- public void test_ArrayList_addAll_scenario1() {
- ArrayList arrayListA = new ArrayList();
- arrayListA.add(1);
- ArrayList arrayListB = new ArrayList();
- arrayListB.add(1);
- arrayListA.addAll(1, arrayListB);
- int size = arrayListA.size();
- assertEquals(2, size);
- for (int index = 0; index < size; index++) {
- assertEquals(1, arrayListA.get(index));
- }
- }
-
- public void test_ArrayList_addAll_scenario2() {
- ArrayList arrayList = new ArrayList();
- arrayList.add(1);
- arrayList.addAll(1, arrayList);
- int size = arrayList.size();
- assertEquals(2, size);
- for (int index = 0; index < size; index++) {
- assertEquals(1, arrayList.get(index));
- }
- }
-
- // Regression test for HARMONY-5839
- public void testaddAllHarmony5839() {
- Collection coll = Arrays.asList(new String[] { "1", "2" });
- List list = new ArrayList();
- list.add("a");
- list.add(0, "b");
- list.add(0, "c");
- list.add(0, "d");
- list.add(0, "e");
- list.add(0, "f");
- list.add(0, "g");
- list.add(0, "h");
- list.add(0, "i");
-
- list.addAll(6, coll);
-
- assertEquals(11, list.size());
- assertFalse(list.contains(null));
- }
-
- /**
- * java.util.ArrayList#clear()
- */
- public void test_clear() {
- // Test for method void java.util.ArrayList.clear()
- alist.clear();
- assertEquals("List did not clear", 0, alist.size());
- alist.add(null);
- alist.add(null);
- alist.add(null);
- alist.add("bam");
- alist.clear();
- assertEquals("List with nulls did not clear", 0, alist.size());
- /*
- * for (int i = 0; i < alist.size(); i++) assertNull("Failed to clear
- * list", alist.get(i));
- */
-
- }
-
- /**
- * java.util.ArrayList#clone()
- */
- public void test_clone() {
- // Test for method java.lang.Object java.util.ArrayList.clone()
- ArrayList x = (ArrayList) (((ArrayList) (alist)).clone());
- assertTrue("Cloned list was inequal to original", x.equals(alist));
- for (int i = 0; i < alist.size(); i++)
- assertTrue("Cloned list contains incorrect elements",
- alist.get(i) == x.get(i));
-
- alist.add(null);
- alist.add(25, null);
- x = (ArrayList) (((ArrayList) (alist)).clone());
- assertTrue("nulls test - Cloned list was inequal to original", x
- .equals(alist));
- for (int i = 0; i < alist.size(); i++)
- assertTrue("nulls test - Cloned list contains incorrect elements",
- alist.get(i) == x.get(i));
-
- }
-
- /**
- * java.util.ArrayList#contains(java.lang.Object)
- */
- public void test_containsLjava_lang_Object() {
- // Test for method boolean
- // java.util.ArrayList.contains(java.lang.Object)
- assertTrue("Returned false for valid element", alist
- .contains(objArray[99]));
- assertTrue("Returned false for equal element", alist
- .contains(new Integer(8)));
- assertTrue("Returned true for invalid element", !alist
- .contains(new Object()));
- assertTrue("Returned true for null but should have returned false",
- !alist.contains(null));
- alist.add(null);
- assertTrue("Returned false for null but should have returned true",
- alist.contains(null));
- }
-
- /**
- * java.util.ArrayList#ensureCapacity(int)
- */
- public void test_ensureCapacityI() {
- // Test for method void java.util.ArrayList.ensureCapacity(int)
- // TODO : There is no good way to test this as it only really impacts on
- // the private implementation.
-
- Object testObject = new Object();
- int capacity = 20;
- ArrayList al = new ArrayList(capacity);
- int i;
- for (i = 0; i < capacity / 2; i++) {
- al.add(i, new Object());
- }
- al.add(i, testObject);
- int location = al.indexOf(testObject);
- al.ensureCapacity(capacity);
- assertTrue("EnsureCapacity moved objects around in array1.",
- location == al.indexOf(testObject));
- al.remove(0);
- al.ensureCapacity(capacity);
- assertTrue("EnsureCapacity moved objects around in array2.",
- --location == al.indexOf(testObject));
- al.ensureCapacity(capacity + 2);
- assertTrue("EnsureCapacity did not change location.", location == al
- .indexOf(testObject));
- }
-
- /**
- * java.util.ArrayList#get(int)
- */
- public void test_getI() {
- // Test for method java.lang.Object java.util.ArrayList.get(int)
- assertTrue("Returned incorrect element", alist.get(22) == objArray[22]);
- try {
- alist.get(8765);
- fail("Failed to throw expected exception for index > size");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
- }
-
- /**
- * java.util.ArrayList#indexOf(java.lang.Object)
- */
- public void test_indexOfLjava_lang_Object() {
- // Test for method int java.util.ArrayList.indexOf(java.lang.Object)
- assertEquals("Returned incorrect index", 87, alist
- .indexOf(objArray[87]));
- assertEquals("Returned index for invalid Object", -1, alist
- .indexOf(new Object()));
- alist.add(25, null);
- alist.add(50, null);
- assertTrue("Wrong indexOf for null. Wanted 25 got: "
- + alist.indexOf(null), alist.indexOf(null) == 25);
- }
-
- /**
- * java.util.ArrayList#isEmpty()
- */
- public void test_isEmpty() {
- // Test for method boolean java.util.ArrayList.isEmpty()
- assertTrue("isEmpty returned false for new list", new ArrayList()
- .isEmpty());
- assertTrue("Returned true for existing list with elements", !alist
- .isEmpty());
- }
-
- /**
- * java.util.ArrayList#lastIndexOf(java.lang.Object)
- */
- public void test_lastIndexOfLjava_lang_Object() {
- // Test for method int java.util.ArrayList.lastIndexOf(java.lang.Object)
- alist.add(new Integer(99));
- assertEquals("Returned incorrect index", 100, alist
- .lastIndexOf(objArray[99]));
- assertEquals("Returned index for invalid Object", -1, alist
- .lastIndexOf(new Object()));
- alist.add(25, null);
- alist.add(50, null);
- assertTrue("Wrong lastIndexOf for null. Wanted 50 got: "
- + alist.lastIndexOf(null), alist.lastIndexOf(null) == 50);
- }
-
- /**
- * {@link java.util.ArrayList#removeRange(int, int)}
- */
- public void test_removeRange() {
- MockArrayList mylist = new MockArrayList();
- mylist.removeRange(0, 0);
-
- try {
- mylist.removeRange(0, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- int[] data = { 1, 2, 3 };
- for (int i = 0; i < data.length; i++) {
- mylist.add(i, data[i]);
- }
-
- mylist.removeRange(0, 1);
- assertEquals(data[1], mylist.get(0));
- assertEquals(data[2], mylist.get(1));
-
- try {
- mylist.removeRange(-1, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- mylist.removeRange(0, -1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- mylist.removeRange(1, 0);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- mylist.removeRange(2, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
- }
-
- /**
- * java.util.ArrayList#remove(int)
- */
- public void test_removeI() {
- // Test for method java.lang.Object java.util.ArrayList.remove(int)
- alist.remove(10);
- assertEquals("Failed to remove element", -1, alist
- .indexOf(objArray[10]));
- try {
- alist.remove(999);
- fail("Failed to throw exception when index out of range");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- ArrayList myList = (ArrayList) (((ArrayList) (alist)).clone());
- alist.add(25, null);
- alist.add(50, null);
- alist.remove(50);
- alist.remove(25);
- assertTrue("Removing nulls did not work", alist.equals(myList));
-
- List list = new ArrayList(Arrays.asList(new String[] { "a", "b", "c",
- "d", "e", "f", "g" }));
- assertTrue("Removed wrong element 1", list.remove(0) == "a");
- assertTrue("Removed wrong element 2", list.remove(4) == "f");
- String[] result = new String[5];
- list.toArray(result);
- assertTrue("Removed wrong element 3", Arrays.equals(result,
- new String[] { "b", "c", "d", "e", "g" }));
-
- List l = new ArrayList(0);
- l.add(new Object());
- l.add(new Object());
- l.remove(0);
- l.remove(0);
- try {
- l.remove(-1);
- fail("-1 should cause exception");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
- try {
- l.remove(0);
- fail("0 should case exception");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
- }
-
- /**
- * java.util.ArrayList#set(int, java.lang.Object)
- */
- public void test_setILjava_lang_Object() {
- // Test for method java.lang.Object java.util.ArrayList.set(int,
- // java.lang.Object)
- Object obj;
- alist.set(65, obj = new Object());
- assertTrue("Failed to set object", alist.get(65) == obj);
- alist.set(50, null);
- assertNull("Setting to null did not work", alist.get(50));
- assertTrue("Setting increased the list's size to: " + alist.size(),
- alist.size() == 100);
-
- obj = new Object();
- alist.set(0, obj);
- assertTrue("Failed to set object", alist.get(0) == obj);
-
- try {
- alist.set(-1, obj);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- alist.set(alist.size(), obj);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- alist.set(-1, null);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
-
- try {
- alist.set(alist.size(), null);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- assertNotNull(e.getMessage());
- }
- }
-
- /**
- * java.util.ArrayList#size()
- */
- public void test_size() {
- // Test for method int java.util.ArrayList.size()
- assertEquals("Returned incorrect size for exiting list", 100, alist
- .size());
- assertEquals("Returned incorrect size for new list", 0, new ArrayList()
- .size());
- }
-
- /**
- * java.util.AbstractCollection#toString()
- */
- public void test_toString() {
- ArrayList l = new ArrayList(1);
- l.add(l);
- String result = l.toString();
- assertTrue("should contain self ref", result.indexOf("(this") > -1);
- }
-
- /**
- * java.util.ArrayList#toArray()
- */
- public void test_toArray() {
- // Test for method java.lang.Object [] java.util.ArrayList.toArray()
- alist.set(25, null);
- alist.set(75, null);
- Object[] obj = alist.toArray();
- assertEquals("Returned array of incorrect size", objArray.length,
- obj.length);
-
- for (int i = 0; i < obj.length; i++) {
- if ((i == 25) || (i == 75))
- assertNull("Should be null at: " + i + " but instead got: "
- + obj[i], obj[i]);
- else
- assertTrue("Returned incorrect array: " + i,
- obj[i] == objArray[i]);
- }
-
- }
-
- /**
- * java.util.ArrayList#toArray(java.lang.Object[])
- */
- public void test_toArray$Ljava_lang_Object() {
- // Test for method java.lang.Object []
- // java.util.ArrayList.toArray(java.lang.Object [])
- alist.set(25, null);
- alist.set(75, null);
- Integer[] argArray = new Integer[100];
- Object[] retArray;
- retArray = alist.toArray(argArray);
- assertTrue("Returned different array than passed", retArray == argArray);
- argArray = new Integer[1000];
- retArray = alist.toArray(argArray);
- assertNull("Failed to set first extra element to null", argArray[alist
- .size()]);
- for (int i = 0; i < 100; i++) {
- if ((i == 25) || (i == 75))
- assertNull("Should be null: " + i, retArray[i]);
- else
- assertTrue("Returned incorrect array: " + i,
- retArray[i] == objArray[i]);
- }
- }
-
- /**
- * java.util.ArrayList#trimToSize()
- */
- public void test_trimToSize() {
- // Test for method void java.util.ArrayList.trimToSize()
- for (int i = 99; i > 24; i--)
- alist.remove(i);
- ((ArrayList) alist).trimToSize();
- assertEquals("Returned incorrect size after trim", 25, alist.size());
- for (int i = 0; i < alist.size(); i++)
- assertTrue("Trimmed list contained incorrect elements", alist
- .get(i) == objArray[i]);
- Vector v = new Vector();
- v.add("a");
- ArrayList al = new ArrayList(v);
- Iterator it = al.iterator();
- al.trimToSize();
- try {
- it.next();
- fail("should throw a ConcurrentModificationException");
- } catch (ConcurrentModificationException ioobe) {
- // expected
- }
- }
-
- /**
- * @test java.util.ArrayList#addAll(int, Collection)
- */
- public void test_addAll() {
- ArrayList list = new ArrayList();
- list.add("one");
- list.add("two");
- assertEquals(2, list.size());
-
- list.remove(0);
- assertEquals(1, list.size());
-
- ArrayList collection = new ArrayList();
- collection.add("1");
- collection.add("2");
- collection.add("3");
- assertEquals(3, collection.size());
-
- list.addAll(0, collection);
- assertEquals(4, list.size());
-
- list.remove(0);
- list.remove(0);
- assertEquals(2, list.size());
-
- collection.add("4");
- collection.add("5");
- collection.add("6");
- collection.add("7");
- collection.add("8");
- collection.add("9");
- collection.add("10");
- collection.add("11");
- collection.add("12");
-
- assertEquals(12, collection.size());
-
- list.addAll(0, collection);
- assertEquals(14, list.size());
- }
-
- public void testAddAllWithConcurrentCollection() {
- ArrayList<String> list = new ArrayList<String>();
- list.addAll(shrinksOnSize("A", "B", "C", "D"));
- assertFalse(list.contains(null));
- }
-
- public void testAddAllAtPositionWithConcurrentCollection() {
- ArrayList<String> list = new ArrayList<String>(
- Arrays.asList("A", "B", "C", "D"));
-
- list.addAll(3, shrinksOnSize("E", "F", "G", "H"));
- assertFalse(list.contains(null));
- }
-
- public void test_override_size() throws Exception {
- ArrayList testlist = new MockArrayList();
- // though size is overriden, it should passed without exception
- testlist.add("test_0");
- testlist.add("test_1");
- testlist.add("test_2");
- testlist.add(1, "test_3");
- testlist.get(1);
- testlist.remove(2);
- testlist.set(1, "test_4");
- }
-
- public static class ArrayListExtend extends ArrayList {
-
- private int size = 0;
-
- public ArrayListExtend() {
- super(10);
- }
-
- public boolean add(Object o) {
- size++;
- return super.add(o);
- }
-
- public int size() {
- return size;
- }
- }
-
- public class MockArrayList extends ArrayList {
- public int size() {
- return 0;
- }
-
- public void removeRange(int start, int end) {
- super.removeRange(start, end);
- }
- }
-
- public void test_subclassing() {
- ArrayListExtend a = new ArrayListExtend();
- /*
- * Regression test for subclasses that override size() (which used to
- * cause an exception when growing 'a').
- */
- for (int i = 0; i < 100; i++) {
- a.add(new Object());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() throws Exception {
- super.setUp();
- alist = new ArrayList();
- for (int i = 0; i < objArray.length; i++)
- alist.add(objArray[i]);
- }
-
- /**
- * Returns a collection that emulates another thread calling remove() each
- * time the current thread calls size().
- */
- private <T> Collection<T> shrinksOnSize(T... elements) {
- return new HashSet<T>(Arrays.asList(elements)) {
- boolean shrink = true;
-
- @Override
- public int size() {
- int result = super.size();
- if (shrink) {
- Iterator<T> i = iterator();
- i.next();
- i.remove();
- }
- return result;
- }
-
- @Override
- public Object[] toArray() {
- shrink = false;
- return super.toArray();
- }
- };
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ArraysTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ArraysTest.java
deleted file mode 100644
index 7e73bcf..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/ArraysTest.java
+++ /dev/null
@@ -1,3520 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.util;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.List;
-
-import tests.support.Support_UnmodifiableCollectionTest;
-
-public class ArraysTest extends junit.framework.TestCase {
-
- public static class ReversedIntegerComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- return -(((Integer) o1).compareTo((Integer) o2));
- }
-
- public boolean equals(Object o1, Object o2) {
- return ((Integer) o1).compareTo((Integer) o2) == 0;
- }
- }
-
- static class MockComparable implements Comparable{
- public int compareTo(Object o) {
- return 0;
- }
- }
-
- final static int arraySize = 100;
-
- static Object[] objArray;
-
- static boolean[] booleanArray;
-
- static byte[] byteArray;
-
- static char[] charArray;
-
- static double[] doubleArray;
-
- static float[] floatArray;
-
- static int[] intArray;
-
- static long[] longArray;
-
- static Object[] objectArray;
-
- static short[] shortArray;
- {
- objArray = new Object[arraySize];
- for (int i = 0; i < objArray.length; i++)
- objArray[i] = new Integer(i);
- }
-
- /**
- * 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
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(byte[], byte)
- */
- public void test_binarySearch$BB() {
- // Test for method int java.util.Arrays.binarySearch(byte [], byte)
- for (byte counter = 0; counter < arraySize; counter++)
- assertTrue("Binary search on byte[] answered incorrect position",
- Arrays.binarySearch(byteArray, counter) == counter);
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(intArray, (byte) -1));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(intArray, (byte) arraySize) == -(arraySize + 1));
- for (byte counter = 0; counter < arraySize; counter++)
- byteArray[counter] -= 50;
- for (byte counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on byte[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(byteArray, (byte) (counter - 50)) == counter);
- }
-
- /**
- * java.util.Arrays#binarySearch(char[], char)
- */
- public void test_binarySearch$CC() {
- // Test for method int java.util.Arrays.binarySearch(char [], char)
- for (char counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on char[] answered incorrect position",
- Arrays.binarySearch(charArray, (char) (counter + 1)) == counter);
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(charArray, '\u0000'));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(charArray, (char) (arraySize + 1)) == -(arraySize + 1));
- }
-
- /**
- * java.util.Arrays#binarySearch(double[], double)
- */
- public void test_binarySearch$DD() {
- // Test for method int java.util.Arrays.binarySearch(double [], double)
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on double[] answered incorrect position",
- Arrays.binarySearch(doubleArray, (double) counter) == (double) counter);
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(doubleArray, (double) -1));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(doubleArray, (double) arraySize) == -(arraySize + 1));
- for (int counter = 0; counter < arraySize; counter++)
- doubleArray[counter] -= (double) 50;
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on double[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(doubleArray, (double) (counter - 50)) == (double) counter);
-
- double[] specials = new double[] { Double.NEGATIVE_INFINITY,
- -Double.MAX_VALUE, -2d, -Double.MIN_VALUE, -0d, 0d,
- Double.MIN_VALUE, 2d, Double.MAX_VALUE,
- Double.POSITIVE_INFINITY, Double.NaN };
- for (int i = 0; i < specials.length; i++) {
- int result = Arrays.binarySearch(specials, specials[i]);
- assertTrue(specials[i] + " invalid: " + result, result == i);
- }
- assertEquals("-1d", -4, Arrays.binarySearch(specials, -1d));
- assertEquals("1d", -8, Arrays.binarySearch(specials, 1d));
-
- }
-
- /**
- * java.util.Arrays#binarySearch(float[], float)
- */
- public void test_binarySearch$FF() {
- // Test for method int java.util.Arrays.binarySearch(float [], float)
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on float[] answered incorrect position",
- Arrays.binarySearch(floatArray, (float) counter) == (float) counter);
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(floatArray, (float) -1));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(floatArray, (float) arraySize) == -(arraySize + 1));
- for (int counter = 0; counter < arraySize; counter++)
- floatArray[counter] -= (float) 50;
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on float[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(floatArray, (float) counter - 50) == (float) counter);
-
- float[] specials = new float[] { Float.NEGATIVE_INFINITY,
- -Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
- Float.MIN_VALUE, 2f, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
- Float.NaN };
- for (int i = 0; i < specials.length; i++) {
- int result = Arrays.binarySearch(specials, specials[i]);
- assertTrue(specials[i] + " invalid: " + result, result == i);
- }
- assertEquals("-1f", -4, Arrays.binarySearch(specials, -1f));
- assertEquals("1f", -8, Arrays.binarySearch(specials, 1f));
- }
-
- /**
- * java.util.Arrays#binarySearch(int[], int)
- */
- public void test_binarySearch$II() {
- // Test for method int java.util.Arrays.binarySearch(int [], int)
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue("Binary search on int[] answered incorrect position",
- Arrays.binarySearch(intArray, counter) == counter);
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(intArray, -1));
- assertTrue("Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(intArray, arraySize) == -(arraySize + 1));
- for (int counter = 0; counter < arraySize; counter++)
- intArray[counter] -= 50;
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on int[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(intArray, counter - 50) == counter);
- }
-
- /**
- * java.util.Arrays#binarySearch(long[], long)
- */
- public void test_binarySearch$JJ() {
- // Test for method int java.util.Arrays.binarySearch(long [], long)
- for (long counter = 0; counter < arraySize; counter++)
- assertTrue("Binary search on long[] answered incorrect position",
- Arrays.binarySearch(longArray, counter) == counter);
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(longArray, (long) -1));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(longArray, (long) arraySize) == -(arraySize + 1));
- for (long counter = 0; counter < arraySize; counter++)
- longArray[(int) counter] -= (long) 50;
- for (long counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on long[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(longArray, counter - (long) 50) == counter);
- }
-
- /**
- * java.util.Arrays#binarySearch(java.lang.Object[],
- * java.lang.Object)
- */
- public void test_binarySearch$Ljava_lang_ObjectLjava_lang_Object() {
- // Test for method int java.util.Arrays.binarySearch(java.lang.Object
- // [], java.lang.Object)
- assertEquals(
- "Binary search succeeded for non-comparable value in empty array",
- -1, Arrays.binarySearch(new Object[] {}, new Object()));
- assertEquals(
- "Binary search succeeded for comparable value in empty array",
- -1, Arrays.binarySearch(new Object[] {}, new Integer(-1)));
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on Object[] answered incorrect position",
- Arrays.binarySearch(objectArray, objArray[counter]) == counter);
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(objectArray, new Integer(-1)));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(objectArray, new Integer(arraySize)) == -(arraySize + 1));
-
- Object object = new Object();
- Object[] objects = new MockComparable[] { new MockComparable() };
- assertEquals("Should always return 0", 0, Arrays.binarySearch(objects, object));
-
- Object[] string_objects = new String[] { "one" };
- try {
- Arrays.binarySearch(string_objects, object);
- fail("No expected ClassCastException");
- } catch (ClassCastException e) {
- // Expected
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(java.lang.Object[],
- * java.lang.Object, java.util.Comparator)
- */
- public void test_binarySearch$Ljava_lang_ObjectLjava_lang_ObjectLjava_util_Comparator() {
- // Test for method int java.util.Arrays.binarySearch(java.lang.Object
- // [], java.lang.Object, java.util.Comparator)
- Comparator comp = new ReversedIntegerComparator();
- for (int counter = 0; counter < arraySize; counter++)
- objectArray[counter] = objArray[arraySize - counter - 1];
- assertTrue(
- "Binary search succeeded for value not present in array 1",
- Arrays.binarySearch(objectArray, new Integer(-1), comp) == -(arraySize + 1));
- assertEquals("Binary search succeeded for value not present in array 2",
- -1, Arrays.binarySearch(objectArray, new Integer(arraySize), comp));
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on Object[] with custom comparator answered incorrect position",
- Arrays.binarySearch(objectArray, objArray[counter], comp) == arraySize
- - counter - 1);
- }
-
- /**
- * java.util.Arrays#binarySearch(short[], short)
- */
- public void test_binarySearch$SS() {
- // Test for method int java.util.Arrays.binarySearch(short [], short)
- for (short counter = 0; counter < arraySize; counter++)
- assertTrue("Binary search on short[] answered incorrect position",
- Arrays.binarySearch(shortArray, counter) == counter);
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(intArray, (short) -1));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(intArray, (short) arraySize) == -(arraySize + 1));
- for (short counter = 0; counter < arraySize; counter++)
- shortArray[counter] -= 50;
- for (short counter = 0; counter < arraySize; counter++)
- assertTrue(
- "Binary search on short[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(shortArray, (short) (counter - 50)) == counter);
- }
-
- /**
- * java.util.Arrays#fill(byte[], byte)
- */
- public void test_fill$BB() {
- // Test for method void java.util.Arrays.fill(byte [], byte)
-
- byte d[] = new byte[1000];
- Arrays.fill(d, Byte.MAX_VALUE);
- for (int i = 0; i < d.length; i++)
- assertTrue("Failed to fill byte array correctly",
- d[i] == Byte.MAX_VALUE);
- }
-
- /**
- * java.util.Arrays#fill(byte[], int, int, byte)
- */
- public void test_fill$BIIB() {
- // Test for method void java.util.Arrays.fill(byte [], int, int, byte)
- byte val = Byte.MAX_VALUE;
- byte d[] = new byte[1000];
- Arrays.fill(d, 400, d.length, val);
- for (int i = 0; i < 400; i++)
- assertTrue("Filled elements not in range", !(d[i] == val));
- for (int i = 400; i < d.length; i++)
- assertTrue("Failed to fill byte array correctly", d[i] == val);
-
- int result;
- try {
- Arrays.fill(new byte[2], 2, 1, (byte) 27);
- result = 0;
- } catch (ArrayIndexOutOfBoundsException e) {
- result = 1;
- } catch (IllegalArgumentException e) {
- result = 2;
- }
- assertEquals("Wrong exception1", 2, result);
- try {
- Arrays.fill(new byte[2], -1, 1, (byte) 27);
- result = 0;
- } catch (ArrayIndexOutOfBoundsException e) {
- result = 1;
- } catch (IllegalArgumentException e) {
- result = 2;
- }
- assertEquals("Wrong exception2", 1, result);
- try {
- Arrays.fill(new byte[2], 1, 4, (byte) 27);
- result = 0;
- } catch (ArrayIndexOutOfBoundsException e) {
- result = 1;
- } catch (IllegalArgumentException e) {
- result = 2;
- }
- assertEquals("Wrong exception", 1, result);
- }
-
- /**
- * java.util.Arrays#fill(short[], short)
- */
- public void test_fill$SS() {
- // Test for method void java.util.Arrays.fill(short [], short)
-
- short d[] = new short[1000];
- Arrays.fill(d, Short.MAX_VALUE);
- for (int i = 0; i < d.length; i++)
- assertTrue("Failed to fill short array correctly",
- d[i] == Short.MAX_VALUE);
- }
-
- /**
- * java.util.Arrays#fill(short[], int, int, short)
- */
- public void test_fill$SIIS() {
- // Test for method void java.util.Arrays.fill(short [], int, int, short)
- short val = Short.MAX_VALUE;
- short d[] = new short[1000];
- Arrays.fill(d, 400, d.length, val);
- for (int i = 0; i < 400; i++)
- assertTrue("Filled elements not in range", !(d[i] == val));
- for (int i = 400; i < d.length; i++)
- assertTrue("Failed to fill short array correctly", d[i] == val);
- }
-
- /**
- * java.util.Arrays#fill(char[], char)
- */
- public void test_fill$CC() {
- // Test for method void java.util.Arrays.fill(char [], char)
-
- char d[] = new char[1000];
- Arrays.fill(d, 'V');
- for (int i = 0; i < d.length; i++)
- assertEquals("Failed to fill char array correctly", 'V', d[i]);
- }
-
- /**
- * java.util.Arrays#fill(char[], int, int, char)
- */
- public void test_fill$CIIC() {
- // Test for method void java.util.Arrays.fill(char [], int, int, char)
- char val = 'T';
- char d[] = new char[1000];
- Arrays.fill(d, 400, d.length, val);
- for (int i = 0; i < 400; i++)
- assertTrue("Filled elements not in range", !(d[i] == val));
- for (int i = 400; i < d.length; i++)
- assertTrue("Failed to fill char array correctly", d[i] == val);
- }
-
- /**
- * java.util.Arrays#fill(int[], int)
- */
- public void test_fill$II() {
- // Test for method void java.util.Arrays.fill(int [], int)
-
- int d[] = new int[1000];
- Arrays.fill(d, Integer.MAX_VALUE);
- for (int i = 0; i < d.length; i++)
- assertTrue("Failed to fill int array correctly",
- d[i] == Integer.MAX_VALUE);
- }
-
- /**
- * java.util.Arrays#fill(int[], int, int, int)
- */
- public void test_fill$IIII() {
- // Test for method void java.util.Arrays.fill(int [], int, int, int)
- int val = Integer.MAX_VALUE;
- int d[] = new int[1000];
- Arrays.fill(d, 400, d.length, val);
- for (int i = 0; i < 400; i++)
- assertTrue("Filled elements not in range", !(d[i] == val));
- for (int i = 400; i < d.length; i++)
- assertTrue("Failed to fill int array correctly", d[i] == val);
- }
-
- /**
- * java.util.Arrays#fill(long[], long)
- */
- public void test_fill$JJ() {
- // Test for method void java.util.Arrays.fill(long [], long)
-
- long d[] = new long[1000];
- Arrays.fill(d, Long.MAX_VALUE);
- for (int i = 0; i < d.length; i++)
- assertTrue("Failed to fill long array correctly",
- d[i] == Long.MAX_VALUE);
- }
-
- /**
- * java.util.Arrays#fill(long[], int, int, long)
- */
- public void test_fill$JIIJ() {
- // Test for method void java.util.Arrays.fill(long [], int, int, long)
- long d[] = new long[1000];
- Arrays.fill(d, 400, d.length, Long.MAX_VALUE);
- for (int i = 0; i < 400; i++)
- assertTrue("Filled elements not in range", !(d[i] == Long.MAX_VALUE));
- for (int i = 400; i < d.length; i++)
- assertTrue("Failed to fill long array correctly",
- d[i] == Long.MAX_VALUE);
- }
-
- /**
- * java.util.Arrays#fill(float[], float)
- */
- public void test_fill$FF() {
- // Test for method void java.util.Arrays.fill(float [], float)
- float d[] = new float[1000];
- Arrays.fill(d, Float.MAX_VALUE);
- for (int i = 0; i < d.length; i++)
- assertTrue("Failed to fill float array correctly",
- d[i] == Float.MAX_VALUE);
- }
-
- /**
- * java.util.Arrays#fill(float[], int, int, float)
- */
- public void test_fill$FIIF() {
- // Test for method void java.util.Arrays.fill(float [], int, int, float)
- float val = Float.MAX_VALUE;
- float d[] = new float[1000];
- Arrays.fill(d, 400, d.length, val);
- for (int i = 0; i < 400; i++)
- assertTrue("Filled elements not in range", !(d[i] == val));
- for (int i = 400; i < d.length; i++)
- assertTrue("Failed to fill float array correctly", d[i] == val);
- }
-
- /**
- * java.util.Arrays#fill(double[], double)
- */
- public void test_fill$DD() {
- // Test for method void java.util.Arrays.fill(double [], double)
-
- double d[] = new double[1000];
- Arrays.fill(d, Double.MAX_VALUE);
- for (int i = 0; i < d.length; i++)
- assertTrue("Failed to fill double array correctly",
- d[i] == Double.MAX_VALUE);
- }
-
- /**
- * java.util.Arrays#fill(double[], int, int, double)
- */
- public void test_fill$DIID() {
- // Test for method void java.util.Arrays.fill(double [], int, int,
- // double)
- double val = Double.MAX_VALUE;
- double d[] = new double[1000];
- Arrays.fill(d, 400, d.length, val);
- for (int i = 0; i < 400; i++)
- assertTrue("Filled elements not in range", !(d[i] == val));
- for (int i = 400; i < d.length; i++)
- assertTrue("Failed to fill double array correctly", d[i] == val);
- }
-
- /**
- * java.util.Arrays#fill(boolean[], boolean)
- */
- public void test_fill$ZZ() {
- // Test for method void java.util.Arrays.fill(boolean [], boolean)
-
- boolean d[] = new boolean[1000];
- Arrays.fill(d, true);
- for (int i = 0; i < d.length; i++)
- assertTrue("Failed to fill boolean array correctly", d[i]);
- }
-
- /**
- * java.util.Arrays#fill(boolean[], int, int, boolean)
- */
- public void test_fill$ZIIZ() {
- // Test for method void java.util.Arrays.fill(boolean [], int, int,
- // boolean)
- boolean val = true;
- boolean d[] = new boolean[1000];
- Arrays.fill(d, 400, d.length, val);
- for (int i = 0; i < 400; i++)
- assertTrue("Filled elements not in range", !(d[i] == val));
- for (int i = 400; i < d.length; i++)
- assertTrue("Failed to fill boolean array correctly", d[i] == val);
- }
-
- /**
- * java.util.Arrays#fill(java.lang.Object[], java.lang.Object)
- */
- public void test_fill$Ljava_lang_ObjectLjava_lang_Object() {
- // Test for method void java.util.Arrays.fill(java.lang.Object [],
- // java.lang.Object)
- Object val = new Object();
- Object d[] = new Object[1000];
- Arrays.fill(d, 0, d.length, val);
- for (int i = 0; i < d.length; i++)
- assertTrue("Failed to fill Object array correctly", d[i] == val);
- }
-
- /**
- * java.util.Arrays#fill(java.lang.Object[], int, int,
- * java.lang.Object)
- */
- public void test_fill$Ljava_lang_ObjectIILjava_lang_Object() {
- // Test for method void java.util.Arrays.fill(java.lang.Object [], int,
- // int, java.lang.Object)
- Object val = new Object();
- Object d[] = new Object[1000];
- Arrays.fill(d, 400, d.length, val);
- for (int i = 0; i < 400; i++)
- assertTrue("Filled elements not in range", !(d[i] == val));
- for (int i = 400; i < d.length; i++)
- assertTrue("Failed to fill Object array correctly", d[i] == val);
-
- Arrays.fill(d, 400, d.length, null);
- for (int i = 400; i < d.length; i++)
- assertNull("Failed to fill Object array correctly with nulls",
- d[i]);
- }
-
- /**
- * java.util.Arrays#equals(byte[], byte[])
- */
- public void test_equals$B$B() {
- // Test for method boolean java.util.Arrays.equals(byte [], byte [])
- byte d[] = new byte[1000];
- byte x[] = new byte[1000];
- Arrays.fill(d, Byte.MAX_VALUE);
- Arrays.fill(x, Byte.MIN_VALUE);
- assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
- Arrays.fill(x, Byte.MAX_VALUE);
- assertTrue("equal arrays returned false", Arrays.equals(d, x));
- }
-
- /**
- * java.util.Arrays#equals(short[], short[])
- */
- public void test_equals$S$S() {
- // Test for method boolean java.util.Arrays.equals(short [], short [])
- short d[] = new short[1000];
- short x[] = new short[1000];
- Arrays.fill(d, Short.MAX_VALUE);
- Arrays.fill(x, Short.MIN_VALUE);
- assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
- Arrays.fill(x, Short.MAX_VALUE);
- assertTrue("equal arrays returned false", Arrays.equals(d, x));
- }
-
- /**
- * java.util.Arrays#equals(char[], char[])
- */
- public void test_equals$C$C() {
- // Test for method boolean java.util.Arrays.equals(char [], char [])
- char d[] = new char[1000];
- char x[] = new char[1000];
- char c = 'T';
- Arrays.fill(d, c);
- Arrays.fill(x, 'L');
- assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
- Arrays.fill(x, c);
- assertTrue("equal arrays returned false", Arrays.equals(d, x));
- }
-
- /**
- * java.util.Arrays#equals(int[], int[])
- */
- public void test_equals$I$I() {
- // Test for method boolean java.util.Arrays.equals(int [], int [])
- int d[] = new int[1000];
- int x[] = new int[1000];
- Arrays.fill(d, Integer.MAX_VALUE);
- Arrays.fill(x, Integer.MIN_VALUE);
- assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
- Arrays.fill(x, Integer.MAX_VALUE);
- assertTrue("equal arrays returned false", Arrays.equals(d, x));
-
- assertTrue("wrong result for null array1", !Arrays.equals(new int[2],
- null));
- assertTrue("wrong result for null array2", !Arrays.equals(null,
- new int[2]));
- }
-
- /**
- * java.util.Arrays#equals(long[], long[])
- */
- public void test_equals$J$J() {
- // Test for method boolean java.util.Arrays.equals(long [], long [])
- long d[] = new long[1000];
- long x[] = new long[1000];
- Arrays.fill(d, Long.MAX_VALUE);
- Arrays.fill(x, Long.MIN_VALUE);
- assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
- Arrays.fill(x, Long.MAX_VALUE);
- assertTrue("equal arrays returned false", Arrays.equals(d, x));
-
- assertTrue("should be false", !Arrays.equals(
- new long[] { 0x100000000L }, new long[] { 0x200000000L }));
-
- }
-
- /**
- * java.util.Arrays#equals(float[], float[])
- */
- public void test_equals$F$F() {
- // Test for method boolean java.util.Arrays.equals(float [], float [])
- float d[] = new float[1000];
- float x[] = new float[1000];
- Arrays.fill(d, Float.MAX_VALUE);
- Arrays.fill(x, Float.MIN_VALUE);
- assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
- Arrays.fill(x, Float.MAX_VALUE);
- assertTrue("equal arrays returned false", Arrays.equals(d, x));
-
- assertTrue("NaN not equals", Arrays.equals(new float[] { Float.NaN },
- new float[] { Float.NaN }));
- assertTrue("0f equals -0f", !Arrays.equals(new float[] { 0f },
- new float[] { -0f }));
- }
-
- /**
- * java.util.Arrays#equals(double[], double[])
- */
- public void test_equals$D$D() {
- // Test for method boolean java.util.Arrays.equals(double [], double [])
- double d[] = new double[1000];
- double x[] = new double[1000];
- Arrays.fill(d, Double.MAX_VALUE);
- Arrays.fill(x, Double.MIN_VALUE);
- assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
- Arrays.fill(x, Double.MAX_VALUE);
- assertTrue("equal arrays returned false", Arrays.equals(d, x));
-
- assertTrue("should be false", !Arrays.equals(new double[] { 1.0 },
- new double[] { 2.0 }));
-
- assertTrue("NaN not equals", Arrays.equals(new double[] { Double.NaN },
- new double[] { Double.NaN }));
- assertTrue("0d equals -0d", !Arrays.equals(new double[] { 0d },
- new double[] { -0d }));
- }
-
- /**
- * java.util.Arrays#equals(boolean[], boolean[])
- */
- public void test_equals$Z$Z() {
- // Test for method boolean java.util.Arrays.equals(boolean [], boolean
- // [])
- boolean d[] = new boolean[1000];
- boolean x[] = new boolean[1000];
- Arrays.fill(d, true);
- Arrays.fill(x, false);
- assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
- Arrays.fill(x, true);
- assertTrue("equal arrays returned false", Arrays.equals(d, x));
- }
-
- /**
- * java.util.Arrays#equals(java.lang.Object[], java.lang.Object[])
- */
- public void test_equals$Ljava_lang_Object$Ljava_lang_Object() {
- // Test for method boolean java.util.Arrays.equals(java.lang.Object [],
- // java.lang.Object [])
- Object d[] = new Object[1000];
- Object x[] = new Object[1000];
- Object o = new Object();
- Arrays.fill(d, o);
- Arrays.fill(x, new Object());
- assertTrue("Inequal arrays returned true", !Arrays.equals(d, x));
- Arrays.fill(x, o);
- d[50] = null;
- x[50] = null;
- assertTrue("equal arrays returned false", Arrays.equals(d, x));
- }
-
- /**
- * java.util.Arrays#sort(byte[])
- */
- public void test_sort$B() {
- // Test for method void java.util.Arrays.sort(byte [])
- byte[] reversedArray = new byte[arraySize];
- for (int counter = 0; counter < arraySize; counter++)
- reversedArray[counter] = (byte) (arraySize - counter - 1);
- Arrays.sort(reversedArray);
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue("Resulting array not sorted",
- reversedArray[counter] == (byte) counter);
- }
-
- /**
- * java.util.Arrays#sort(byte[], int, int)
- */
- public void test_sort$BII() {
- // Test for method void java.util.Arrays.sort(byte [], int, int)
- int startIndex = arraySize / 4;
- int endIndex = 3 * arraySize / 4;
- byte[] reversedArray = new byte[arraySize];
- byte[] originalReversedArray = new byte[arraySize];
- for (int counter = 0; counter < arraySize; counter++) {
- reversedArray[counter] = (byte) (arraySize - counter - 1);
- originalReversedArray[counter] = reversedArray[counter];
- }
- Arrays.sort(reversedArray, startIndex, endIndex);
- for (int counter = 0; counter < startIndex; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
- for (int counter = startIndex; counter < endIndex - 1; counter++)
- assertTrue("Array not sorted within bounds",
- reversedArray[counter] <= reversedArray[counter + 1]);
- for (int counter = endIndex; counter < arraySize; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
-
- //exception testing
- try {
- Arrays.sort(reversedArray, startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, -1, startIndex);
- fail("ArrayIndexOutOfBoundsException expected (1)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
- fail("ArrayIndexOutOfBoundsException expected (2)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- //exception order testing
- try {
- Arrays.sort(new byte[1], startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
- }
-
- /**
- * java.util.Arrays#sort(char[])
- */
- public void test_sort$C() {
- // Test for method void java.util.Arrays.sort(char [])
- char[] reversedArray = new char[arraySize];
- for (int counter = 0; counter < arraySize; counter++)
- reversedArray[counter] = (char) (arraySize - counter - 1);
- Arrays.sort(reversedArray);
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue("Resulting array not sorted",
- reversedArray[counter] == (char) counter);
-
- }
-
- /**
- * java.util.Arrays#sort(char[], int, int)
- */
- public void test_sort$CII() {
- // Test for method void java.util.Arrays.sort(char [], int, int)
- int startIndex = arraySize / 4;
- int endIndex = 3 * arraySize / 4;
- char[] reversedArray = new char[arraySize];
- char[] originalReversedArray = new char[arraySize];
- for (int counter = 0; counter < arraySize; counter++) {
- reversedArray[counter] = (char) (arraySize - counter - 1);
- originalReversedArray[counter] = reversedArray[counter];
- }
- Arrays.sort(reversedArray, startIndex, endIndex);
- for (int counter = 0; counter < startIndex; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
- for (int counter = startIndex; counter < endIndex - 1; counter++)
- assertTrue("Array not sorted within bounds",
- reversedArray[counter] <= reversedArray[counter + 1]);
- for (int counter = endIndex; counter < arraySize; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
-
- //exception testing
- try {
- Arrays.sort(reversedArray, startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, -1, startIndex);
- fail("ArrayIndexOutOfBoundsException expected (1)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
- fail("ArrayIndexOutOfBoundsException expected (2)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- //exception order testing
- try {
- Arrays.sort(new char[1], startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
- }
-
- /**
- * java.util.Arrays#sort(double[])
- */
- public void test_sort$D() {
- // Test for method void java.util.Arrays.sort(double [])
- double[] reversedArray = new double[arraySize];
- for (int counter = 0; counter < arraySize; counter++)
- reversedArray[counter] = (double) (arraySize - counter - 1);
- Arrays.sort(reversedArray);
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue("Resulting array not sorted",
- reversedArray[counter] == (double) counter);
-
- double[] specials1 = new double[] { Double.NaN, Double.MAX_VALUE,
- Double.MIN_VALUE, 0d, -0d, Double.POSITIVE_INFINITY,
- Double.NEGATIVE_INFINITY };
- double[] specials2 = new double[] { 0d, Double.POSITIVE_INFINITY, -0d,
- Double.NEGATIVE_INFINITY, Double.MIN_VALUE, Double.NaN,
- Double.MAX_VALUE };
- double[] specials3 = new double[] { 0.0, Double.NaN, 1.0, 2.0, Double.NaN,
- Double.NaN, 1.0, 3.0, -0.0};
- double[] answer = new double[] { Double.NEGATIVE_INFINITY, -0d, 0d,
- Double.MIN_VALUE, Double.MAX_VALUE, Double.POSITIVE_INFINITY,
- Double.NaN };
- double[] answer3 = new double[] { -0.0, 0.0, 1.0, 1.0, 2.0, 3.0, Double.NaN,
- Double.NaN, Double.NaN };
-
- Arrays.sort(specials1);
- Object[] print1 = new Object[specials1.length];
- for (int i = 0; i < specials1.length; i++)
- print1[i] = new Double(specials1[i]);
- assertTrue("specials sort incorrectly 1: " + Arrays.asList(print1),
- Arrays.equals(specials1, answer));
-
- Arrays.sort(specials2);
- Object[] print2 = new Object[specials2.length];
- for (int i = 0; i < specials2.length; i++)
- print2[i] = new Double(specials2[i]);
- assertTrue("specials sort incorrectly 2: " + Arrays.asList(print2),
- Arrays.equals(specials2, answer));
-
- Arrays.sort(specials3);
- Object[] print3 = new Object[specials3.length];
- for (int i = 0; i < specials3.length; i++)
- print3[i] = new Double(specials3[i]);
- assertTrue("specials sort incorrectly 3: " + Arrays.asList(print3),
- Arrays.equals(specials3, answer3));
- }
-
- /**
- * java.util.Arrays#sort(double[], int, int)
- */
- public void test_sort$DII() {
- // Test for method void java.util.Arrays.sort(double [], int, int)
- int startIndex = arraySize / 4;
- int endIndex = 3 * arraySize / 4;
- double[] reversedArray = new double[arraySize];
- double[] originalReversedArray = new double[arraySize];
- for (int counter = 0; counter < arraySize; counter++) {
- reversedArray[counter] = (double) (arraySize - counter - 1);
- originalReversedArray[counter] = reversedArray[counter];
- }
- Arrays.sort(reversedArray, startIndex, endIndex);
- for (int counter = 0; counter < startIndex; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
- for (int counter = startIndex; counter < endIndex - 1; counter++)
- assertTrue("Array not sorted within bounds",
- reversedArray[counter] <= reversedArray[counter + 1]);
- for (int counter = endIndex; counter < arraySize; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
-
- //exception testing
- try {
- Arrays.sort(reversedArray, startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, -1, startIndex);
- fail("ArrayIndexOutOfBoundsException expected (1)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
- fail("ArrayIndexOutOfBoundsException expected (2)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- //exception order testing
- try {
- Arrays.sort(new double[1], startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
- }
-
- /**
- * java.util.Arrays#sort(float[])
- */
- public void test_sort$F() {
- // Test for method void java.util.Arrays.sort(float [])
- float[] reversedArray = new float[arraySize];
- for (int counter = 0; counter < arraySize; counter++)
- reversedArray[counter] = (float) (arraySize - counter - 1);
- Arrays.sort(reversedArray);
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue("Resulting array not sorted",
- reversedArray[counter] == (float) counter);
-
- float[] specials1 = new float[] { Float.NaN, Float.MAX_VALUE,
- Float.MIN_VALUE, 0f, -0f, Float.POSITIVE_INFINITY,
- Float.NEGATIVE_INFINITY };
- float[] specials2 = new float[] { 0f, Float.POSITIVE_INFINITY, -0f,
- Float.NEGATIVE_INFINITY, Float.MIN_VALUE, Float.NaN,
- Float.MAX_VALUE };
- float[] answer = new float[] { Float.NEGATIVE_INFINITY, -0f, 0f,
- Float.MIN_VALUE, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
- Float.NaN };
-
- Arrays.sort(specials1);
- Object[] print1 = new Object[specials1.length];
- for (int i = 0; i < specials1.length; i++)
- print1[i] = new Float(specials1[i]);
- assertTrue("specials sort incorrectly 1: " + Arrays.asList(print1),
- Arrays.equals(specials1, answer));
-
- Arrays.sort(specials2);
- Object[] print2 = new Object[specials2.length];
- for (int i = 0; i < specials2.length; i++)
- print2[i] = new Float(specials2[i]);
- assertTrue("specials sort incorrectly 2: " + Arrays.asList(print2),
- Arrays.equals(specials2, answer));
- }
-
- /**
- * java.util.Arrays#sort(float[], int, int)
- */
- public void test_sort$FII() {
- // Test for method void java.util.Arrays.sort(float [], int, int)
- int startIndex = arraySize / 4;
- int endIndex = 3 * arraySize / 4;
- float[] reversedArray = new float[arraySize];
- float[] originalReversedArray = new float[arraySize];
- for (int counter = 0; counter < arraySize; counter++) {
- reversedArray[counter] = (float) (arraySize - counter - 1);
- originalReversedArray[counter] = reversedArray[counter];
- }
- Arrays.sort(reversedArray, startIndex, endIndex);
- for (int counter = 0; counter < startIndex; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
- for (int counter = startIndex; counter < endIndex - 1; counter++)
- assertTrue("Array not sorted within bounds",
- reversedArray[counter] <= reversedArray[counter + 1]);
- for (int counter = endIndex; counter < arraySize; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
-
- //exception testing
- try {
- Arrays.sort(reversedArray, startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, -1, startIndex);
- fail("ArrayIndexOutOfBoundsException expected (1)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
- fail("ArrayIndexOutOfBoundsException expected (2)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- //exception order testing
- try {
- Arrays.sort(new float[1], startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
- }
-
- /**
- * java.util.Arrays#sort(int[])
- */
- public void test_sort$I() {
- // Test for method void java.util.Arrays.sort(int [])
- int[] reversedArray = new int[arraySize];
- for (int counter = 0; counter < arraySize; counter++)
- reversedArray[counter] = arraySize - counter - 1;
- Arrays.sort(reversedArray);
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue("Resulting array not sorted",
- reversedArray[counter] == counter);
- }
-
- /**
- * java.util.Arrays#sort(int[], int, int)
- */
- public void test_sort$III() {
- // Test for method void java.util.Arrays.sort(int [], int, int)
- int startIndex = arraySize / 4;
- int endIndex = 3 * arraySize / 4;
- int[] reversedArray = new int[arraySize];
- int[] originalReversedArray = new int[arraySize];
- for (int counter = 0; counter < arraySize; counter++) {
- reversedArray[counter] = arraySize - counter - 1;
- originalReversedArray[counter] = reversedArray[counter];
- }
- Arrays.sort(reversedArray, startIndex, endIndex);
- for (int counter = 0; counter < startIndex; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
- for (int counter = startIndex; counter < endIndex - 1; counter++)
- assertTrue("Array not sorted within bounds",
- reversedArray[counter] <= reversedArray[counter + 1]);
- for (int counter = endIndex; counter < arraySize; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
-
- //exception testing
- try {
- Arrays.sort(reversedArray, startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, -1, startIndex);
- fail("ArrayIndexOutOfBoundsException expected (1)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
- fail("ArrayIndexOutOfBoundsException expected (2)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- //exception order testing
- try {
- Arrays.sort(new int[1], startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
- }
-
- /**
- * java.util.Arrays#sort(long[])
- */
- public void test_sort$J() {
- // Test for method void java.util.Arrays.sort(long [])
- long[] reversedArray = new long[arraySize];
- for (int counter = 0; counter < arraySize; counter++)
- reversedArray[counter] = (long) (arraySize - counter - 1);
- Arrays.sort(reversedArray);
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue("Resulting array not sorted",
- reversedArray[counter] == (long) counter);
-
- }
-
- /**
- * java.util.Arrays#sort(long[], int, int)
- */
- public void test_sort$JII() {
- // Test for method void java.util.Arrays.sort(long [], int, int)
- int startIndex = arraySize / 4;
- int endIndex = 3 * arraySize / 4;
- long[] reversedArray = new long[arraySize];
- long[] originalReversedArray = new long[arraySize];
- for (int counter = 0; counter < arraySize; counter++) {
- reversedArray[counter] = (long) (arraySize - counter - 1);
- originalReversedArray[counter] = reversedArray[counter];
- }
- Arrays.sort(reversedArray, startIndex, endIndex);
- for (int counter = 0; counter < startIndex; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
- for (int counter = startIndex; counter < endIndex - 1; counter++)
- assertTrue("Array not sorted within bounds",
- reversedArray[counter] <= reversedArray[counter + 1]);
- for (int counter = endIndex; counter < arraySize; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
-
- //exception testing
- try {
- Arrays.sort(reversedArray, startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, -1, startIndex);
- fail("ArrayIndexOutOfBoundsException expected (1)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
- fail("ArrayIndexOutOfBoundsException expected (2)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- //exception order testing
- try {
- Arrays.sort(new long[1], startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
- }
-
- /**
- * java.util.Arrays#sort(java.lang.Object[])
- */
- public void test_sort$Ljava_lang_Object() {
- // Test for method void java.util.Arrays.sort(java.lang.Object [])
- Object[] reversedArray = new Object[arraySize];
- for (int counter = 0; counter < arraySize; counter++)
- reversedArray[counter] = objectArray[arraySize - counter - 1];
- Arrays.sort(reversedArray);
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue("Resulting array not sorted",
- reversedArray[counter] == objectArray[counter]);
- }
-
- /**
- * java.util.Arrays#sort(java.lang.Object[], int, int)
- */
- public void test_sort$Ljava_lang_ObjectII() {
- // Test for method void java.util.Arrays.sort(java.lang.Object [], int,
- // int)
- int startIndex = arraySize / 4;
- int endIndex = 3 * arraySize / 4;
- Object[] reversedArray = new Object[arraySize];
- Object[] originalReversedArray = new Object[arraySize];
- for (int counter = 0; counter < arraySize; counter++) {
- reversedArray[counter] = objectArray[arraySize - counter - 1];
- originalReversedArray[counter] = reversedArray[counter];
- }
- Arrays.sort(reversedArray, startIndex, endIndex);
- for (int counter = 0; counter < startIndex; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
- for (int counter = startIndex; counter < endIndex - 1; counter++)
- assertTrue("Array not sorted within bounds",
- ((Comparable) reversedArray[counter])
- .compareTo(reversedArray[counter + 1]) <= 0);
- for (int counter = endIndex; counter < arraySize; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
-
- //exception testing
- try {
- Arrays.sort(reversedArray, startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, -1, startIndex);
- fail("ArrayIndexOutOfBoundsException expected (1)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
- fail("ArrayIndexOutOfBoundsException expected (2)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- //exception order testing
- try {
- Arrays.sort(new Object[1], startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
- }
-
- /**
- * java.util.Arrays#sort(java.lang.Object[], int, int,
- * java.util.Comparator)
- */
- public void test_sort$Ljava_lang_ObjectIILjava_util_Comparator() {
- // Test for method void java.util.Arrays.sort(java.lang.Object [], int,
- // int, java.util.Comparator)
- int startIndex = arraySize / 4;
- int endIndex = 3 * arraySize / 4;
- ReversedIntegerComparator comp = new ReversedIntegerComparator();
- Object[] originalArray = new Object[arraySize];
- for (int counter = 0; counter < arraySize; counter++)
- originalArray[counter] = objectArray[counter];
- Arrays.sort(objectArray, startIndex, endIndex, comp);
- for (int counter = 0; counter < startIndex; counter++)
- assertTrue("Array modified outside of bounds",
- objectArray[counter] == originalArray[counter]);
- for (int counter = startIndex; counter < endIndex - 1; counter++)
- assertTrue("Array not sorted within bounds", comp.compare(
- objectArray[counter], objectArray[counter + 1]) <= 0);
- for (int counter = endIndex; counter < arraySize; counter++)
- assertTrue("Array modified outside of bounds",
- objectArray[counter] == originalArray[counter]);
- }
-
- /**
- * java.util.Arrays#sort(java.lang.Object[], java.util.Comparator)
- */
- public void test_sort$Ljava_lang_ObjectLjava_util_Comparator() {
- // Test for method void java.util.Arrays.sort(java.lang.Object [],
- // java.util.Comparator)
- ReversedIntegerComparator comp = new ReversedIntegerComparator();
- Arrays.sort(objectArray, comp);
- for (int counter = 0; counter < arraySize - 1; counter++)
- assertTrue("Array not sorted correctly with custom comparator",
- comp
- .compare(objectArray[counter],
- objectArray[counter + 1]) <= 0);
- }
-
- // Regression HARMONY-6076
- public void test_sort$Ljava_lang_ObjectLjava_util_Comparator_stable() {
- Element[] array = new Element[11];
- array[0] = new Element(122);
- array[1] = new Element(146);
- array[2] = new Element(178);
- array[3] = new Element(208);
- array[4] = new Element(117);
- array[5] = new Element(146);
- array[6] = new Element(173);
- array[7] = new Element(203);
- array[8] = new Element(56);
- array[9] = new Element(208);
- array[10] = new Element(96);
-
- Comparator<Element> comparator = new Comparator<Element>() {
- public int compare(Element object1, Element object2) {
- return object1.value - object2.value;
- }
- };
-
- Arrays.sort(array, comparator);
-
- for (int i = 1; i < array.length; i++) {
- assertTrue(comparator.compare(array[i - 1], array[i]) <= 0);
- if (comparator.compare(array[i - 1], array[i]) == 0) {
- assertTrue(array[i - 1].index < array[i].index);
- }
- }
- }
-
- public static class Element {
- public int value;
-
- public int index;
-
- private static int count = 0;
-
- public Element(int value) {
- this.value = value;
- index = count++;
- }
- }
-
- /**
- * java.util.Arrays#sort(short[])
- */
- public void test_sort$S() {
- // Test for method void java.util.Arrays.sort(short [])
- short[] reversedArray = new short[arraySize];
- for (int counter = 0; counter < arraySize; counter++)
- reversedArray[counter] = (short) (arraySize - counter - 1);
- Arrays.sort(reversedArray);
- for (int counter = 0; counter < arraySize; counter++)
- assertTrue("Resulting array not sorted",
- reversedArray[counter] == (short) counter);
- }
-
- /**
- * java.util.Arrays#sort(short[], int, int)
- */
- public void test_sort$SII() {
- // Test for method void java.util.Arrays.sort(short [], int, int)
- int startIndex = arraySize / 4;
- int endIndex = 3 * arraySize / 4;
- short[] reversedArray = new short[arraySize];
- short[] originalReversedArray = new short[arraySize];
- for (int counter = 0; counter < arraySize; counter++) {
- reversedArray[counter] = (short) (arraySize - counter - 1);
- originalReversedArray[counter] = reversedArray[counter];
- }
- Arrays.sort(reversedArray, startIndex, endIndex);
- for (int counter = 0; counter < startIndex; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
- for (int counter = startIndex; counter < endIndex - 1; counter++)
- assertTrue("Array not sorted within bounds",
- reversedArray[counter] <= reversedArray[counter + 1]);
- for (int counter = endIndex; counter < arraySize; counter++)
- assertTrue("Array modified outside of bounds",
- reversedArray[counter] == originalReversedArray[counter]);
-
- //exception testing
- try {
- Arrays.sort(reversedArray, startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, -1, startIndex);
- fail("ArrayIndexOutOfBoundsException expected (1)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- try {
- Arrays.sort(reversedArray, startIndex, reversedArray.length + 1);
- fail("ArrayIndexOutOfBoundsException expected (2)");
- } catch (ArrayIndexOutOfBoundsException ignore) {
- }
-
- //exception order testing
- try {
- Arrays.sort(new short[1], startIndex + 1, startIndex);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ignore) {
- }
- }
-
- /**
- * java.util.Arrays#sort(byte[], int, int)
- */
- public void test_java_util_Arrays_sort_byte_array_NPE() {
- byte[] byte_array_null = null;
- try {
- java.util.Arrays.sort(byte_array_null);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- // Regression for HARMONY-378
- java.util.Arrays.sort(byte_array_null, (int) -1, (int) 1);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * java.util.Arrays#sort(char[], int, int)
- */
- public void test_java_util_Arrays_sort_char_array_NPE() {
- char[] char_array_null = null;
- try {
- java.util.Arrays.sort(char_array_null);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- // Regression for HARMONY-378
- java.util.Arrays.sort(char_array_null, (int) -1, (int) 1);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * java.util.Arrays#sort(double[], int, int)
- */
- public void test_java_util_Arrays_sort_double_array_NPE() {
- double[] double_array_null = null;
- try {
- java.util.Arrays.sort(double_array_null);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- // Regression for HARMONY-378
- java.util.Arrays.sort(double_array_null, (int) -1, (int) 1);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * java.util.Arrays#sort(float[], int, int)
- */
- public void test_java_util_Arrays_sort_float_array_NPE() {
- float[] float_array_null = null;
- try {
- java.util.Arrays.sort(float_array_null);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- // Regression for HARMONY-378
- java.util.Arrays.sort(float_array_null, (int) -1, (int) 1);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * java.util.Arrays#sort(int[], int, int)
- */
- public void test_java_util_Arrays_sort_int_array_NPE() {
- int[] int_array_null = null;
- try {
- java.util.Arrays.sort(int_array_null);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- // Regression for HARMONY-378
- java.util.Arrays.sort(int_array_null, (int) -1, (int) 1);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * java.util.Arrays#sort(Object[], int, int)
- */
- public void test_java_util_Arrays_sort_object_array_NPE() {
- Object[] object_array_null = null;
- try {
- java.util.Arrays.sort(object_array_null);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- // Regression for HARMONY-378
- java.util.Arrays.sort(object_array_null, (int) -1, (int) 1);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- // Regression for HARMONY-378
- java.util.Arrays.sort(object_array_null, (int) -1, (int) 1, null);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * java.util.Arrays#sort(long[], int, int)
- */
- public void test_java_util_Arrays_sort_long_array_NPE() {
- long[] long_array_null = null;
- try {
- java.util.Arrays.sort(long_array_null);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- // Regression for HARMONY-378
- java.util.Arrays.sort(long_array_null, (int) -1, (int) 1);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * java.util.Arrays#sort(short[], int, int)
- */
- public void test_java_util_Arrays_sort_short_array_NPE() {
- short[] short_array_null = null;
- try {
- java.util.Arrays.sort(short_array_null);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- // Regression for HARMONY-378
- java.util.Arrays.sort(short_array_null, (int) -1, (int) 1);
- fail("Should throw java.lang.NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * java.util.Arrays#deepEquals(Object[], Object[])
- */
- public void test_deepEquals$Ljava_lang_ObjectLjava_lang_Object() {
- int [] a1 = {1, 2, 3};
- short [] a2 = {0, 1};
- Object [] a3 = {new Integer(1), a2};
- int [] a4 = {6, 5, 4};
-
- int [] b1 = {1, 2, 3};
- short [] b2 = {0, 1};
- Object [] b3 = {new Integer(1), b2};
-
- Object a [] = {a1, a2, a3};
- Object b [] = {b1, b2, b3};
-
- assertFalse(Arrays.equals(a, b));
- assertTrue(Arrays.deepEquals(a,b));
-
- a[2] = a4;
-
- assertFalse(Arrays.deepEquals(a, b));
- }
-
- /**
- * java.util.Arrays#deepHashCode(Object[])
- */
- public void test_deepHashCode$Ljava_lang_Object() {
- int [] a1 = {1, 2, 3};
- short [] a2 = {0, 1};
- Object [] a3 = {new Integer(1), a2};
-
- int [] b1 = {1, 2, 3};
- short [] b2 = {0, 1};
- Object [] b3 = {new Integer(1), b2};
-
- Object a [] = {a1, a2, a3};
- Object b [] = {b1, b2, b3};
-
- int deep_hash_a = Arrays.deepHashCode(a);
- int deep_hash_b = Arrays.deepHashCode(b);
-
- assertEquals(deep_hash_a, deep_hash_b);
- }
-
- /**
- * java.util.Arrays#hashCode(boolean[] a)
- */
- public void test_hashCode$LZ() {
- int listHashCode;
- int arrayHashCode;
-
- boolean [] boolArr = {true, false, false, true, false};
- List listOfBoolean = new LinkedList();
- for (int i = 0; i < boolArr.length; i++) {
- listOfBoolean.add(new Boolean(boolArr[i]));
- }
- listHashCode = listOfBoolean.hashCode();
- arrayHashCode = Arrays.hashCode(boolArr);
- assertEquals(listHashCode, arrayHashCode);
- }
-
- /**
- * java.util.Arrays#hashCode(int[] a)
- */
- public void test_hashCode$LI() {
- int listHashCode;
- int arrayHashCode;
-
- int [] intArr = {10, 5, 134, 7, 19};
- List listOfInteger = new LinkedList();
-
- for (int i = 0; i < intArr.length; i++) {
- listOfInteger.add(new Integer(intArr[i]));
- }
- listHashCode = listOfInteger.hashCode();
- arrayHashCode = Arrays.hashCode(intArr);
- assertEquals(listHashCode, arrayHashCode);
-
- int [] intArr2 = {10, 5, 134, 7, 19};
- assertEquals(Arrays.hashCode(intArr2), Arrays.hashCode(intArr));
- }
-
- /**
- * java.util.Arrays#hashCode(char[] a)
- */
- public void test_hashCode$LC() {
- int listHashCode;
- int arrayHashCode;
-
- char [] charArr = {'a', 'g', 'x', 'c', 'm'};
- List listOfCharacter = new LinkedList();
- for (int i = 0; i < charArr.length; i++) {
- listOfCharacter.add(new Character(charArr[i]));
- }
- listHashCode = listOfCharacter.hashCode();
- arrayHashCode = Arrays.hashCode(charArr);
- assertEquals(listHashCode, arrayHashCode);
- }
-
- /**
- * java.util.Arrays#hashCode(byte[] a)
- */
- public void test_hashCode$LB() {
- int listHashCode;
- int arrayHashCode;
-
- byte [] byteArr = {5, 9, 7, 6, 17};
- List listOfByte = new LinkedList();
- for (int i = 0; i < byteArr.length; i++) {
- listOfByte.add(new Byte(byteArr[i]));
- }
- listHashCode = listOfByte.hashCode();
- arrayHashCode = Arrays.hashCode(byteArr);
- assertEquals(listHashCode, arrayHashCode);
- }
-
- /**
- * java.util.Arrays#hashCode(long[] a)
- */
- public void test_hashCode$LJ() {
- int listHashCode;
- int arrayHashCode;
-
- long [] longArr = {67890234512l, 97587236923425l, 257421912912l,
- 6754268100l, 5};
- List listOfLong = new LinkedList();
- for (int i = 0; i < longArr.length; i++) {
- listOfLong.add(new Long(longArr[i]));
- }
- listHashCode = listOfLong.hashCode();
- arrayHashCode = Arrays.hashCode(longArr);
- assertEquals(listHashCode, arrayHashCode);
- }
-
- /**
- * java.util.Arrays#hashCode(float[] a)
- */
- public void test_hashCode$LF() {
- int listHashCode;
- int arrayHashCode;
-
- float [] floatArr = {0.13497f, 0.268934f, 12e-5f, -3e+2f, 10e-4f};
- List listOfFloat = new LinkedList();
- for (int i = 0; i < floatArr.length; i++) {
- listOfFloat.add(new Float(floatArr[i]));
- }
- listHashCode = listOfFloat.hashCode();
- arrayHashCode = Arrays.hashCode(floatArr);
- assertEquals(listHashCode, arrayHashCode);
-
- float [] floatArr2 = {0.13497f, 0.268934f, 12e-5f, -3e+2f, 10e-4f};
- assertEquals(Arrays.hashCode(floatArr2), Arrays.hashCode(floatArr));
- }
-
- /**
- * java.util.Arrays#hashCode(double[] a)
- */
- public void test_hashCode$LD() {
- int listHashCode;
- int arrayHashCode;
-
- double [] doubleArr = {0.134945657, 0.0038754, 11e-150, -30e-300, 10e-4};
- List listOfDouble = new LinkedList();
- for (int i = 0; i < doubleArr.length; i++) {
- listOfDouble.add(new Double(doubleArr[i]));
- }
- listHashCode = listOfDouble.hashCode();
- arrayHashCode = Arrays.hashCode(doubleArr);
- assertEquals(listHashCode, arrayHashCode);
- }
-
- /**
- * java.util.Arrays#hashCode(short[] a)
- */
- public void test_hashCode$LS() {
- int listHashCode;
- int arrayHashCode;
-
- short [] shortArr = {35, 13, 45, 2, 91};
- List listOfShort = new LinkedList();
- for (int i = 0; i < shortArr.length; i++) {
- listOfShort.add(new Short(shortArr[i]));
- }
- listHashCode = listOfShort.hashCode();
- arrayHashCode = Arrays.hashCode(shortArr);
- assertEquals(listHashCode, arrayHashCode);
- }
-
- /**
- * java.util.Arrays#hashCode(Object[] a)
- */
- public void test_hashCode$Ljava_lang_Object() {
- int listHashCode;
- int arrayHashCode;
-
- Object[] objectArr = {new Integer(1), new Float(10e-12f), null};
- List listOfObject= new LinkedList();
- for (int i = 0; i < objectArr.length; i++) {
- listOfObject.add(objectArr[i]);
- }
- listHashCode = listOfObject.hashCode();
- arrayHashCode = Arrays.hashCode(objectArr);
- assertEquals(listHashCode, arrayHashCode);
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- booleanArray = new boolean[arraySize];
- byteArray = new byte[arraySize];
- charArray = new char[arraySize];
- doubleArray = new double[arraySize];
- floatArray = new float[arraySize];
- intArray = new int[arraySize];
- longArray = new long[arraySize];
- objectArray = new Object[arraySize];
- shortArray = new short[arraySize];
-
- for (int counter = 0; counter < arraySize; counter++) {
- byteArray[counter] = (byte) counter;
- charArray[counter] = (char) (counter + 1);
- doubleArray[counter] = counter;
- floatArray[counter] = counter;
- intArray[counter] = counter;
- longArray[counter] = counter;
- objectArray[counter] = objArray[counter];
- shortArray[counter] = (short) counter;
- }
- for (int counter = 0; counter < arraySize; counter += 2) {
- booleanArray[counter] = false;
- booleanArray[counter + 1] = true;
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(byte[],int,int, byte)
- */
- public void test_binarySearch$BIIB() {
- for (byte counter = 0; counter < arraySize; counter++) {
- assertTrue(
- "Binary search on byte[] answered incorrect position",
- Arrays.binarySearch(byteArray, counter, arraySize, counter) == counter);
- }
- assertEquals(
- "Binary search succeeded for value not present in array 1", -1,
- Arrays.binarySearch(byteArray, 0, arraySize, (byte) -1));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(byteArray, (byte) arraySize) == -(arraySize + 1));
- for (byte counter = 0; counter < arraySize; counter++) {
- byteArray[counter] -= 50;
- }
- for (byte counter = 0; counter < arraySize; counter++) {
- assertTrue(
- "Binary search on byte[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(byteArray, counter, arraySize,
- (byte) (counter - 50)) == counter);
- }
- try {
- Arrays.binarySearch((byte[])null, 2, 1, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((byte[])null, -1, 0, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((byte[])null, -1, -2, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch(byteArray, 2, 1, (byte) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(-1, Arrays.binarySearch(byteArray, 0, 0, (byte) arraySize));
- try {
- Arrays.binarySearch(byteArray, -1, -2, (byte) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(byteArray, arraySize + 2, arraySize + 1,
- (byte) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(byteArray, -1, 0, (byte) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.binarySearch(byteArray, 0, arraySize + 1, (byte) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(char[], char)
- */
- public void test_binarySearch$CIIC() {
- for (char counter = 0; counter < arraySize; counter++) {
- assertTrue("Binary search on char[] answered incorrect position",
- Arrays.binarySearch(charArray, counter, arraySize,
- (char) (counter + 1)) == counter);
- }
- assertEquals(
- "Binary search succeeded for value not present in array 1", -1,
- Arrays.binarySearch(charArray, 0, arraySize, '\u0000'));
- assertTrue("Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(charArray, 0, arraySize,
- (char) (arraySize + 1)) == -(arraySize + 1));
- try {
- Arrays.binarySearch(charArray, 2, 1, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch((char[])null, 2, 1, (char) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((char[])null, -1, 0, (char) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((char[])null, -1, -2, (char) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- assertEquals(-1, Arrays.binarySearch(charArray, 0, 0, (char) arraySize));
- try {
- Arrays.binarySearch(charArray, -1, -2, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(charArray, arraySize + 2, arraySize + 1,
- (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(charArray, -1, 0, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.binarySearch(charArray, 0, arraySize + 1, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(double[], double)
- */
- public void test_binarySearch$DIID() {
- for (int counter = 0; counter < arraySize; counter++) {
- assertTrue("Binary search on double[] answered incorrect position",
- Arrays.binarySearch(doubleArray, counter, arraySize,
- (double) counter) == (double) counter);
- }
- assertEquals(
- "Binary search succeeded for value not present in array 1", -1,
- Arrays.binarySearch(doubleArray, 0, arraySize, (double) -1));
- assertTrue("Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(doubleArray, 0, arraySize,
- (double) arraySize) == -(arraySize + 1));
- for (int counter = 0; counter < arraySize; counter++) {
- doubleArray[counter] -= (double) 50;
- }
- for (int counter = 0; counter < arraySize; counter++) {
- assertTrue(
- "Binary search on double[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(doubleArray, counter, arraySize,(double) (counter - 50)) == (double) counter);
- }
- double[] specials = new double[] { Double.NEGATIVE_INFINITY,
- -Double.MAX_VALUE, -2d, -Double.MIN_VALUE, -0d, 0d,
- Double.MIN_VALUE, 2d, Double.MAX_VALUE,
- Double.POSITIVE_INFINITY, Double.NaN };
- for (int i = 0; i < specials.length; i++) {
- int result = Arrays.binarySearch(specials, i, specials.length,specials[i]);
- assertTrue(specials[i] + " invalid: " + result, result == i);
- }
- assertEquals("-1d", -4, Arrays.binarySearch(specials,0,specials.length, -1d));
- assertEquals("1d", -8, Arrays.binarySearch(specials,0,specials.length, 1d));
- try {
- Arrays.binarySearch((double[])null, 2, 1, (double) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((double[])null, -1, 0, (double) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((double[])null, -1, -2, (double) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch(doubleArray, 2, 1, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(-1, Arrays.binarySearch(doubleArray, 0, 0, (char) arraySize));
- try {
- Arrays.binarySearch(doubleArray, -1, -2, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(doubleArray, arraySize + 2, arraySize + 1,
- (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(doubleArray, -1, 0, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.binarySearch(doubleArray, 0, arraySize + 1, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(float[], float)
- */
- public void test_binarySearch$FIIF() {
- for (int counter = 0; counter < arraySize; counter++) {
- assertTrue("Binary search on float[] answered incorrect position",
- Arrays.binarySearch(floatArray, counter, arraySize,
- (float) counter) == (float) counter);
- }
- assertEquals(
- "Binary search succeeded for value not present in array 1", -1,
- Arrays.binarySearch(floatArray, 0, arraySize, (float) -1));
- assertTrue("Binary search succeeded for value not present in array 2",
- Arrays
- .binarySearch(floatArray, 0, arraySize,
- (float) arraySize) == -(arraySize + 1));
- for (int counter = 0; counter < arraySize; counter++) {
- floatArray[counter] -= (float) 50;
- }
- for (int counter = 0; counter < arraySize; counter++) {
- assertTrue(
- "Binary search on float[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(floatArray, 0, arraySize,
- (float) counter - 50) == (float) counter);
- }
- float[] specials = new float[] { Float.NEGATIVE_INFINITY,
- -Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
- Float.MIN_VALUE, 2f, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
- Float.NaN };
- for (int i = 0; i < specials.length; i++) {
- int result = Arrays.binarySearch(specials,i,specials.length,specials[i]);
- assertTrue(specials[i] + " invalid: " + result, result == i);
- }
- assertEquals("-1f", -4, Arrays.binarySearch(specials,0,specials.length, -1f));
- assertEquals("1f", -8, Arrays.binarySearch(specials,0,specials.length, 1f));
- try {
- Arrays.binarySearch((float[])null, 2, 1, (float) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((float[])null, -1, 0, (float) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((float[])null, -1, -2, (float) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch(floatArray, 2, 1, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(-1, Arrays.binarySearch(floatArray, 0, 0,
- (char) arraySize));
- try {
- Arrays.binarySearch(floatArray, -1, -2, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(floatArray, arraySize + 2, arraySize + 1,
- (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(floatArray, -1, 0, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays
- .binarySearch(floatArray, 0, arraySize + 1,
- (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(int[], int)
- */
- public void test_binarySearch$IIII() {
- for (int counter = 0; counter < arraySize; counter++) {
- assertTrue(
- "Binary search on int[] answered incorrect position",
- Arrays.binarySearch(intArray, counter, arraySize, counter) == counter);
- }
- assertEquals(
- "Binary search succeeded for value not present in array 1", -1,
- Arrays.binarySearch(intArray,0, arraySize, -1));
- assertTrue("Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(intArray,0, arraySize, arraySize) == -(arraySize + 1));
- for (int counter = 0; counter < arraySize; counter++) {
- intArray[counter] -= 50;
- }
- for (int counter = 0; counter < arraySize; counter++) {
- assertTrue(
- "Binary search on int[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(intArray,0, arraySize, counter - 50) == counter);
- }
- try {
- Arrays.binarySearch((int[])null, 2, 1, (int) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((int[])null, -1, 0, (int) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((int[])null, -1, -2, (int) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch(intArray, 2, 1, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(-1, Arrays
- .binarySearch(intArray, 0, 0, (char) arraySize));
- try {
- Arrays.binarySearch(intArray, -1, -2, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(intArray, arraySize + 2, arraySize + 1,
- (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(intArray, -1, 0, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.binarySearch(intArray, 0, arraySize + 1, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(long[], long)
- */
- public void test_binarySearch$JIIJ() {
- for (long counter = 0; counter < arraySize; counter++){
- assertTrue("Binary search on long[] answered incorrect position",
- Arrays.binarySearch(longArray,0,arraySize, counter) == counter);
- }
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(longArray,0,arraySize, (long) -1));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(longArray,0,arraySize, (long) arraySize) == -(arraySize + 1));
- for (long counter = 0; counter < arraySize; counter++){
- longArray[(int) counter] -= (long) 50;
- }
- for (long counter = 0; counter < arraySize; counter++){
- assertTrue(
- "Binary search on long[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(longArray,0,arraySize, counter - (long) 50) == counter);
- }
- try {
- Arrays.binarySearch((long[])null, 2, 1, (long) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((long[])null, -1, 0, (long) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((long[])null, -1, -2, (long) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch(longArray, 2, 1, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(-1, Arrays
- .binarySearch(longArray, 0, 0, (char) arraySize));
- try {
- Arrays.binarySearch(longArray, -1, -2, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(longArray, arraySize + 2, arraySize + 1,
- (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(longArray, -1, 0, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.binarySearch(longArray, 0, arraySize + 1, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(java.lang.Object[],
- * java.lang.Object)
- */
- public void test_binarySearch$Ljava_lang_ObjectIILjava_lang_Object() {
- assertEquals(
- "Binary search succeeded for non-comparable value in empty array",
- -1, Arrays.binarySearch(new Object[] {},0,0, new Object()));
- assertEquals(
- "Binary search succeeded for comparable value in empty array",
- -1, Arrays.binarySearch(new Object[] {},0,0, new Integer(-1)));
- for (int counter = 0; counter < arraySize; counter++){
- assertTrue(
- "Binary search on Object[] answered incorrect position",
- Arrays.binarySearch(objectArray,counter,arraySize, objArray[counter]) == counter);
- }
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(objectArray,0,arraySize, new Integer(-1)));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(objectArray,0,arraySize, new Integer(arraySize)) == -(arraySize + 1));
- try {
- Arrays.binarySearch((Object[])null, 2, 1, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((Object[])null, -1, 0, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((Object[])null, -1, -2, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch(objectArray, 2, 1, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(-1, Arrays
- .binarySearch(objectArray, 0, 0, (char) arraySize));
- try {
- Arrays.binarySearch(objectArray, -1, -2, (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(objectArray, arraySize + 2, arraySize + 1,
- (char) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(objectArray, -1, 0, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.binarySearch(objectArray, 0, arraySize + 1, (char) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(java.lang.Object[],
- * java.lang.Object, java.util.Comparator)
- */
- public void test_binarySearch$Ljava_lang_ObjectIILjava_lang_ObjectLjava_util_Comparator() {
- Comparator comp = new ReversedIntegerComparator();
- for (int counter = 0; counter < arraySize; counter++) {
- objectArray[counter] = objArray[arraySize - counter - 1];
- }
- assertTrue("Binary search succeeded for value not present in array 1",
- Arrays.binarySearch(objectArray, 0, arraySize, new Integer(-1),
- comp) == -(arraySize + 1));
- assertEquals(
- "Binary search succeeded for value not present in array 2", -1,
- Arrays.binarySearch(objectArray, 0, arraySize, new Integer(
- arraySize), comp));
- for (int counter = 0; counter < arraySize; counter++) {
- assertTrue(
- "Binary search on Object[] with custom comparator answered incorrect position",
- Arrays.binarySearch(objectArray, objArray[counter], comp) == arraySize
- - counter - 1);
- }
- try {
- Arrays.binarySearch((Object[])null, 2, 1, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((Object[])null, -1, 0, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((Object[])null, -1, -2, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch(objectArray, 2, 1, (char) arraySize, comp);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(-1, Arrays.binarySearch(objectArray, 0, 0,
- (char) arraySize, comp));
- try {
- Arrays.binarySearch(objectArray, -1, -2, (char) arraySize, comp);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(objectArray, arraySize + 2, arraySize + 1,
- (char) arraySize, comp);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(objectArray, -1, 0, (char) arraySize, comp);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.binarySearch(objectArray, 0, arraySize + 1,
- (char) arraySize, comp);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.binarySearch(objectArray, 0, arraySize ,
- new LinkedList(), comp);
- fail("should throw ClassCastException");
- } catch (ClassCastException e) {
- // expected
- }
- }
-
- /**
- * java.util.Arrays#binarySearch(short[], short)
- */
- public void test_binarySearch$SIIS() {
- for (short counter = 0; counter < arraySize; counter++){
- assertTrue("Binary search on short[] answered incorrect position",
- Arrays.binarySearch(shortArray,counter,arraySize, counter) == counter);
- }
- assertEquals("Binary search succeeded for value not present in array 1",
- -1, Arrays.binarySearch(shortArray,0,arraySize, (short) -1));
- assertTrue(
- "Binary search succeeded for value not present in array 2",
- Arrays.binarySearch(shortArray,0,arraySize, (short) arraySize) == -(arraySize + 1));
- for (short counter = 0; counter < arraySize; counter++){
- shortArray[counter] -= 50;
- }
- for (short counter = 0; counter < arraySize; counter++){
- assertTrue(
- "Binary search on short[] involving negative numbers answered incorrect position",
- Arrays.binarySearch(shortArray,counter,arraySize, (short) (counter - 50)) == counter);
- }
- try {
- Arrays.binarySearch((String[])null, 2, 1, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((String[])null, -1, 0, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch((String[])null, -1, -2, (byte) arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.binarySearch(shortArray, 2, 1, (short) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(-1, Arrays
- .binarySearch(shortArray, 0, 0, (short) arraySize));
- try {
- Arrays.binarySearch(shortArray, -1, -2, (short) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(shortArray, arraySize + 2, arraySize + 1,
- (short) arraySize);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.binarySearch(shortArray, -1, 0, (short) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.binarySearch(shortArray, 0, arraySize + 1, (short) arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- String[] array = {"a" , "b" , "c"};
- assertEquals(-2,Arrays.binarySearch(array, 1, 2, "a", null));
- }
-
- /**
- * {@link java.util.Arrays#copyOf(byte[],int)
- */
- public void test_copyOf_$BI() throws Exception {
- byte[] result = Arrays.copyOf(byteArray, arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(i, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOf(byteArray, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(i, result[i]);
- }
- try {
- Arrays.copyOf((byte[])null, arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(byteArray, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((byte[])null, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- }
-
- /**
- * {@link java.util.Arrays#copyOf(short[],int)
- */
- public void test_copyOf_$SI() throws Exception {
- short[] result = Arrays.copyOf(shortArray, arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(i, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOf(shortArray, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(i, result[i]);
- }
- try {
- Arrays.copyOf((short[])null, arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(shortArray, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((short[])null, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- }
-
- /**
- * {@link java.util.Arrays#copyOf(int[],int)
- */
- public void test_copyOf_$II() throws Exception {
- int[] result = Arrays.copyOf(intArray, arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(i, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOf(intArray, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(i, result[i]);
- }
- try {
- Arrays.copyOf((int[])null, arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(intArray, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((int[])null, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- }
-
- /**
- * {@link java.util.Arrays#copyOf(boolean[],int)
- */
- public void test_copyOf_$ZI() throws Exception {
- boolean[] result = Arrays.copyOf(booleanArray, arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(booleanArray[i], result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(false, result[i]);
- }
- result = Arrays.copyOf(booleanArray, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(booleanArray[i], result[i]);
- }
- try {
- Arrays.copyOf((boolean[])null, arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(booleanArray, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((boolean[])null, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- }
-
- /**
- * {@link java.util.Arrays#copyOf(char[],int)
- */
- public void test_copyOf_$CI() throws Exception {
- char[] result = Arrays.copyOf(charArray, arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(i+1, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOf(charArray, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(i+1, result[i]);
- }
- try {
- Arrays.copyOf((char[])null, arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(charArray, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((char[])null, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- }
-
- /**
- * {@link java.util.Arrays#copyOf(float[],int)
- */
- public void test_copyOf_$FI() throws Exception {
- float[] result = Arrays.copyOf(floatArray, arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(floatArray[i], result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0.0f, result[i]);
- }
- result = Arrays.copyOf(floatArray, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(floatArray[i], result[i]);
- }
- try {
- Arrays.copyOf((float[])null, arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(floatArray, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((float[])null, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- }
-
- /**
- * {@link java.util.Arrays#copyOf(double[],int)
- */
- public void test_copyOf_$DI() throws Exception {
- double[] result = Arrays.copyOf(doubleArray, arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(doubleArray[i], result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0.0, result[i]);
- }
- result = Arrays.copyOf(doubleArray, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(doubleArray[i], result[i]);
- }
- try {
- Arrays.copyOf((double[])null, arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(doubleArray, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((double[])null, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- }
-
- /**
- * {@link java.util.Arrays#copyOf(long[],int)
- */
- public void test_copyOf_$JI() throws Exception {
- long[] result = Arrays.copyOf(longArray, arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(longArray[i], result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOf(longArray, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(longArray[i], result[i]);
- }
- try {
- Arrays.copyOf((long[])null, arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(longArray, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((long[])null, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- }
-
- /**
- * {@link java.util.Arrays#copyOf(T[],int)
- */
- public void test_copyOf_$TI() throws Exception {
- Object[] result = Arrays.copyOf(objArray, arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(objArray[i], result[i]);
- }
- for (; i < result.length; i++) {
- assertNull(result[i]);
- }
- result = Arrays.copyOf(objArray, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(objArray[i], result[i]);
- }
- try {
- Arrays.copyOf((String[])null, arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(objArray, -1);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((String[])null, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- Date[] component = new Date[0];
- Object object[] = new Date[0];
-
- object = Arrays.copyOf(component,2);
- assertNotNull(object);
- component = Arrays.copyOf(component,2);
- assertNotNull(component);
- assertEquals(2, component.length);
- }
-
- /**
- * {@link java.util.Arrays#copyOf(T[],int,Class<? extends Object[]>))
- */
- public void test_copyOf_$TILClass() throws Exception {
- Object[] result = Arrays.copyOf(objArray, arraySize*2,Object[].class);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(objArray[i], result[i]);
- }
- for (; i < result.length; i++) {
- assertNull(result[i]);
- }
- result = Arrays.copyOf(objArray, arraySize/2,Object[].class);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(objArray[i], result[i]);
- }
- result = Arrays.copyOf(objArray, arraySize/2,Integer[].class);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(objArray[i], result[i]);
- }
- try {
- Arrays.copyOf((Object[])null, arraySize,LinkedList[].class);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(objArray, arraySize,LinkedList[].class);
- fail("should throw ArrayStoreException ");
- } catch (ArrayStoreException e) {
- // expected
- }
- try {
- Arrays.copyOf((Object[])null, arraySize,Object[].class);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOf(objArray, -1,Object[].class);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((Object[])null, -1,Object[].class);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((Object[])null, -1,LinkedList[].class);
- fail("should throw NegativeArraySizeException");
- } catch (NegativeArraySizeException e) {
- // expected
- }
- try {
- Arrays.copyOf((Object[])null, 0,LinkedList[].class);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- assertEquals(0,Arrays.copyOf(objArray, 0,LinkedList[].class).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(byte[],int,int)
- */
- public void test_copyOfRange_$BII() throws Exception {
- byte[] result = Arrays.copyOfRange(byteArray, 0,arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(i, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOfRange(byteArray,0, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(i, result[i]);
- }
- result = Arrays.copyOfRange(byteArray,0, 0);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange((byte[])null, 0,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((byte[])null, -1,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((byte[])null, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(byteArray, -1,arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(byteArray, 0, -1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(byteArray.length + 1, Arrays.copyOfRange(byteArray, 0,
- byteArray.length + 1).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(short[],int,int)
- */
- public void test_copyOfRange_$SII() throws Exception {
- short[] result = Arrays.copyOfRange(shortArray, 0,arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(i, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOfRange(shortArray,0, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(i, result[i]);
- }
- result = Arrays.copyOfRange(shortArray,0, 0);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange((short[])null, 0,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((short[])null, -1,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((short[])null, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(shortArray, -1,arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(shortArray, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(shortArray.length + 1, Arrays.copyOfRange(shortArray, 0,
- shortArray.length + 1).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(int[],int,int)
- */
- public void test_copyOfRange_$III() throws Exception {
- int[] result = Arrays.copyOfRange(intArray, 0,arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(i, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOfRange(intArray,0, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(i, result[i]);
- }
- result = Arrays.copyOfRange(intArray,0, 0);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange((int[])null, 0,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((int[])null, -1,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((int[])null, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(intArray, -1,arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(intArray, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(intArray.length + 1, Arrays.copyOfRange(intArray, 0,
- intArray.length + 1).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(long[],int,int)
- */
- public void test_copyOfRange_$JII() throws Exception {
- long[] result = Arrays.copyOfRange(longArray, 0,arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(i, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOfRange(longArray,0, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(i, result[i]);
- }
- result = Arrays.copyOfRange(longArray,0, 0);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange((long[])null, 0,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((long[])null, -1,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((long[])null, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(longArray, -1,arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(longArray, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(longArray.length + 1, Arrays.copyOfRange(longArray, 0,
- longArray.length + 1).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(char[],int,int)
- */
- public void test_copyOfRange_$CII() throws Exception {
- char[] result = Arrays.copyOfRange(charArray, 0,arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(i+1, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0, result[i]);
- }
- result = Arrays.copyOfRange(charArray,0, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(i+1, result[i]);
- }
- result = Arrays.copyOfRange(charArray,0, 0);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange((char[])null, 0,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((char[])null, -1,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((char[])null, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(charArray, -1,arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(charArray, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(charArray.length + 1, Arrays.copyOfRange(charArray, 0,
- charArray.length + 1).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(float[],int,int)
- */
- public void test_copyOfRange_$FII() throws Exception {
- float[] result = Arrays.copyOfRange(floatArray, 0,arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals((float)i, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0.0f, result[i]);
- }
- result = Arrays.copyOfRange(floatArray,0, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals((float)i, result[i]);
- }
- result = Arrays.copyOfRange(floatArray,0, 0);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange((float[])null, 0,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((float[])null, -1,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((float[])null, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(floatArray, -1,arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(floatArray, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(floatArray.length + 1, Arrays.copyOfRange(floatArray, 0,
- floatArray.length + 1).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(double[],int,int)
- */
- public void test_copyOfRange_$DII() throws Exception {
- double[] result = Arrays.copyOfRange(doubleArray, 0,arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals((double)i, result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(0.0, result[i]);
- }
- result = Arrays.copyOfRange(doubleArray,0, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals((double)i, result[i]);
- }
- result = Arrays.copyOfRange(doubleArray,0, 0);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange((double[])null, 0,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((double[])null, -1,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((double[])null, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(doubleArray, -1,arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(doubleArray, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(doubleArray.length + 1, Arrays.copyOfRange(doubleArray, 0,
- doubleArray.length + 1).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(boolean[],int,int)
- */
- public void test_copyOfRange_$ZII() throws Exception {
- boolean[] result = Arrays.copyOfRange(booleanArray, 0,arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(booleanArray[i], result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(false, result[i]);
- }
- result = Arrays.copyOfRange(booleanArray,0, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(booleanArray[i], result[i]);
- }
- result = Arrays.copyOfRange(booleanArray,0, 0);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange((boolean[])null, 0,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((boolean[])null, -1,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((boolean[])null, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(booleanArray, -1,arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(booleanArray, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(booleanArray.length + 1, Arrays.copyOfRange(booleanArray, 0,
- booleanArray.length + 1).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(Object[],int,int)
- */
- public void test_copyOfRange_$TII() throws Exception {
- Object[] result = Arrays.copyOfRange(objArray, 0,arraySize*2);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(objArray[i], result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(null, result[i]);
- }
- result = Arrays.copyOfRange(objArray,0, arraySize/2);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(objArray[i], result[i]);
- }
- result = Arrays.copyOfRange(objArray,0, 0);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange((Object[])null, 0,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((Object[])null, -1,arraySize);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((Object[])null, 0,-1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((Object[])objArray, -1,arraySize);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange((Object[])objArray, 0,-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(objArray.length + 1, Arrays.copyOfRange(objArray, 0,
- objArray.length + 1).length);
- }
-
- /**
- * {@link java.util.Arrays#copyOfRange(Object[], int, int, Class)
- */
- public void test_copyOfRange_$TIILClass() throws Exception {
- Object[] result = Arrays.copyOfRange(objArray, 0,arraySize*2,Integer[].class);
- int i = 0;
- for (; i < arraySize; i++) {
- assertEquals(objArray[i], result[i]);
- }
- for (; i < result.length; i++) {
- assertEquals(null, result[i]);
- }
- result = Arrays.copyOfRange(objArray,0, arraySize/2,Integer[].class);
- i = 0;
- for (; i < result.length; i++) {
- assertEquals(objArray[i], result[i]);
- }
- result = Arrays.copyOfRange(objArray,0, 0,Integer[].class);
- assertEquals(0, result.length);
- try {
- Arrays.copyOfRange(null, 0,arraySize,Integer[].class);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(null, -1,arraySize,Integer[].class);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(null, 0,-1,Integer[].class);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(objArray, -1,arraySize,Integer[].class);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(objArray, 0,-1,Integer[].class);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(objArray, 0,-1,LinkedList[].class);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(objArray, 0,1,LinkedList[].class);
- fail("should throw ArrayStoreException");
- } catch (ArrayStoreException e) {
- // expected
- }
- try {
- Arrays.copyOfRange(null, 0,1,LinkedList[].class);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- assertEquals(objArray.length + 1, Arrays.copyOfRange(objArray, 0,
- objArray.length + 1, LinkedList[].class).length);
- fail("should throw ArrayStoreException");
- } catch (ArrayStoreException e) {
- // expected
- }
- assertEquals(0,
- Arrays.copyOfRange(objArray, 0, 0, LinkedList[].class).length);
- }
-
- /**
- * java.util.Arrays#swap(int, int, Object[])
- */
- /* BEGIN android-removed: tests private implementation detail we don't share.
- public void test_swap_I_I_$Ljava_lang_Object() throws Exception {
- Method m = Arrays.class.getDeclaredMethod("swap", int.class, int.class, Object[].class);
- m.setAccessible(true);
- Integer[] arr = {new Integer(0), new Integer(1), new Integer(2)};
- m.invoke(null,0, 1, arr);
- assertEquals("should be equal to 1",1, arr[0].intValue());
- assertEquals("should be equal to 0",0, arr[1].intValue());
- }
- */
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/DictionaryTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/DictionaryTest.java
deleted file mode 100644
index 2aaab58..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/DictionaryTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import junit.framework.TestCase;
-
-import java.util.Date;
-import java.util.Dictionary;
-import java.util.Enumeration;
-
-public class DictionaryTest extends TestCase {
-
- class Mock_Dictionary extends Dictionary {
-
- @Override
- public Enumeration elements() {
- return null;
- }
-
- @Override
- public Object get(Object arg0) {
- return null;
- }
-
- @Override
- public boolean isEmpty() {
- return false;
- }
-
- @Override
- public Enumeration keys() {
- return null;
- }
-
- @Override
- public Object put(Object arg0, Object arg1) {
- return null;
- }
-
- @Override
- public Object remove(Object arg0) {
- return null;
- }
-
- @Override
- public int size() {
- return 0;
- }
- }
-
- public void testDictionary() {
- Dictionary md = new Mock_Dictionary();
- assertNotNull(md);
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/DuplicateFormatFlagsExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/DuplicateFormatFlagsExceptionTest.java
deleted file mode 100644
index 1c4df4f..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/DuplicateFormatFlagsExceptionTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.DuplicateFormatFlagsException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class DuplicateFormatFlagsExceptionTest extends TestCase {
-
- /**
- * java.util.DuplicateFormatFlagsException#DuplicateFormatFlagsException(String)
- */
- public void test_duplicateFormatFlagsException() {
- try {
- new DuplicateFormatFlagsException(null);
- fail("should throw NullPointerException.");
- } catch (NullPointerException e) {
- // desired
- }
- }
-
- /**
- * java.util.DuplicateFormatFlagsException#getFlags()
- */
- public void test_getFlags() {
- String strFlags = "MYTESTFLAGS";
- DuplicateFormatFlagsException duplicateFormatException = new DuplicateFormatFlagsException(
- strFlags);
- assertEquals(strFlags, duplicateFormatException.getFlags());
- }
-
- /**
- * java.util.DuplicateFormatFlagsException#getMessage()
- */
- public void test_getMessage() {
- String strFlags = "MYTESTFLAGS";
- DuplicateFormatFlagsException duplicateFormatException = new DuplicateFormatFlagsException(
- strFlags);
- assertTrue(null != duplicateFormatException.getFlags());
-
- }
-
- // comparator for DuplicateFormatFlagsException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- DuplicateFormatFlagsException initEx = (DuplicateFormatFlagsException) initial;
- DuplicateFormatFlagsException desrEx = (DuplicateFormatFlagsException) deserialized;
-
- assertEquals("Flags", initEx.getFlags(), desrEx.getFlags());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new DuplicateFormatFlagsException(
- "TESTDESC"), exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new DuplicateFormatFlagsException(
- "TESTDESC"), exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormatFlagsConversionMismatchExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormatFlagsConversionMismatchExceptionTest.java
deleted file mode 100644
index fd2a545..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormatFlagsConversionMismatchExceptionTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.FormatFlagsConversionMismatchException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class FormatFlagsConversionMismatchExceptionTest extends TestCase {
-
- /**
- * java.util.FormatFlagsConversionMismatchException#FormatFlagsConversionMismatchException(String,
- * char)
- */
- public void test_formatFlagsConversionMismatchException() {
- try {
- new FormatFlagsConversionMismatchException(null, ' ');
- fail("should throw NullPointerException.");
- } catch (NullPointerException e) {
- // expected
- }
-
- }
-
- /**
- * java.util.FormatFlagsConversionMismatchException#getFlags()
- */
- public void test_getFlags() {
- String flags = "MYTESTFLAGS";
- char conversion = 'T';
- FormatFlagsConversionMismatchException formatFlagsConversionMismatchException = new FormatFlagsConversionMismatchException(
- flags, conversion);
- assertEquals(flags, formatFlagsConversionMismatchException.getFlags());
- }
-
- /**
- * java.util.FormatFlagsConversionMismatchException#getConversion()
- */
- public void test_getConversion() {
- String flags = "MYTESTFLAGS";
- char conversion = 'T';
- FormatFlagsConversionMismatchException formatFlagsConversionMismatchException = new FormatFlagsConversionMismatchException(
- flags, conversion);
- assertEquals(conversion, formatFlagsConversionMismatchException
- .getConversion());
-
- }
-
- /**
- * java.util.FormatFlagsConversionMismatchException#getMessage()
- */
- public void test_getMessage() {
- String flags = "MYTESTFLAGS";
- char conversion = 'T';
- FormatFlagsConversionMismatchException formatFlagsConversionMismatchException = new FormatFlagsConversionMismatchException(
- flags, conversion);
- assertTrue(null != formatFlagsConversionMismatchException.getMessage());
-
- }
-
- // comparator for FormatFlagsConversionMismatchException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- FormatFlagsConversionMismatchException initEx = (FormatFlagsConversionMismatchException) initial;
- FormatFlagsConversionMismatchException desrEx = (FormatFlagsConversionMismatchException) deserialized;
-
- assertEquals("Flags", initEx.getFlags(), desrEx.getFlags());
- assertEquals("Conversion", initEx.getConversion(), desrEx
- .getConversion());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(
- new FormatFlagsConversionMismatchException("MYTESTFLAGS", 'T'),
- exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- new FormatFlagsConversionMismatchException("MYTESTFLAGS", 'T'),
- exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormatterClosedExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormatterClosedExceptionTest.java
deleted file mode 100644
index 273aee8..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/FormatterClosedExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.util.FormatterClosedException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-public class FormatterClosedExceptionTest extends TestCase {
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new FormatterClosedException());
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new FormatterClosedException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java
deleted file mode 100644
index aca5bac..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/HashMapTest.java
+++ /dev/null
@@ -1,773 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.AbstractMap;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-import tests.support.Support_MapTest2;
-import tests.support.Support_UnmodifiableCollectionTest;
-
-public class HashMapTest extends junit.framework.TestCase {
- class MockMap extends AbstractMap {
- public Set entrySet() {
- return null;
- }
- public int size(){
- return 0;
- }
- }
-
- private static class MockMapNull extends AbstractMap {
- public Set entrySet() {
- return null;
- }
-
- public int size() {
- return 10;
- }
- }
-
- interface MockInterface {
- public String mockMethod();
- }
-
- class MockClass implements MockInterface {
- public String mockMethod() {
- return "This is a MockClass";
- }
- }
-
- class MockHandler implements InvocationHandler {
-
- Object obj;
-
- public MockHandler(Object o) {
- obj = o;
- }
-
- public Object invoke(Object proxy, Method m, Object[] args)
- throws Throwable {
-
- Object result = null;
-
- try {
-
- result = m.invoke(obj, args);
-
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
-
- }
- return result;
- }
-
- }
-
-
- HashMap hm;
-
- final static int hmSize = 1000;
-
- static Object[] objArray;
-
- static Object[] objArray2;
- {
- objArray = new Object[hmSize];
- objArray2 = new Object[hmSize];
- for (int i = 0; i < objArray.length; i++) {
- objArray[i] = new Integer(i);
- objArray2[i] = objArray[i].toString();
- }
- }
-
- /**
- * java.util.HashMap#HashMap()
- */
- public void test_Constructor() {
- // Test for method java.util.HashMap()
- new Support_MapTest2(new HashMap()).runTest();
-
- HashMap hm2 = new HashMap();
- assertEquals("Created incorrect HashMap", 0, hm2.size());
- }
-
- /**
- * java.util.HashMap#HashMap(int)
- */
- public void test_ConstructorI() {
- // Test for method java.util.HashMap(int)
- HashMap hm2 = new HashMap(5);
- assertEquals("Created incorrect HashMap", 0, hm2.size());
- try {
- new HashMap(-1);
- } catch (IllegalArgumentException e) {
- return;
- }
- fail(
- "Failed to throw IllegalArgumentException for initial capacity < 0");
-
- HashMap empty = new HashMap(0);
- assertNull("Empty hashmap access", empty.get("nothing"));
- empty.put("something", "here");
- assertTrue("cannot get element", empty.get("something") == "here");
- }
-
- /**
- * java.util.HashMap#HashMap(int, float)
- */
- public void test_ConstructorIF() {
- // Test for method java.util.HashMap(int, float)
- HashMap hm2 = new HashMap(5, (float) 0.5);
- assertEquals("Created incorrect HashMap", 0, hm2.size());
- try {
- new HashMap(0, 0);
- } catch (IllegalArgumentException e) {
- return;
- }
- fail(
- "Failed to throw IllegalArgumentException for initial load factor <= 0");
-
- HashMap empty = new HashMap(0, 0.75f);
- assertNull("Empty hashtable access", empty.get("nothing"));
- empty.put("something", "here");
- assertTrue("cannot get element", empty.get("something") == "here");
- }
-
- /**
- * java.util.HashMap#HashMap(java.util.Map)
- */
- public void test_ConstructorLjava_util_Map() {
- // Test for method java.util.HashMap(java.util.Map)
- Map myMap = new TreeMap();
- for (int counter = 0; counter < hmSize; counter++)
- myMap.put(objArray2[counter], objArray[counter]);
- HashMap hm2 = new HashMap(myMap);
- for (int counter = 0; counter < hmSize; counter++)
- assertTrue("Failed to construct correct HashMap", hm
- .get(objArray2[counter]) == hm2.get(objArray2[counter]));
-
- try {
- Map mockMap = new MockMap();
- hm = new HashMap(mockMap);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- //empty
- }
-
- HashMap map = new HashMap();
- map.put("a", "a");
- SubMap map2 = new SubMap(map);
- assertTrue(map2.containsKey("a"));
- assertTrue(map2.containsValue("a"));
- }
-
- /**
- * java.util.HashMap#clear()
- */
- public void test_clear() {
- hm.clear();
- assertEquals("Clear failed to reset size", 0, hm.size());
- for (int i = 0; i < hmSize; i++)
- assertNull("Failed to clear all elements",
- hm.get(objArray2[i]));
-
- // Check clear on a large loaded map of Integer keys
- HashMap<Integer, String> map = new HashMap<Integer, String>();
- for (int i = -32767; i < 32768; i++) {
- map.put(i, "foobar");
- }
- map.clear();
- assertEquals("Failed to reset size on large integer map", 0, hm.size());
- for (int i = -32767; i < 32768; i++) {
- assertNull("Failed to clear integer map values", map.get(i));
- }
- }
-
- /**
- * java.util.HashMap#clone()
- */
- public void test_clone() {
- // Test for method java.lang.Object java.util.HashMap.clone()
- HashMap hm2 = (HashMap) hm.clone();
- assertTrue("Clone answered equivalent HashMap", hm2 != hm);
- for (int counter = 0; counter < hmSize; counter++)
- assertTrue("Clone answered unequal HashMap", hm
- .get(objArray2[counter]) == hm2.get(objArray2[counter]));
-
- HashMap map = new HashMap();
- map.put("key", "value");
- // get the keySet() and values() on the original Map
- Set keys = map.keySet();
- Collection values = map.values();
- assertEquals("values() does not work",
- "value", values.iterator().next());
- assertEquals("keySet() does not work",
- "key", keys.iterator().next());
- AbstractMap map2 = (AbstractMap) map.clone();
- map2.put("key", "value2");
- Collection values2 = map2.values();
- assertTrue("values() is identical", values2 != values);
- // values() and keySet() on the cloned() map should be different
- assertEquals("values() was not cloned",
- "value2", values2.iterator().next());
- map2.clear();
- map2.put("key2", "value3");
- Set key2 = map2.keySet();
- assertTrue("keySet() is identical", key2 != keys);
- assertEquals("keySet() was not cloned",
- "key2", key2.iterator().next());
-
- // regresion test for HARMONY-4603
- HashMap hashmap = new HashMap();
- MockClonable mock = new MockClonable(1);
- hashmap.put(1, mock);
- assertEquals(1, ((MockClonable) hashmap.get(1)).i);
- HashMap hm3 = (HashMap)hashmap.clone();
- assertEquals(1, ((MockClonable) hm3.get(1)).i);
- mock.i = 0;
- assertEquals(0, ((MockClonable) hashmap.get(1)).i);
- assertEquals(0, ((MockClonable) hm3.get(1)).i);
- }
-
- /**
- * java.util.HashMap#containsKey(java.lang.Object)
- */
- public void test_containsKeyLjava_lang_Object() {
- // Test for method boolean
- // java.util.HashMap.containsKey(java.lang.Object)
- assertTrue("Returned false for valid key", hm.containsKey(new Integer(
- 876).toString()));
- assertTrue("Returned true for invalid key", !hm.containsKey("KKDKDKD"));
-
- HashMap m = new HashMap();
- m.put(null, "test");
- assertTrue("Failed with null key", m.containsKey(null));
- assertTrue("Failed with missing key matching null hash", !m
- .containsKey(new Integer(0)));
- }
-
- /**
- * java.util.HashMap#containsValue(java.lang.Object)
- */
- public void test_containsValueLjava_lang_Object() {
- // Test for method boolean
- // java.util.HashMap.containsValue(java.lang.Object)
- assertTrue("Returned false for valid value", hm
- .containsValue(new Integer(875)));
- assertTrue("Returned true for invalid valie", !hm
- .containsValue(new Integer(-9)));
- }
-
- /**
- * java.util.HashMap#entrySet()
- */
- public void test_entrySet() {
- // Test for method java.util.Set java.util.HashMap.entrySet()
- Set s = hm.entrySet();
- Iterator i = s.iterator();
- assertTrue("Returned set of incorrect size", hm.size() == s.size());
- while (i.hasNext()) {
- Map.Entry m = (Map.Entry) i.next();
- assertTrue("Returned incorrect entry set", hm.containsKey(m
- .getKey())
- && hm.containsValue(m.getValue()));
- }
-
- Iterator iter = s.iterator();
- s.remove(iter.next());
- assertEquals(1001, s.size());
- }
-
- /**
- * java.util.HashMap#get(java.lang.Object)
- */
- public void test_getLjava_lang_Object() {
- // Test for method java.lang.Object
- // java.util.HashMap.get(java.lang.Object)
- assertNull("Get returned non-null for non existent key",
- hm.get("T"));
- hm.put("T", "HELLO");
- assertEquals("Get returned incorrect value for existing key", "HELLO", hm.get("T")
- );
-
- HashMap m = new HashMap();
- m.put(null, "test");
- assertEquals("Failed with null key", "test", m.get(null));
- assertNull("Failed with missing key matching null hash", m
- .get(new Integer(0)));
-
- // Regression for HARMONY-206
- ReusableKey k = new ReusableKey();
- HashMap map = new HashMap();
- k.setKey(1);
- map.put(k, "value1");
-
- k.setKey(18);
- assertNull(map.get(k));
-
- k.setKey(17);
- assertNull(map.get(k));
- }
-
- /**
- * Tests for proxy object keys and values
- */
- public void test_proxies() {
- // Regression for HARMONY-6237
- MockInterface proxyKey = (MockInterface) Proxy.newProxyInstance(
- MockInterface.class.getClassLoader(),
- new Class[] { MockInterface.class }, new MockHandler(
- new MockClass()));
- MockInterface proxyValue = (MockInterface) Proxy.newProxyInstance(
- MockInterface.class.getClassLoader(),
- new Class[] { MockInterface.class }, new MockHandler(
- new MockClass()));
-
- // Proxy key
- Object val = new Object();
- hm.put(proxyKey, val);
-
- assertEquals("Failed with proxy object key", val, hm
- .get(proxyKey));
- assertTrue("Failed to find proxy key", hm.containsKey(proxyKey));
- assertEquals("Failed to remove proxy object key", val,
- hm.remove(proxyKey));
- assertFalse("Should not have found proxy key", hm.containsKey(proxyKey));
-
- // Proxy value
- Object k = new Object();
- hm.put(k, proxyValue);
-
- assertTrue("Failed to find proxy object as value", hm.containsValue(proxyValue));
-
- // Proxy key and value
- HashMap map = new HashMap();
- map.put(proxyKey, proxyValue);
- assertTrue("Failed to find proxy key", map.containsKey(proxyKey));
- assertEquals(1, map.size());
- Object[] entries = map.entrySet().toArray();
- Map.Entry entry = (Map.Entry)entries[0];
- assertTrue("Failed to find proxy association", map.entrySet().contains(entry));
- }
-
- /**
- * java.util.HashMap#isEmpty()
- */
- public void test_isEmpty() {
- // Test for method boolean java.util.HashMap.isEmpty()
- assertTrue("Returned false for new map", new HashMap().isEmpty());
- assertTrue("Returned true for non-empty", !hm.isEmpty());
- }
-
- /**
- * java.util.HashMap#keySet()
- */
- public void test_keySet() {
- // Test for method java.util.Set java.util.HashMap.keySet()
- Set s = hm.keySet();
- assertTrue("Returned set of incorrect size()", s.size() == hm.size());
- for (int i = 0; i < objArray.length; i++)
- assertTrue("Returned set does not contain all keys", s
- .contains(objArray[i].toString()));
-
- HashMap m = new HashMap();
- m.put(null, "test");
- assertTrue("Failed with null key", m.keySet().contains(null));
- assertNull("Failed with null key", m.keySet().iterator().next());
-
- Map map = new HashMap(101);
- map.put(new Integer(1), "1");
- map.put(new Integer(102), "102");
- map.put(new Integer(203), "203");
- Iterator it = map.keySet().iterator();
- Integer remove1 = (Integer) it.next();
- it.hasNext();
- it.remove();
- Integer remove2 = (Integer) it.next();
- it.remove();
- ArrayList list = new ArrayList(Arrays.asList(new Integer[] {
- new Integer(1), new Integer(102), new Integer(203) }));
- list.remove(remove1);
- list.remove(remove2);
- assertTrue("Wrong result", it.next().equals(list.get(0)));
- assertEquals("Wrong size", 1, map.size());
- assertTrue("Wrong contents", map.keySet().iterator().next().equals(
- list.get(0)));
-
- Map map2 = new HashMap(101);
- map2.put(new Integer(1), "1");
- map2.put(new Integer(4), "4");
- Iterator it2 = map2.keySet().iterator();
- Integer remove3 = (Integer) it2.next();
- Integer next;
- if (remove3.intValue() == 1)
- next = new Integer(4);
- else
- next = new Integer(1);
- it2.hasNext();
- it2.remove();
- assertTrue("Wrong result 2", it2.next().equals(next));
- assertEquals("Wrong size 2", 1, map2.size());
- assertTrue("Wrong contents 2", map2.keySet().iterator().next().equals(
- next));
- }
-
- /**
- * java.util.HashMap#put(java.lang.Object, java.lang.Object)
- */
- public void test_putLjava_lang_ObjectLjava_lang_Object() {
- hm.put("KEY", "VALUE");
- assertEquals("Failed to install key/value pair", "VALUE", hm.get("KEY"));
-
- HashMap<Object,Object> m = new HashMap<Object,Object>();
- m.put(new Short((short) 0), "short");
- m.put(null, "test");
- m.put(new Integer(0), "int");
- assertEquals("Failed adding to bucket containing null", "short", m
- .get(new Short((short) 0)));
- assertEquals("Failed adding to bucket containing null2", "int", m
- .get(new Integer(0)));
-
- // Check my actual key instance is returned
- HashMap<Integer, String> map = new HashMap<Integer, String>();
- for (int i = -32767; i < 32768; i++) {
- map.put(i, "foobar");
- }
- Integer myKey = new Integer(0);
- // Put a new value at the old key position
- map.put(myKey, "myValue");
- assertTrue(map.containsKey(myKey));
- assertEquals("myValue", map.get(myKey));
- boolean found = false;
- for (Iterator<Integer> itr = map.keySet().iterator(); itr.hasNext();) {
- Integer key = itr.next();
- if (found = key == myKey) {
- break;
- }
- }
- assertFalse("Should not find new key instance in hashmap", found);
-
- // Add a new key instance and check it is returned
- assertNotNull(map.remove(myKey));
- map.put(myKey, "myValue");
- assertTrue(map.containsKey(myKey));
- assertEquals("myValue", map.get(myKey));
- for (Iterator<Integer> itr = map.keySet().iterator(); itr.hasNext();) {
- Integer key = itr.next();
- if (found = key == myKey) {
- break;
- }
- }
- assertTrue("Did not find new key instance in hashmap", found);
-
- // Ensure keys with identical hashcode are stored separately
- HashMap<Object,Object> objmap = new HashMap<Object, Object>();
- for (int i = 0; i < 32768; i++) {
- objmap.put(i, "foobar");
- }
- // Put non-equal object with same hashcode
- MyKey aKey = new MyKey();
- assertNull(objmap.put(aKey, "value"));
- assertNull(objmap.remove(new MyKey()));
- assertEquals("foobar", objmap.get(0));
- assertEquals("value", objmap.get(aKey));
- }
-
- static class MyKey {
- public MyKey() {
- super();
- }
-
- public int hashCode() {
- return 0;
- }
- }
- /**
- * java.util.HashMap#putAll(java.util.Map)
- */
- public void test_putAllLjava_util_Map() {
- // Test for method void java.util.HashMap.putAll(java.util.Map)
- HashMap hm2 = new HashMap();
- hm2.putAll(hm);
- for (int i = 0; i < 1000; i++)
- assertTrue("Failed to clear all elements", hm2.get(
- new Integer(i).toString()).equals((new Integer(i))));
-
- Map mockMap = new MockMap();
- hm2 = new HashMap();
- hm2.putAll(mockMap);
- assertEquals("Size should be 0", 0, hm2.size());
- }
-
- /**
- * java.util.HashMap#putAll(java.util.Map)
- */
- public void test_putAllLjava_util_Map_Null() {
- HashMap hashMap = new HashMap();
- try {
- hashMap.putAll(new MockMapNull());
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected.
- }
-
- try {
- hashMap = new HashMap(new MockMapNull());
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected.
- }
- }
-
- /**
- * java.util.HashMap#remove(java.lang.Object)
- */
- public void test_removeLjava_lang_Object() {
- int size = hm.size();
- Integer y = new Integer(9);
- Integer x = ((Integer) hm.remove(y.toString()));
- assertTrue("Remove returned incorrect value", x.equals(new Integer(9)));
- assertNull("Failed to remove given key", hm.get(new Integer(9)));
- assertTrue("Failed to decrement size", hm.size() == (size - 1));
- assertNull("Remove of non-existent key returned non-null", hm
- .remove("LCLCLC"));
-
- HashMap m = new HashMap();
- m.put(null, "test");
- assertNull("Failed with same hash as null",
- m.remove(new Integer(0)));
- assertEquals("Failed with null key", "test", m.remove(null));
-
- HashMap<Integer, Object> map = new HashMap<Integer, Object>();
- for (int i = 0; i < 32768; i++) {
- map.put(i, "const");
- }
- Object[] values = new Object[32768];
- for (int i = 0; i < 32768; i++) {
- values[i] = new Object();
- map.put(i, values[i]);
- }
- for (int i = 32767; i >= 0; i--) {
- assertEquals("Failed to remove same value", values[i], map.remove(i));
- }
-
- // Ensure keys with identical hashcode are removed properly
- map = new HashMap<Integer, Object>();
- for (int i = -32767; i < 32768; i++) {
- map.put(i, "foobar");
- }
- // Remove non equal object with same hashcode
- assertNull(map.remove(new MyKey()));
- assertEquals("foobar", map.get(0));
- map.remove(0);
- assertNull(map.get(0));
- }
-
- /**
- * java.util.HashMap#size()
- */
- public void test_size() {
- // Test for method int java.util.HashMap.size()
- assertTrue("Returned incorrect size",
- hm.size() == (objArray.length + 2));
- }
-
- /**
- * 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)));
-
- }
-
- /**
- * java.util.AbstractMap#toString()
- */
- public void test_toString() {
-
- HashMap m = new HashMap();
- m.put(m, m);
- String result = m.toString();
- assertTrue("should contain self ref", result.indexOf("(this") > -1);
- }
-
- static class ReusableKey {
- private int key = 0;
-
- public void setKey(int key) {
- this.key = key;
- }
-
- public int hashCode() {
- return key;
- }
-
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
- if (!(o instanceof ReusableKey)) {
- return false;
- }
- return key == ((ReusableKey) o).key;
- }
- }
-
- public void test_Map_Entry_hashCode() {
- //Related to HARMONY-403
- HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(10);
- Integer key = new Integer(1);
- Integer val = new Integer(2);
- map.put(key, val);
- int expected = key.hashCode() ^ val.hashCode();
- assertEquals(expected, map.hashCode());
- key = new Integer(4);
- val = new Integer(8);
- map.put(key, val);
- expected += key.hashCode() ^ val.hashCode();
- assertEquals(expected, map.hashCode());
- }
-
- class MockClonable implements Cloneable{
- public int i;
-
- public MockClonable(int i) {
- this.i = i;
- }
-
- @Override
- protected Object clone() throws CloneNotSupportedException {
- return new MockClonable(i);
- }
- }
-
- /*
- * Regression test for HY-4750
- */
- public void test_EntrySet() {
- HashMap map = new HashMap();
- map.put(new Integer(1), "ONE");
-
- Set entrySet = map.entrySet();
- Iterator e = entrySet.iterator();
- Object real = e.next();
- Map.Entry copyEntry = new MockEntry();
- assertEquals(real, copyEntry);
- assertTrue(entrySet.contains(copyEntry));
-
- entrySet.remove(copyEntry);
- assertFalse(entrySet.contains(copyEntry));
-
-
- }
-
- private static class MockEntry implements Map.Entry {
-
- public Object getKey() {
- return new Integer(1);
- }
-
- public Object getValue() {
- return "ONE";
- }
-
- public Object setValue(Object object) {
- return null;
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- hm = new HashMap();
- for (int i = 0; i < objArray.length; i++)
- hm.put(objArray2[i], objArray[i]);
- hm.put("test", null);
- hm.put(null, "test");
- }
-
-
- class SubMap<K, V> extends HashMap<K, V> {
- public SubMap(Map<? extends K, ? extends V> m) {
- super(m);
- }
-
- public V put(K key, V value) {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
- HashMap<String, String> hm = new HashMap<String, String>();
- hm.put("key", "value");
-
- SerializationTest.verifySelf(hm);
-
- // regression for HARMONY-1583
- hm.put(null, "null");
- SerializationTest.verifySelf(hm);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
- HashMap<String, String> hm = new HashMap<String, String>();
- hm.put("key", "value");
-
- SerializationTest.verifyGolden(this, hm);
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java
deleted file mode 100644
index fba97ef..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IdentityHashMapTest.java
+++ /dev/null
@@ -1,436 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class IdentityHashMapTest extends junit.framework.TestCase {
-
- /**
- * java.util.IdentityHashMap#containsKey(java.lang.Object)
- * java.util.IdentityHashMap#containsValue(java.lang.Object)
- * java.util.IdentityHashMap#put(java.lang.Object, java.lang.Object)
- * java.util.IdentityHashMap#get(java.lang.Object)
- */
- public void test_null_Keys_and_Values() {
- // tests with null keys and values
- IdentityHashMap map = new IdentityHashMap();
- Object result;
-
- // null key and null value
- result = map.put(null, null);
- assertTrue("testA can not find null key", map.containsKey(null));
- assertTrue("testA can not find null value", map.containsValue(null));
- assertNull("testA can not get null value for null key",
- map.get(null));
- assertNull("testA put returned wrong value", result);
-
- // null value
- String value = "a value";
- result = map.put(null, value);
- assertTrue("testB can not find null key", map.containsKey(null));
- assertTrue("testB can not find a value with null key", map
- .containsValue(value));
- assertTrue("testB can not get value for null key",
- map.get(null) == value);
- assertNull("testB put returned wrong value", result);
-
- // a null key
- String key = "a key";
- result = map.put(key, null);
- assertTrue("testC can not find a key with null value", map
- .containsKey(key));
- assertTrue("testC can not find null value", map.containsValue(null));
- assertNull("testC can not get null value for key", map.get(key));
- assertNull("testC put returned wrong value", result);
-
- // another null key
- String anothervalue = "another value";
- result = map.put(null, anothervalue);
- assertTrue("testD can not find null key", map.containsKey(null));
- assertTrue("testD can not find a value with null key", map
- .containsValue(anothervalue));
- assertTrue("testD can not get value for null key",
- map.get(null) == anothervalue);
- assertTrue("testD put returned wrong value", result == value);
-
- // remove a null key
- result = map.remove(null);
- assertTrue("testE remove returned wrong value", result == anothervalue);
- assertTrue("testE should not find null key", !map.containsKey(null));
- assertTrue("testE should not find a value with null key", !map
- .containsValue(anothervalue));
- assertNull("testE should not get value for null key",
- map.get(null));
- }
-
- /**
- * java.util.IdentityHashMap#put(java.lang.Object, java.lang.Object)
- */
- public void test_putLjava_lang_ObjectLjava_lang_Object() {
- IdentityHashMap<Object, Object> map = new IdentityHashMap<Object, Object>();
-
- // Test null as a key.
- Object value = "Some value";
- map.put(null, value);
- assertSame("Assert 0: Failure getting null key", value, map.get(null));
-
- // Test null as a value
- Object key = "Some key";
- map.put(key, null);
- assertNull("Assert 1: Failure getting null value", map.get(key));
- }
-
- /**
- * java.util.IdentityHashMap#remove(java.lang.Object)
- * java.util.IdentityHashMap#keySet()
- */
- public void test_remove() {
- IdentityHashMap map = new IdentityHashMap();
- map.put(null, null);
- map.put("key1", "value1");
- map.put("key2", "value2");
- map.remove("key1");
-
- assertTrue("Did not remove key1", !map.containsKey("key1"));
- assertTrue("Did not remove the value for key1", !map
- .containsValue("value1"));
-
- assertTrue("Modified key2", map.get("key2") != null
- && map.get("key2") == "value2");
- assertNull("Modified null entry", map.get(null));
- }
-
- /**
- * java.util.IdentityHashMapTest#remove(java.lang.Object)
- */
- public void test_removeLjava_lang_Object() {
- // Regression for HARMONY-37
- IdentityHashMap<String, String> hashMap = new IdentityHashMap<String, String>();
- hashMap.remove("absent");
- assertEquals("Assert 0: Size is incorrect", 0, hashMap.size());
-
- hashMap.put("key", "value");
- hashMap.remove("key");
- assertEquals("Assert 1: After removing non-null element size is incorrect", 0, hashMap.size());
-
- hashMap.put(null, null);
- assertEquals("Assert 2: adding literal null failed", 1, hashMap.size());
- hashMap.remove(null);
- assertEquals("Assert 3: After removing null element size is incorrect", 0, hashMap.size());
- }
-
- /**
- * java.util.IdentityHashMap#entrySet()
- * java.util.IdentityHashMap#keySet()
- * java.util.IdentityHashMap#values()
- */
- public void test_sets() {
- // tests with null keys and values
- IdentityHashMap map = new IdentityHashMap();
-
- // null key and null value
- map.put("key", "value");
- map.put(null, null);
- map.put("a key", null);
- map.put("another key", null);
-
- Set keyset = map.keySet();
- Collection valueset = map.values();
- Set entries = map.entrySet();
- Iterator it = entries.iterator();
- while (it.hasNext()) {
- Map.Entry entry = (Map.Entry) it.next();
- assertTrue("EntrySetIterator can not find entry ", entries
- .contains(entry));
-
- assertTrue("entry key not found in map", map.containsKey(entry
- .getKey()));
- assertTrue("entry value not found in map", map.containsValue(entry
- .getValue()));
-
- assertTrue("entry key not found in the keyset", keyset
- .contains(entry.getKey()));
- assertTrue("entry value not found in the valueset", valueset
- .contains(entry.getValue()));
- }
- }
-
- /**
- * java.util.IdentityHashMap#entrySet()
- * java.util.IdentityHashMap#remove(java.lang.Object)
- */
- public void test_entrySet_removeAll() {
- IdentityHashMap map = new IdentityHashMap();
- for (int i = 0; i < 1000; i++) {
- map.put(new Integer(i), new Integer(i));
- }
- Set set = map.entrySet();
-
- set.removeAll(set);
- assertEquals("did not remove all elements in the map", 0, map.size());
- assertTrue("did not remove all elements in the entryset", set.isEmpty());
-
- Iterator it = set.iterator();
- assertTrue("entrySet iterator still has elements", !it.hasNext());
- }
-
- /**
- * java.util.IdentityHashMap#keySet()
- * java.util.IdentityHashMap#clear()
- */
- public void test_keySet_clear() {
- IdentityHashMap map = new IdentityHashMap();
- for (int i = 0; i < 1000; i++) {
- map.put(new Integer(i), new Integer(i));
- }
- Set set = map.keySet();
- set.clear();
-
- assertEquals("did not remove all elements in the map", 0, map.size());
- assertTrue("did not remove all elements in the keyset", set.isEmpty());
-
- Iterator it = set.iterator();
- assertTrue("keySet iterator still has elements", !it.hasNext());
- }
-
- /**
- * java.util.IdentityHashMap#values()
- */
- public void test_values() {
-
- IdentityHashMap map = new IdentityHashMap();
- for (int i = 0; i < 10; i++) {
- map.put(new Integer(i), new Integer(i));
- }
-
- Integer key = new Integer(20);
- Integer value = new Integer(40);
- map.put(key, value);
-
- Collection vals = map.values();
- boolean result = vals.remove(key);
- assertTrue("removed entries incorrectly", map.size() == 11 && !result);
- assertTrue("removed key incorrectly", map.containsKey(key));
- assertTrue("removed value incorrectly", map.containsValue(value));
-
- result = vals.remove(value);
- assertTrue("Did not remove entry as expected", map.size() == 10
- && result);
- assertTrue("Did not remove key as expected", !map.containsKey(key));
- assertTrue("Did not remove value as expected", !map
- .containsValue(value));
-
- // put an equivalent key to a value
- key = new Integer(1);
- value = new Integer(100);
- map.put(key, value);
-
- result = vals.remove(key);
- assertTrue("TestB. removed entries incorrectly", map.size() == 11
- && !result);
- assertTrue("TestB. removed key incorrectly", map.containsKey(key));
- assertTrue("TestB. removed value incorrectly", map.containsValue(value));
-
- result = vals.remove(value);
- assertTrue("TestB. Did not remove entry as expected", map.size() == 10
- && result);
- assertTrue("TestB. Did not remove key as expected", !map
- .containsKey(key));
- assertTrue("TestB. Did not remove value as expected", !map
- .containsValue(value));
-
- vals.clear();
- assertEquals("Did not remove all entries as expected", 0, map.size());
- }
-
- /**
- * java.util.IdentityHashMap#keySet()
- * java.util.IdentityHashMap#remove(java.lang.Object)
- */
- public void test_keySet_removeAll() {
- IdentityHashMap map = new IdentityHashMap();
- for (int i = 0; i < 1000; i++) {
- map.put(new Integer(i), new Integer(i));
- }
- Set set = map.keySet();
- set.removeAll(set);
-
- assertEquals("did not remove all elements in the map", 0, map.size());
- assertTrue("did not remove all elements in the keyset", set.isEmpty());
-
- Iterator it = set.iterator();
- assertTrue("keySet iterator still has elements", !it.hasNext());
- }
-
- /**
- * java.util.IdentityHashMap#keySet()
- */
- public void test_keySet_retainAll() {
- IdentityHashMap map = new IdentityHashMap();
- for (int i = 0; i < 1000; i++) {
- map.put(new Integer(i), new Integer(i));
- }
- Set set = map.keySet();
-
- // retain all the elements
- boolean result = set.retainAll(set);
- assertTrue("retain all should return false", !result);
- assertEquals("did not retain all", 1000, set.size());
-
- // send empty set to retainAll
- result = set.retainAll(new TreeSet());
- assertTrue("retain all should return true", result);
- assertEquals("did not remove all elements in the map", 0, map.size());
- assertTrue("did not remove all elements in the keyset", set.isEmpty());
-
- Iterator it = set.iterator();
- assertTrue("keySet iterator still has elements", !it.hasNext());
- }
-
- /**
- * java.util.IdentityHashMap#keySet()
- * java.util.IdentityHashMap#remove(java.lang.Object)
- */
- public void test_keyset_remove() {
- IdentityHashMap map = new IdentityHashMap();
-
- Integer key = new Integer(21);
-
- map.put(new Integer(1), null);
- map.put(new Integer(11), null);
- map.put(key, null);
- map.put(new Integer(31), null);
- map.put(new Integer(41), null);
- map.put(new Integer(51), null);
- map.put(new Integer(61), null);
- map.put(new Integer(71), null);
- map.put(new Integer(81), null);
- map.put(new Integer(91), null);
-
- Set set = map.keySet();
-
- Set newset = new HashSet();
- Iterator it = set.iterator();
- while (it.hasNext()) {
- Object element = it.next();
- if (element == key) {
- it.remove();
- } else
- newset.add(element);
- }
- int size = newset.size();
- assertTrue("keyset and newset don't have same size",
- newset.size() == size);
- assertTrue("element is in newset ", !newset.contains(key));
- assertTrue("element not removed from keyset", !set.contains(key));
- assertTrue("element not removed from map", !map.containsKey(key));
-
- assertTrue("newset and keyset do not have same elements 1", newset
- .equals(set));
- assertTrue("newset and keyset do not have same elements 2", set
- .equals(newset));
- }
-
- public void test_clone_scenario1() {
- IdentityHashMap hashMap = new IdentityHashMap();
- assertEquals(0, hashMap.hashCode());
- Object cloneHashMap = hashMap.clone();
- ((IdentityHashMap) cloneHashMap).put("key", "value");
- assertEquals(0, hashMap.hashCode());
- assertTrue(0 != cloneHashMap.hashCode());
- }
-
- public void test_clone_scenario2() {
- IdentityHashMap hashMap = new IdentityHashMap();
- assertEquals(0, hashMap.hashCode());
- Object cloneHashMap = hashMap.clone();
- hashMap.put("key", "value");
- assertEquals(1, hashMap.size());
- assertEquals(0, ((IdentityHashMap) cloneHashMap).size());
- assertEquals("value", hashMap.get("key"));
- assertNull(((IdentityHashMap) cloneHashMap).get("key"));
- assertTrue(0 != hashMap.hashCode());
- assertEquals(0, cloneHashMap.hashCode());
- }
-
- public void test_clone_scenario3() {
- IdentityHashMap hashMap = new IdentityHashMap();
- assertEquals(0, hashMap.hashCode());
- hashMap.put("key", "value");
- Object cloneHashMap = hashMap.clone();
- assertEquals(1, hashMap.size());
- assertEquals(1, ((IdentityHashMap) cloneHashMap).size());
- assertEquals("value", hashMap.get("key"));
- assertEquals("value", ((IdentityHashMap) cloneHashMap).get("key"));
- assertEquals(hashMap.hashCode(), cloneHashMap.hashCode());
- }
-
- public void test_clone_scenario4() {
- IdentityHashMap hashMap = new IdentityHashMap();
- Object cloneHashMap = hashMap.clone();
- assertNull(((IdentityHashMap) cloneHashMap).get((Object) null));
- hashMap.put((Object) null, cloneHashMap);
- assertNull(((IdentityHashMap) cloneHashMap).get((Object) null));
- assertEquals(cloneHashMap, hashMap.get((Object) null));
- }
-
- public void test_clone_scenario5() throws Exception {
- IdentityHashMap hashMap = new IdentityHashMap();
- Object cloneHashMap = hashMap.clone();
- assertNull(hashMap.remove((Object) null));
- ((IdentityHashMap) cloneHashMap).put((Object) null, cloneHashMap);
- assertNull(hashMap.remove((Object) null));
- assertEquals(cloneHashMap, ((IdentityHashMap) cloneHashMap)
- .get((Object) null));
- }
-
- // comparator for IdentityHashMap objects
- private static final SerializableAssert COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- IdentityHashMap init = (IdentityHashMap) initial;
- IdentityHashMap desr = (IdentityHashMap) deserialized;
-
- assertEquals("Size", init.size(), desr.size());
- }
- };
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
- IdentityHashMap<String, String> identityHashMap = new IdentityHashMap<String, String>();
- identityHashMap.put("key1", "value1");
- identityHashMap.put("key2", "value2");
- identityHashMap.put("key3", "value3");
-
- SerializationTest.verifyGolden(this, identityHashMap, COMPARATOR);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatCodePointExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatCodePointExceptionTest.java
deleted file mode 100644
index 4592ab9..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatCodePointExceptionTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.IllegalFormatCodePointException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class IllegalFormatCodePointExceptionTest extends TestCase {
-
- /**
- * java.util.IllegalFormatCodePointException.IllegalFormatCodePointException(int)
- */
- public void test_illegalFormatCodePointException() {
- IllegalFormatCodePointException illegalFormatCodePointException = new IllegalFormatCodePointException(
- -1);
- assertTrue(null != illegalFormatCodePointException);
- }
-
- /**
- * java.util.IllegalFormatCodePointException.getCodePoint()
- */
- public void test_getCodePoint() {
- int codePoint = 12345;
- IllegalFormatCodePointException illegalFormatCodePointException = new IllegalFormatCodePointException(
- codePoint);
- assertEquals(codePoint, illegalFormatCodePointException.getCodePoint());
- }
-
- /**
- * java.util.IllegalFormatCodePointException.getMessage()
- */
- public void test_getMessage() {
- int codePoint = 12345;
- IllegalFormatCodePointException illegalFormatCodePointException = new IllegalFormatCodePointException(
- codePoint);
- assertTrue(null != illegalFormatCodePointException.getMessage());
- }
-
- // comparator for IllegalFormatCodePointException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- IllegalFormatCodePointException initEx = (IllegalFormatCodePointException) initial;
- IllegalFormatCodePointException desrEx = (IllegalFormatCodePointException) deserialized;
-
- assertEquals("CodePoint", initEx.getCodePoint(), desrEx
- .getCodePoint());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(
- new IllegalFormatCodePointException(12345), exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- new IllegalFormatCodePointException(12345), exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatConversionExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatConversionExceptionTest.java
deleted file mode 100644
index 94cf1e4..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatConversionExceptionTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.IllegalFormatConversionException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class IllegalFormatConversionExceptionTest extends TestCase {
-
- /**
- * java.util.IllegalFormatConversionException#IllegalFormatConversionException(char,
- * Class)
- */
- public void test_illegalFormatConversionException() {
- try {
- new IllegalFormatConversionException(' ', null);
- fail("should throw NullPointerExcetpion.");
- } catch (NullPointerException e) {
- // desired
- }
- }
-
- /**
- * java.util.IllegalFormatConversionException#getArgumentClass()
- */
- public void test_getArgumentClass() {
- char c = '*';
- Class<String> argClass = String.class;
- IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(
- c, argClass);
- assertEquals(argClass, illegalFormatConversionException
- .getArgumentClass());
-
- }
-
- /**
- * java.util.IllegalFormatConversionException#getConversion()
- */
- public void test_getConversion() {
- char c = '*';
- Class<String> argClass = String.class;
- IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(
- c, argClass);
- assertEquals(c, illegalFormatConversionException.getConversion());
-
- }
-
- /**
- * java.util.IllegalFormatConversionException#getMessage()
- */
- public void test_getMessage() {
- char c = '*';
- Class<String> argClass = String.class;
- IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(
- c, argClass);
- assertTrue(null != illegalFormatConversionException.getMessage());
-
- }
-
- // comparator for IllegalFormatConversionException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- IllegalFormatConversionException initEx = (IllegalFormatConversionException) initial;
- IllegalFormatConversionException desrEx = (IllegalFormatConversionException) deserialized;
-
- assertEquals("ArgumentClass", initEx.getArgumentClass(), desrEx
- .getArgumentClass());
- assertEquals("Conversion", initEx.getConversion(), desrEx
- .getConversion());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new IllegalFormatConversionException('*',
- String.class), exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- new IllegalFormatConversionException('*', String.class),
- exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatFlagsExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatFlagsExceptionTest.java
deleted file mode 100644
index 6816d16..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatFlagsExceptionTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.IllegalFormatFlagsException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class IllegalFormatFlagsExceptionTest extends TestCase {
-
- /**
- * java.util.IllegalFormatFlagsException#IllegalFormatFlagsException(String)
- */
- public void test_illegalFormatFlagsException() {
- try {
- new IllegalFormatFlagsException(null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * java.util.IllegalFormatFlagsException.getFlags()
- */
- public void test_getFlags() {
- String flags = "TESTFLAGS";
- IllegalFormatFlagsException illegalFormatFlagsException = new IllegalFormatFlagsException(
- flags);
- assertEquals(flags, illegalFormatFlagsException.getFlags());
- }
-
- /**
- * java.util.IllegalFormatFlagsException.getMessage()
- */
- public void test_getMessage() {
- String flags = "TESTFLAGS";
- IllegalFormatFlagsException illegalFormatFlagsException = new IllegalFormatFlagsException(
- flags);
- assertTrue(null != illegalFormatFlagsException.getMessage());
-
- }
-
- // comparator for IllegalFormatFlagsException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- IllegalFormatFlagsException initEx = (IllegalFormatFlagsException) initial;
- IllegalFormatFlagsException desrEx = (IllegalFormatFlagsException) deserialized;
-
- assertEquals("Flags", initEx.getFlags(), desrEx.getFlags());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new IllegalFormatFlagsException(
- "TESTFLAGS"), exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new IllegalFormatFlagsException(
- "TESTFLAGS"), exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatPrecisionExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatPrecisionExceptionTest.java
deleted file mode 100644
index 84d06c4..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatPrecisionExceptionTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.IllegalFormatPrecisionException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class IllegalFormatPrecisionExceptionTest extends TestCase {
-
- /**
- * java.util.IllegalFormatPrecisionException#IllegalFormatPrecisionException(int)
- */
- public void test_illegalFormatPrecisionException() {
- IllegalFormatPrecisionException illegalFormatPrecisionException = new IllegalFormatPrecisionException(
- Integer.MIN_VALUE);
- assertEquals(Integer.MIN_VALUE, illegalFormatPrecisionException
- .getPrecision());
- }
-
- /**
- * java.util.IllegalFormatPrecisionException#getPrecision()
- */
- public void test_getPrecision() {
- int precision = 12345;
- IllegalFormatPrecisionException illegalFormatPrecisionException = new IllegalFormatPrecisionException(
- precision);
- assertEquals(precision, illegalFormatPrecisionException.getPrecision());
- }
-
- /**
- * method for 'java.util.IllegalFormatPrecisionException#getMessage()
- */
- public void test_getMessage() {
- int precision = 12345;
- IllegalFormatPrecisionException illegalFormatPrecisionException = new IllegalFormatPrecisionException(
- precision);
- assertTrue(null != illegalFormatPrecisionException.getMessage());
-
- }
-
- // comparator for IllegalFormatPrecisionException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- IllegalFormatPrecisionException initEx = (IllegalFormatPrecisionException) initial;
- IllegalFormatPrecisionException desrEx = (IllegalFormatPrecisionException) deserialized;
-
- assertEquals("Precision", initEx.getPrecision(), desrEx
- .getPrecision());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(
- new IllegalFormatPrecisionException(12345), exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- new IllegalFormatPrecisionException(12345), exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatWidthExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatWidthExceptionTest.java
deleted file mode 100644
index 312635b..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/IllegalFormatWidthExceptionTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.IllegalFormatWidthException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class IllegalFormatWidthExceptionTest extends TestCase {
-
- /**
- * java.util.IllegalFormatWidthException#IllegalFormatWidthException(int)
- */
- public void test_illegalFormatWidthException() {
- int width = Integer.MAX_VALUE;
- IllegalFormatWidthException illegalFormatWidthException = new IllegalFormatWidthException(
- width);
- assertEquals(width, illegalFormatWidthException.getWidth());
-
- }
-
- /**
- * java.util.IllegalFormatWidthException#getWidth()
- */
- public void test_getWidth() {
- int width = 12345;
- IllegalFormatWidthException illegalFormatWidthException = new IllegalFormatWidthException(
- width);
- assertEquals(width, illegalFormatWidthException.getWidth());
-
- }
-
- /**
- * java.util.IllegalFormatWidthException#getMessage()
- */
- public void test_getMessage() {
- int width = 12345;
- IllegalFormatWidthException illegalFormatWidthException = new IllegalFormatWidthException(
- width);
- assertTrue(null != illegalFormatWidthException.getMessage());
-
- }
-
- // comparator for IllegalFormatWidthException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- IllegalFormatWidthException initEx = (IllegalFormatWidthException) initial;
- IllegalFormatWidthException desrEx = (IllegalFormatWidthException) deserialized;
-
- assertEquals("Width", initEx.getWidth(), desrEx.getWidth());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new IllegalFormatWidthException(12345),
- exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new IllegalFormatWidthException(
- 12345), exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/InputMismatchExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/InputMismatchExceptionTest.java
deleted file mode 100644
index fb8fc0d..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/InputMismatchExceptionTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.InputMismatchException;
-import java.util.NoSuchElementException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-public class InputMismatchExceptionTest extends TestCase {
-
- private static final String ERROR_MESSAGE = "for serialization test";
-
- /**
- * java.util.InputMismatchException#InputMismatchException()
- */
- @SuppressWarnings("cast")
- public void test_Constructor() {
- InputMismatchException exception = new InputMismatchException();
- assertNotNull(exception);
- assertTrue(exception instanceof NoSuchElementException);
- assertTrue(exception instanceof Serializable);
- }
-
- /**
- * java.util.InputMismatchException#InputMismatchException(String)
- */
- public void test_ConstructorLjava_lang_String() {
- InputMismatchException exception = new InputMismatchException(
- ERROR_MESSAGE);
- assertNotNull(exception);
- assertEquals(ERROR_MESSAGE, exception.getMessage());
- }
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new InputMismatchException(ERROR_MESSAGE));
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new InputMismatchException(
- ERROR_MESSAGE));
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/InvalidPropertiesFormatExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/InvalidPropertiesFormatExceptionTest.java
deleted file mode 100644
index 8b7bfce..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/InvalidPropertiesFormatExceptionTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.NotSerializableException;
-import java.util.InvalidPropertiesFormatException;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-public class InvalidPropertiesFormatExceptionTest extends
- junit.framework.TestCase {
-
- /**
- * java.util.InvalidPropertiesFormatException#SerializationTest()
- */
- public void test_Serialization() throws Exception {
- InvalidPropertiesFormatException ipfe = new InvalidPropertiesFormatException(
- "Hey, this is InvalidPropertiesFormatException");
- try {
- SerializationTest.verifySelf(ipfe);
- } catch (NotSerializableException e) {
- // expected
- }
- }
-
- /**
- * {@link java.util.InvalidPropertiesFormatException#InvalidPropertiesFormatException(Throwable)}
- */
- public void test_Constructor_Ljava_lang_Throwable() {
- Throwable throwable = new Throwable();
- InvalidPropertiesFormatException exception = new InvalidPropertiesFormatException(
- throwable);
- assertEquals("the casue did not equals argument passed in constructor",
- throwable, exception.getCause());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/LinkedHashMapTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/LinkedHashMapTest.java
deleted file mode 100644
index 37f21da..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/LinkedHashMapTest.java
+++ /dev/null
@@ -1,694 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.util.AbstractMap;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-
-import tests.support.Support_MapTest2;
-import tests.support.Support_UnmodifiableCollectionTest;
-
-/**
- * java.util.LinkedHashMap
- */
-public class LinkedHashMapTest extends junit.framework.TestCase {
-
- LinkedHashMap hm;
-
- final static int hmSize = 1000;
-
- static Object[] objArray;
-
- static Object[] objArray2;
- {
- objArray = new Object[hmSize];
- objArray2 = new Object[hmSize];
- for (int i = 0; i < objArray.length; i++) {
- objArray[i] = new Integer(i);
- objArray2[i] = objArray[i].toString();
- }
- }
-
- static final class CacheMap extends LinkedHashMap {
- protected boolean removeEldestEntry(Map.Entry e) {
- return size() > 5;
- }
- }
-
- private static class MockMapNull extends AbstractMap {
- @Override
- public Set entrySet() {
- return null;
- }
-
- @Override
- public int size() {
- return 10;
- }
- }
-
- /**
- * java.util.LinkedHashMap#LinkedHashMap()
- */
- public void test_Constructor() {
- // Test for method java.util.LinkedHashMap()
- new Support_MapTest2(new LinkedHashMap()).runTest();
-
- LinkedHashMap hm2 = new LinkedHashMap();
- assertEquals("Created incorrect LinkedHashMap", 0, hm2.size());
- }
-
- /**
- * java.util.LinkedHashMap#LinkedHashMap(int)
- */
- public void test_ConstructorI() {
- // Test for method java.util.LinkedHashMap(int)
- LinkedHashMap hm2 = new LinkedHashMap(5);
- assertEquals("Created incorrect LinkedHashMap", 0, hm2.size());
- try {
- new LinkedHashMap(-1);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- LinkedHashMap empty = new LinkedHashMap(0);
- assertNull("Empty LinkedHashMap access", empty.get("nothing"));
- empty.put("something", "here");
- assertTrue("cannot get element", empty.get("something") == "here");
- }
-
- /**
- * java.util.LinkedHashMap#LinkedHashMap(int, float)
- */
- public void test_ConstructorIF() {
- // Test for method java.util.LinkedHashMap(int, float)
- LinkedHashMap hm2 = new LinkedHashMap(5, (float) 0.5);
- assertEquals("Created incorrect LinkedHashMap", 0, hm2.size());
- try {
- new LinkedHashMap(0, 0);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- LinkedHashMap empty = new LinkedHashMap(0, 0.75f);
- assertNull("Empty hashtable access", empty.get("nothing"));
- empty.put("something", "here");
- assertTrue("cannot get element", empty.get("something") == "here");
- }
-
- /**
- * java.util.LinkedHashMap#LinkedHashMap(java.util.Map)
- */
- public void test_ConstructorLjava_util_Map() {
- // Test for method java.util.LinkedHashMap(java.util.Map)
- Map myMap = new TreeMap();
- for (int counter = 0; counter < hmSize; counter++)
- myMap.put(objArray2[counter], objArray[counter]);
- LinkedHashMap hm2 = new LinkedHashMap(myMap);
- for (int counter = 0; counter < hmSize; counter++)
- assertTrue("Failed to construct correct LinkedHashMap", hm
- .get(objArray2[counter]) == hm2.get(objArray2[counter]));
-
- try {
- new LinkedHashMap(null);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
- }
-
- /**
- * java.util.LinkedHashMap#get(java.lang.Object)
- */
- public void test_getLjava_lang_Object() {
- // Test for method java.lang.Object
- // java.util.LinkedHashMap.get(java.lang.Object)
- assertNull("Get returned non-null for non existent key",
- hm.get("T"));
- hm.put("T", "HELLO");
- assertEquals("Get returned incorecct value for existing key", "HELLO", hm.get("T")
- );
-
- LinkedHashMap m = new LinkedHashMap();
- m.put(null, "test");
- assertEquals("Failed with null key", "test", m.get(null));
- assertNull("Failed with missing key matching null hash", m
- .get(new Integer(0)));
- }
-
- /**
- * java.util.LinkedHashMap#put(java.lang.Object, java.lang.Object)
- */
- public void test_putLjava_lang_ObjectLjava_lang_Object() {
- // Test for method java.lang.Object
- // java.util.LinkedHashMap.put(java.lang.Object, java.lang.Object)
- hm.put("KEY", "VALUE");
- assertEquals("Failed to install key/value pair",
- "VALUE", hm.get("KEY"));
-
- LinkedHashMap m = new LinkedHashMap();
- m.put(new Short((short) 0), "short");
- m.put(null, "test");
- m.put(new Integer(0), "int");
- assertEquals("Failed adding to bucket containing null", "short", m.get(
- new Short((short) 0)));
- assertEquals("Failed adding to bucket containing null2", "int", m.get(
- new Integer(0)));
- }
-
- /**
- * java.util.LinkedHashMap#putAll(java.util.Map)
- */
- public void test_putAllLjava_util_Map() {
- // Test for method void java.util.LinkedHashMap.putAll(java.util.Map)
- LinkedHashMap hm2 = new LinkedHashMap();
- hm2.putAll(hm);
- for (int i = 0; i < 1000; i++)
- assertTrue("Failed to clear all elements", hm2.get(
- new Integer(i).toString()).equals((new Integer(i))));
- }
-
- /**
- * java.util.LinkedHashMap#putAll(java.util.Map)
- */
- public void test_putAll_Ljava_util_Map_Null() {
- LinkedHashMap linkedHashMap = new LinkedHashMap();
- try {
- linkedHashMap.putAll(new MockMapNull());
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected.
- }
-
- try {
- linkedHashMap = new LinkedHashMap(new MockMapNull());
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected.
- }
- }
-
- /**
- * java.util.LinkedHashMap#entrySet()
- */
- public void test_entrySet() {
- // Test for method java.util.Set java.util.LinkedHashMap.entrySet()
- Set s = hm.entrySet();
- Iterator i = s.iterator();
- assertTrue("Returned set of incorrect size", hm.size() == s.size());
- while (i.hasNext()) {
- Map.Entry m = (Map.Entry) i.next();
- assertTrue("Returned incorrect entry set", hm.containsKey(m
- .getKey())
- && hm.containsValue(m.getValue()));
- }
- }
-
- /**
- * java.util.LinkedHashMap#keySet()
- */
- public void test_keySet() {
- // Test for method java.util.Set java.util.LinkedHashMap.keySet()
- Set s = hm.keySet();
- assertTrue("Returned set of incorrect size()", s.size() == hm.size());
- for (int i = 0; i < objArray.length; i++)
- assertTrue("Returned set does not contain all keys", s
- .contains(objArray[i].toString()));
-
- LinkedHashMap m = new LinkedHashMap();
- m.put(null, "test");
- assertTrue("Failed with null key", m.keySet().contains(null));
- assertNull("Failed with null key", m.keySet().iterator().next());
-
- Map map = new LinkedHashMap(101);
- map.put(new Integer(1), "1");
- map.put(new Integer(102), "102");
- map.put(new Integer(203), "203");
- Iterator it = map.keySet().iterator();
- Integer remove1 = (Integer) it.next();
- it.hasNext();
- it.remove();
- Integer remove2 = (Integer) it.next();
- it.remove();
- ArrayList list = new ArrayList(Arrays.asList(new Integer[] {
- new Integer(1), new Integer(102), new Integer(203) }));
- list.remove(remove1);
- list.remove(remove2);
- assertTrue("Wrong result", it.next().equals(list.get(0)));
- assertEquals("Wrong size", 1, map.size());
- assertTrue("Wrong contents", map.keySet().iterator().next().equals(
- list.get(0)));
-
- Map map2 = new LinkedHashMap(101);
- map2.put(new Integer(1), "1");
- map2.put(new Integer(4), "4");
- Iterator it2 = map2.keySet().iterator();
- Integer remove3 = (Integer) it2.next();
- Integer next;
- if (remove3.intValue() == 1)
- next = new Integer(4);
- else
- next = new Integer(1);
- it2.hasNext();
- it2.remove();
- assertTrue("Wrong result 2", it2.next().equals(next));
- assertEquals("Wrong size 2", 1, map2.size());
- assertTrue("Wrong contents 2", map2.keySet().iterator().next().equals(
- next));
- }
-
- /**
- * 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)));
-
- }
-
- /**
- * java.util.LinkedHashMap#remove(java.lang.Object)
- */
- public void test_removeLjava_lang_Object() {
- // Test for method java.lang.Object
- // java.util.LinkedHashMap.remove(java.lang.Object)
- int size = hm.size();
- Integer y = new Integer(9);
- Integer x = ((Integer) hm.remove(y.toString()));
- assertTrue("Remove returned incorrect value", x.equals(new Integer(9)));
- assertNull("Failed to remove given key", hm.get(new Integer(9)));
- assertTrue("Failed to decrement size", hm.size() == (size - 1));
- assertNull("Remove of non-existent key returned non-null", hm
- .remove("LCLCLC"));
-
- LinkedHashMap m = new LinkedHashMap();
- m.put(null, "test");
- assertNull("Failed with same hash as null",
- m.remove(new Integer(0)));
- assertEquals("Failed with null key", "test", m.remove(null));
- }
-
- /**
- * java.util.LinkedHashMap#clear()
- */
- public void test_clear() {
- // Test for method void java.util.LinkedHashMap.clear()
- hm.clear();
- assertEquals("Clear failed to reset size", 0, hm.size());
- for (int i = 0; i < hmSize; i++)
- assertNull("Failed to clear all elements",
- hm.get(objArray2[i]));
-
- }
-
- /**
- * java.util.LinkedHashMap#clone()
- */
- public void test_clone() {
- // Test for method java.lang.Object java.util.LinkedHashMap.clone()
- LinkedHashMap hm2 = (LinkedHashMap) hm.clone();
- assertTrue("Clone answered equivalent LinkedHashMap", hm2 != hm);
- for (int counter = 0; counter < hmSize; counter++)
- assertTrue("Clone answered unequal LinkedHashMap", hm
- .get(objArray2[counter]) == hm2.get(objArray2[counter]));
-
- LinkedHashMap map = new LinkedHashMap();
- map.put("key", "value");
- // get the keySet() and values() on the original Map
- Set keys = map.keySet();
- Collection values = map.values();
- assertEquals("values() does not work",
- "value", values.iterator().next());
- assertEquals("keySet() does not work",
- "key", keys.iterator().next());
- AbstractMap map2 = (AbstractMap) map.clone();
- map2.put("key", "value2");
- Collection values2 = map2.values();
- assertTrue("values() is identical", values2 != values);
-
- // values() and keySet() on the cloned() map should be different
- assertEquals("values() was not cloned",
- "value2", values2.iterator().next());
- map2.clear();
- map2.put("key2", "value3");
- Set key2 = map2.keySet();
- assertTrue("keySet() is identical", key2 != keys);
- assertEquals("keySet() was not cloned",
- "key2", key2.iterator().next());
- }
-
- /**
- * java.util.LinkedHashMap#containsKey(java.lang.Object)
- */
- public void test_containsKeyLjava_lang_Object() {
- // Test for method boolean
- // java.util.LinkedHashMap.containsKey(java.lang.Object)
- assertTrue("Returned false for valid key", hm.containsKey(new Integer(
- 876).toString()));
- assertTrue("Returned true for invalid key", !hm.containsKey("KKDKDKD"));
-
- LinkedHashMap m = new LinkedHashMap();
- m.put(null, "test");
- assertTrue("Failed with null key", m.containsKey(null));
- assertTrue("Failed with missing key matching null hash", !m
- .containsKey(new Integer(0)));
- }
-
- /**
- * java.util.LinkedHashMap#containsValue(java.lang.Object)
- */
- public void test_containsValueLjava_lang_Object() {
- // Test for method boolean
- // java.util.LinkedHashMap.containsValue(java.lang.Object)
- assertTrue("Returned false for valid value", hm
- .containsValue(new Integer(875)));
- assertTrue("Returned true for invalid valie", !hm
- .containsValue(new Integer(-9)));
- }
-
- /**
- * java.util.LinkedHashMap#isEmpty()
- */
- public void test_isEmpty() {
- // Test for method boolean java.util.LinkedHashMap.isEmpty()
- assertTrue("Returned false for new map", new LinkedHashMap().isEmpty());
- assertTrue("Returned true for non-empty", !hm.isEmpty());
- }
-
- /**
- * java.util.LinkedHashMap#size()
- */
- public void test_size() {
- // Test for method int java.util.LinkedHashMap.size()
- assertTrue("Returned incorrect size",
- hm.size() == (objArray.length + 2));
- }
-
- /**
- * java.util.LinkedHashMap#entrySet()
- */
- public void test_ordered_entrySet() {
- int i;
- int sz = 100;
- LinkedHashMap lhm = new LinkedHashMap();
- for (i = 0; i < sz; i++) {
- Integer ii = new Integer(i);
- lhm.put(ii, ii.toString());
- }
-
- Set s1 = lhm.entrySet();
- Iterator it1 = s1.iterator();
- assertTrue("Returned set of incorrect size 1", lhm.size() == s1.size());
- for (i = 0; it1.hasNext(); i++) {
- Map.Entry m = (Map.Entry) it1.next();
- Integer jj = (Integer) m.getKey();
- assertTrue("Returned incorrect entry set 1", jj.intValue() == i);
- }
-
- LinkedHashMap lruhm = new LinkedHashMap(200, .75f, true);
- for (i = 0; i < sz; i++) {
- Integer ii = new Integer(i);
- lruhm.put(ii, ii.toString());
- }
-
- Set s3 = lruhm.entrySet();
- Iterator it3 = s3.iterator();
- assertTrue("Returned set of incorrect size 2", lruhm.size() == s3
- .size());
- for (i = 0; i < sz && it3.hasNext(); i++) {
- Map.Entry m = (Map.Entry) it3.next();
- Integer jj = (Integer) m.getKey();
- assertTrue("Returned incorrect entry set 2", jj.intValue() == i);
- }
-
- /* fetch the even numbered entries to affect traversal order */
- int p = 0;
- for (i = 0; i < sz; i += 2) {
- String ii = (String) lruhm.get(new Integer(i));
- p = p + Integer.parseInt(ii);
- }
- assertEquals("invalid sum of even numbers", 2450, p);
-
- Set s2 = lruhm.entrySet();
- Iterator it2 = s2.iterator();
- assertTrue("Returned set of incorrect size 3", lruhm.size() == s2
- .size());
- for (i = 1; i < sz && it2.hasNext(); i += 2) {
- Map.Entry m = (Map.Entry) it2.next();
- Integer jj = (Integer) m.getKey();
- assertTrue("Returned incorrect entry set 3", jj.intValue() == i);
- }
- for (i = 0; i < sz && it2.hasNext(); i += 2) {
- Map.Entry m = (Map.Entry) it2.next();
- Integer jj = (Integer) m.getKey();
- assertTrue("Returned incorrect entry set 4", jj.intValue() == i);
- }
- assertTrue("Entries left to iterate on", !it2.hasNext());
- }
-
- /**
- * java.util.LinkedHashMap#keySet()
- */
- public void test_ordered_keySet() {
- int i;
- int sz = 100;
- LinkedHashMap lhm = new LinkedHashMap();
- for (i = 0; i < sz; i++) {
- Integer ii = new Integer(i);
- lhm.put(ii, ii.toString());
- }
-
- Set s1 = lhm.keySet();
- Iterator it1 = s1.iterator();
- assertTrue("Returned set of incorrect size", lhm.size() == s1.size());
- for (i = 0; it1.hasNext(); i++) {
- Integer jj = (Integer) it1.next();
- assertTrue("Returned incorrect entry set", jj.intValue() == i);
- }
-
- LinkedHashMap lruhm = new LinkedHashMap(200, .75f, true);
- for (i = 0; i < sz; i++) {
- Integer ii = new Integer(i);
- lruhm.put(ii, ii.toString());
- }
-
- Set s3 = lruhm.keySet();
- Iterator it3 = s3.iterator();
- assertTrue("Returned set of incorrect size", lruhm.size() == s3.size());
- for (i = 0; i < sz && it3.hasNext(); i++) {
- Integer jj = (Integer) it3.next();
- assertTrue("Returned incorrect entry set", jj.intValue() == i);
- }
-
- /* fetch the even numbered entries to affect traversal order */
- int p = 0;
- for (i = 0; i < sz; i += 2) {
- String ii = (String) lruhm.get(new Integer(i));
- p = p + Integer.parseInt(ii);
- }
- assertEquals("invalid sum of even numbers", 2450, p);
-
- Set s2 = lruhm.keySet();
- Iterator it2 = s2.iterator();
- assertTrue("Returned set of incorrect size", lruhm.size() == s2.size());
- for (i = 1; i < sz && it2.hasNext(); i += 2) {
- Integer jj = (Integer) it2.next();
- assertTrue("Returned incorrect entry set", jj.intValue() == i);
- }
- for (i = 0; i < sz && it2.hasNext(); i += 2) {
- Integer jj = (Integer) it2.next();
- assertTrue("Returned incorrect entry set", jj.intValue() == i);
- }
- assertTrue("Entries left to iterate on", !it2.hasNext());
- }
-
- /**
- * java.util.LinkedHashMap#values()
- */
- public void test_ordered_values() {
- int i;
- int sz = 100;
- LinkedHashMap lhm = new LinkedHashMap();
- for (i = 0; i < sz; i++) {
- Integer ii = new Integer(i);
- lhm.put(ii, new Integer(i * 2));
- }
-
- Collection s1 = lhm.values();
- Iterator it1 = s1.iterator();
- assertTrue("Returned set of incorrect size 1", lhm.size() == s1.size());
- for (i = 0; it1.hasNext(); i++) {
- Integer jj = (Integer) it1.next();
- assertTrue("Returned incorrect entry set 1", jj.intValue() == i * 2);
- }
-
- LinkedHashMap lruhm = new LinkedHashMap(200, .75f, true);
- for (i = 0; i < sz; i++) {
- Integer ii = new Integer(i);
- lruhm.put(ii, new Integer(i * 2));
- }
-
- Collection s3 = lruhm.values();
- Iterator it3 = s3.iterator();
- assertTrue("Returned set of incorrect size", lruhm.size() == s3.size());
- for (i = 0; i < sz && it3.hasNext(); i++) {
- Integer jj = (Integer) it3.next();
- assertTrue("Returned incorrect entry set", jj.intValue() == i * 2);
- }
-
- // fetch the even numbered entries to affect traversal order
- int p = 0;
- for (i = 0; i < sz; i += 2) {
- Integer ii = (Integer) lruhm.get(new Integer(i));
- p = p + ii.intValue();
- }
- assertTrue("invalid sum of even numbers", p == 2450 * 2);
-
- Collection s2 = lruhm.values();
- Iterator it2 = s2.iterator();
- assertTrue("Returned set of incorrect size", lruhm.size() == s2.size());
- for (i = 1; i < sz && it2.hasNext(); i += 2) {
- Integer jj = (Integer) it2.next();
- assertTrue("Returned incorrect entry set", jj.intValue() == i * 2);
- }
- for (i = 0; i < sz && it2.hasNext(); i += 2) {
- Integer jj = (Integer) it2.next();
- assertTrue("Returned incorrect entry set", jj.intValue() == i * 2);
- }
- assertTrue("Entries left to iterate on", !it2.hasNext());
- }
-
- /**
- * java.util.LinkedHashMap#removeEldestEntry(java.util.Map$Entry)
- */
- public void test_remove_eldest() {
- int i;
- int sz = 10;
- CacheMap lhm = new CacheMap();
- for (i = 0; i < sz; i++) {
- Integer ii = new Integer(i);
- lhm.put(ii, new Integer(i * 2));
- }
-
- Collection s1 = lhm.values();
- Iterator it1 = s1.iterator();
- assertTrue("Returned set of incorrect size 1", lhm.size() == s1.size());
- for (i = 5; it1.hasNext(); i++) {
- Integer jj = (Integer) it1.next();
- assertTrue("Returned incorrect entry set 1", jj.intValue() == i * 2);
- }
- assertTrue("Entries left in map", !it1.hasNext());
- }
-
- // BEGIN android-added
- public void testLinkedHashMap() {
- // we want to test the LinkedHashMap in access ordering mode.
- LinkedHashMap map = new LinkedHashMap<String, String>(10, 0.75f, true);
-
- map.put("key1", "value1");
- map.put("key2", "value2");
- map.put("key3", "value3");
-
- Iterator iterator = map.keySet().iterator();
- String id = (String) iterator.next();
- map.get(id);
- try {
- iterator.next();
- // A LinkedHashMap is supposed to throw this Exception when a
- // iterator.next() Operation takes place after a get
- // Operation. This is because the get Operation is considered
- // a structural modification if the LinkedHashMap is in
- // access order mode.
- fail("expected ConcurrentModificationException was not thrown.");
- } catch(ConcurrentModificationException e) {
- // expected
- }
-
- LinkedHashMap mapClone = (LinkedHashMap) map.clone();
-
- iterator = map.keySet().iterator();
- id = (String) iterator.next();
- mapClone.get(id);
- try {
- iterator.next();
- } catch(ConcurrentModificationException e) {
- fail("expected ConcurrentModificationException was not thrown.");
- }
-
- try {
- new LinkedHashMap<String, String>(-10, 0.75f, true);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try {
- new LinkedHashMap<String, String>(10, -0.75f, true);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
- }
- // END android-added
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- hm = new LinkedHashMap();
- for (int i = 0; i < objArray.length; i++)
- hm.put(objArray2[i], objArray[i]);
- hm.put("test", null);
- hm.put(null, "test");
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/MissingFormatArgumentExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/MissingFormatArgumentExceptionTest.java
deleted file mode 100644
index 3334fed..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/MissingFormatArgumentExceptionTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.MissingFormatArgumentException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class MissingFormatArgumentExceptionTest extends TestCase {
-
- /**
- * java.util.MissingFormatArgumentException#MissingFormatArgumentException(String)
- */
- public void test_missingFormatArgumentException() {
-
- try {
- new MissingFormatArgumentException(null);
- fail("should throw NullPointerExcepiton.");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * java.util.MissingFormatArgumentException#getFormatSpecifier()
- */
- public void test_getFormatSpecifier() {
- String s = "MYTESTSTRING";
- MissingFormatArgumentException missingFormatArgumentException = new MissingFormatArgumentException(
- s);
- assertEquals(s, missingFormatArgumentException.getFormatSpecifier());
- }
-
- /**
- * java.util.MissingFormatArgumentException#getMessage()
- */
- public void test_getMessage() {
- String s = "MYTESTSTRING";
- MissingFormatArgumentException missingFormatArgumentException = new MissingFormatArgumentException(
- s);
- assertTrue(null != missingFormatArgumentException.getMessage());
-
- }
-
- // comparator for comparing MissingFormatArgumentException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- MissingFormatArgumentException initEx = (MissingFormatArgumentException) initial;
- MissingFormatArgumentException desrEx = (MissingFormatArgumentException) deserialized;
-
- assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
- .getFormatSpecifier());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new MissingFormatArgumentException(
- "MYTESTSTRING"), exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- new MissingFormatArgumentException("MYTESTSTRING"),
- exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/MissingFormatWidthExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/MissingFormatWidthExceptionTest.java
deleted file mode 100644
index 38c3bdb..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/MissingFormatWidthExceptionTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.MissingFormatWidthException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class MissingFormatWidthExceptionTest extends TestCase {
-
- /**
- * java.util.MissingFormatWidthException#MissingFormatWidthException(String)
- */
- public void test_missingFormatWidthException() {
- try {
- new MissingFormatWidthException(null);
- fail("should throw NullPointerExcepiton");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * java.util.MissingFormatWidthException#getFormatSpecifier()
- */
- public void test_getFormatSpecifier() {
- String s = "MYTESTSTRING";
- MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
- s);
- assertEquals(s, missingFormatWidthException.getFormatSpecifier());
-
- }
-
- /**
- * java.util.MissingFormatWidthException#getMessage()
- */
- public void test_getMessage() {
- String s = "MYTESTSTRING";
- MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(
- s);
- assertTrue(null != missingFormatWidthException.getMessage());
-
- }
-
- // comparator for comparing MissingFormatWidthException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- MissingFormatWidthException initEx = (MissingFormatWidthException) initial;
- MissingFormatWidthException desrEx = (MissingFormatWidthException) deserialized;
-
- assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
- .getFormatSpecifier());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new MissingFormatWidthException(
- "MYTESTSTRING"), exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new MissingFormatWidthException(
- "MYTESTSTRING"), exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/UUIDTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/UUIDTest.java
deleted file mode 100644
index e70cd78..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/UUIDTest.java
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.util.UUID;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-import junit.framework.TestCase;
-
-public class UUIDTest extends TestCase {
-
- /**
- * @see UUID#UUID(long, long)
- */
- public void test_ConstructorJJ() {
- UUID uuid = new UUID(0xf81d4fae7dec11d0L, 0xa76500a0c91e6bf6L);
- assertEquals(2, uuid.variant());
- assertEquals(1, uuid.version());
- assertEquals(0x1d07decf81d4faeL, uuid.timestamp());
- assertEquals(130742845922168750L, uuid.timestamp());
- assertEquals(0x2765, uuid.clockSequence());
- assertEquals(0xA0C91E6BF6L, uuid.node());
- }
-
- /**
- * @see UUID#getLeastSignificantBits()
- */
- public void test_getLeastSignificantBits() {
- UUID uuid = new UUID(0, 0);
- assertEquals(0, uuid.getLeastSignificantBits());
- uuid = new UUID(0, Long.MIN_VALUE);
- assertEquals(Long.MIN_VALUE, uuid.getLeastSignificantBits());
- uuid = new UUID(0, Long.MAX_VALUE);
- assertEquals(Long.MAX_VALUE, uuid.getLeastSignificantBits());
- }
-
- /**
- * @see UUID#getMostSignificantBits()
- */
- public void test_getMostSignificantBits() {
- UUID uuid = new UUID(0, 0);
- assertEquals(0, uuid.getMostSignificantBits());
- uuid = new UUID(Long.MIN_VALUE, 0);
- assertEquals(Long.MIN_VALUE, uuid.getMostSignificantBits());
- uuid = new UUID(Long.MAX_VALUE, 0);
- assertEquals(Long.MAX_VALUE, uuid.getMostSignificantBits());
- }
-
- /**
- * @see UUID#version()
- */
- public void test_version() {
- UUID uuid = new UUID(0, 0);
- assertEquals(0, uuid.version());
- uuid = new UUID(0x0000000000001000L, 0);
- assertEquals(1, uuid.version());
- uuid = new UUID(0x0000000000002000L, 0);
- assertEquals(2, uuid.version());
- uuid = new UUID(0x0000000000003000L, 0);
- assertEquals(3, uuid.version());
- uuid = new UUID(0x0000000000004000L, 0);
- assertEquals(4, uuid.version());
- uuid = new UUID(0x0000000000005000L, 0);
- assertEquals(5, uuid.version());
- }
-
- /**
- * @see UUID#variant()
- */
- public void test_variant() {
- UUID uuid = new UUID(0, 0x0000000000000000L);
- assertEquals(0, uuid.variant());
- uuid = new UUID(0, 0x7000000000000000L);
- assertEquals(0, uuid.variant());
- uuid = new UUID(0, 0x3000000000000000L);
- assertEquals(0, uuid.variant());
- uuid = new UUID(0, 0x1000000000000000L);
- assertEquals(0, uuid.variant());
-
- uuid = new UUID(0, 0x8000000000000000L);
- assertEquals(2, uuid.variant());
- uuid = new UUID(0, 0xB000000000000000L);
- assertEquals(2, uuid.variant());
- uuid = new UUID(0, 0xA000000000000000L);
- assertEquals(2, uuid.variant());
- uuid = new UUID(0, 0x9000000000000000L);
- assertEquals(2, uuid.variant());
-
- uuid = new UUID(0, 0xC000000000000000L);
- assertEquals(6, uuid.variant());
- uuid = new UUID(0, 0xD000000000000000L);
- assertEquals(6, uuid.variant());
-
- uuid = new UUID(0, 0xE000000000000000L);
- assertEquals(7, uuid.variant());
- uuid = new UUID(0, 0xF000000000000000L);
- assertEquals(7, uuid.variant());
- }
-
- /**
- * @see UUID#timestamp()
- */
- public void test_timestamp() {
- UUID uuid = new UUID(0x0000000000001000L, 0x8000000000000000L);
- assertEquals(0x0, uuid.timestamp());
-
- uuid = new UUID(0x7777777755551333L, 0x8000000000000000L);
- assertEquals(0x333555577777777L, uuid.timestamp());
-
- uuid = new UUID(0x0000000000000000L, 0x8000000000000000L);
- try {
- uuid.timestamp();
- fail("No UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {}
-
- uuid = new UUID(0x0000000000002000L, 0x8000000000000000L);
- try {
- uuid.timestamp();
- fail("No UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {}
- }
-
- /**
- * @see UUID#clockSequence()
- */
- public void test_clockSequence() {
- UUID uuid = new UUID(0x0000000000001000L, 0x8000000000000000L);
- assertEquals(0x0, uuid.clockSequence());
-
- uuid = new UUID(0x0000000000001000L, 0x8FFF000000000000L);
- assertEquals(0x0FFF, uuid.clockSequence());
-
- uuid = new UUID(0x0000000000001000L, 0xBFFF000000000000L);
- assertEquals(0x3FFF, uuid.clockSequence());
-
- uuid = new UUID(0x0000000000000000L, 0x8000000000000000L);
- try {
- uuid.clockSequence();
- fail("No UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {}
-
- uuid = new UUID(0x0000000000002000L, 0x8000000000000000L);
- try {
- uuid.clockSequence();
- fail("No UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {}
- }
-
- /**
- * @see UUID#node()
- */
- public void test_node() {
- UUID uuid = new UUID(0x0000000000001000L, 0x8000000000000000L);
- assertEquals(0x0, uuid.node());
-
- uuid = new UUID(0x0000000000001000L, 0x8000FFFFFFFFFFFFL);
- assertEquals(0xFFFFFFFFFFFFL, uuid.node());
-
- uuid = new UUID(0x0000000000000000L, 0x8000000000000000L);
- try {
- uuid.node();
- fail("No UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {}
-
- uuid = new UUID(0x0000000000002000L, 0x8000000000000000L);
- try {
- uuid.node();
- fail("No UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {}
- }
-
- /**
- * @see UUID#compareTo(UUID)
- */
- public void test_compareTo() {
- UUID uuid1 = new UUID(0, 0);
- assertEquals(0, uuid1.compareTo(uuid1));
- UUID uuid2 = new UUID(1, 0);
- assertEquals(-1, uuid1.compareTo(uuid2));
- assertEquals(1, uuid2.compareTo(uuid1));
-
- uuid2 = new UUID(0, 1);
- assertEquals(-1, uuid1.compareTo(uuid2));
- assertEquals(1, uuid2.compareTo(uuid1));
- }
-
- /**
- * @see UUID#hashCode()
- */
- public void test_hashCode() {
- UUID uuid = new UUID(0, 0);
- assertEquals(0, uuid.hashCode());
- uuid = new UUID(123, 123);
- UUID uuidClone = new UUID(123, 123);
- assertEquals(uuid.hashCode(), uuidClone.hashCode());
- }
-
- /**
- * @see UUID#equals(Object)
- */
- public void test_equalsObject() {
- UUID uuid1 = new UUID(0, 0);
- assertEquals(uuid1, uuid1);
- assertFalse(uuid1.equals(null));
- assertFalse(uuid1.equals("NOT A UUID"));
- UUID uuid2 = new UUID(0, 0);
- assertEquals(uuid1, uuid2);
- assertEquals(uuid2, uuid1);
-
- uuid1 = new UUID(0xf81d4fae7dec11d0L, 0xa76500a0c91e6bf6L);
- uuid2 = new UUID(0xf81d4fae7dec11d0L, 0xa76500a0c91e6bf6L);
- assertEquals(uuid1, uuid2);
- assertEquals(uuid2, uuid1);
-
- uuid2 = new UUID(0xf81d4fae7dec11d0L, 0xa76500a0c91e6bf7L);
- assertFalse(uuid1.equals(uuid2));
- assertFalse(uuid2.equals(uuid1));
- }
-
- /**
- * @see UUID#toString()
- */
- public void test_toString() {
- UUID uuid = new UUID(0xf81d4fae7dec11d0L, 0xa76500a0c91e6bf6L);
- String actual = uuid.toString();
- assertEquals("f81d4fae-7dec-11d0-a765-00a0c91e6bf6", actual);
-
- uuid = new UUID(0x0000000000001000L, 0x8000000000000000L);
- actual = uuid.toString();
- assertEquals("00000000-0000-1000-8000-000000000000", actual);
- }
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
- SerializationTest.verifySelf(new UUID(0xf81d4fae7dec11d0L,
- 0xa76500a0c91e6bf6L));
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
- SerializationTest.verifyGolden(this, new UUID(0xf81d4fae7dec11d0L,
- 0xa76500a0c91e6bf6L));
- }
-
- /**
- * @see UUID#randomUUID()
- */
- public void test_randomUUID() {
- UUID uuid = UUID.randomUUID();
- assertEquals(2, uuid.variant());
- assertEquals(4, uuid.version());
- }
-
- /**
- * @see UUID#nameUUIDFromBytes(byte[])
- */
- public void test_nameUUIDFromBytes() throws Exception {
- byte[] name = { (byte) 0x6b, (byte) 0xa7, (byte) 0xb8, (byte) 0x11,
- (byte) 0x9d, (byte) 0xad, (byte) 0x11, (byte) 0xd1,
- (byte) 0x80, (byte) 0xb4, (byte) 0x00, (byte) 0xc0,
- (byte) 0x4f, (byte) 0xd4, (byte) 0x30, (byte) 0xc8 };
-
- UUID uuid = UUID.nameUUIDFromBytes(name);
-
- assertEquals(2, uuid.variant());
- assertEquals(3, uuid.version());
-
- assertEquals(0xaff565bc2f771745L, uuid.getLeastSignificantBits());
- assertEquals(0x14cdb9b4de013faaL, uuid.getMostSignificantBits());
-
- uuid = UUID.nameUUIDFromBytes(new byte[0]);
- assertEquals(2, uuid.variant());
- assertEquals(3, uuid.version());
-
- assertEquals(0xa9800998ecf8427eL, uuid.getLeastSignificantBits());
- assertEquals(0xd41d8cd98f003204L, uuid.getMostSignificantBits());
-
- try {
- UUID.nameUUIDFromBytes(null);
- fail("No NPE");
- } catch (NullPointerException e) {}
- }
-
- /**
- * @see UUID#fromString(String)
- */
- public void test_fromString() {
- UUID actual = UUID.fromString("f81d4fae-7dec-11d0-a765-00a0c91e6bf6");
- UUID expected = new UUID(0xf81d4fae7dec11d0L, 0xa76500a0c91e6bf6L);
- assertEquals(expected, actual);
-
- assertEquals(2, actual.variant());
- assertEquals(1, actual.version());
- assertEquals(130742845922168750L, actual.timestamp());
- assertEquals(10085, actual.clockSequence());
- assertEquals(690568981494L, actual.node());
-
- actual = UUID.fromString("00000000-0000-1000-8000-000000000000");
- expected = new UUID(0x0000000000001000L, 0x8000000000000000L);
- assertEquals(expected, actual);
-
- assertEquals(2, actual.variant());
- assertEquals(1, actual.version());
- assertEquals(0L, actual.timestamp());
- assertEquals(0, actual.clockSequence());
- assertEquals(0L, actual.node());
-
- try {
- UUID.fromString(null);
- fail("No NPE");
- } catch (NullPointerException e) {}
-
- try {
- UUID.fromString("");
- fail("No IAE");
- } catch (IllegalArgumentException e) {}
-
- try {
- UUID.fromString("f81d4fae_7dec-11d0-a765-00a0c91e6bf6");
- fail("No IAE");
- } catch (IllegalArgumentException e) {}
-
- try {
- UUID.fromString("f81d4fae-7dec_11d0-a765-00a0c91e6bf6");
- fail("No IAE");
- } catch (IllegalArgumentException e) {}
-
- try {
- UUID.fromString("f81d4fae-7dec-11d0_a765-00a0c91e6bf6");
- fail("No IAE");
- } catch (IllegalArgumentException e) {}
-
- try {
- UUID.fromString("f81d4fae-7dec-11d0-a765_00a0c91e6bf6");
- fail("No IAE");
- } catch (IllegalArgumentException e) {}
- }
-
- /**
- * java.util.UUID#fromString(String)
- */
- public void test_fromString_LString_Exception() {
-
- UUID uuid = UUID.fromString("0-0-0-0-0");
-
- try {
- uuid = UUID.fromString("0-0-0-0-");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- uuid = UUID.fromString("-0-0-0-0-0");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- uuid = UUID.fromString("-0-0-0-0");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- uuid = UUID.fromString("-0-0-0-");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- uuid = UUID.fromString("0--0-0-0");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- uuid = UUID.fromString("0-0-0-0-");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- uuid = UUID.fromString("-1-0-0-0-0");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- uuid = UUID.fromString("123456789-0-0-0-0");
- assertEquals(0x2345678900000000L, uuid.getMostSignificantBits());
- assertEquals(0x0L, uuid.getLeastSignificantBits());
-
- uuid = UUID.fromString("111123456789-0-0-0-0");
- assertEquals(0x2345678900000000L, uuid.getMostSignificantBits());
- assertEquals(0x0L, uuid.getLeastSignificantBits());
-
- uuid = UUID.fromString("7fffffffffffffff-0-0-0-0");
- assertEquals(0xffffffff00000000L, uuid.getMostSignificantBits());
- assertEquals(0x0L, uuid.getLeastSignificantBits());
-
- try {
- uuid = UUID.fromString("8000000000000000-0-0-0-0");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- // expected
- }
-
- uuid = UUID
- .fromString("7fffffffffffffff-7fffffffffffffff-7fffffffffffffff-0-0");
- assertEquals(0xffffffffffffffffL, uuid.getMostSignificantBits());
- assertEquals(0x0L, uuid.getLeastSignificantBits());
-
- uuid = UUID.fromString("0-0-0-7fffffffffffffff-7fffffffffffffff");
- assertEquals(0x0L, uuid.getMostSignificantBits());
- assertEquals(0xffffffffffffffffL, uuid.getLeastSignificantBits());
-
- try {
- uuid = UUID.fromString("0-0-0-8000000000000000-0");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- uuid = UUID.fromString("0-0-0-0-8000000000000000");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/UnknownFormatFlagsExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/UnknownFormatFlagsExceptionTest.java
deleted file mode 100644
index 01e02be..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/UnknownFormatFlagsExceptionTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.io.Serializable;
-import java.util.UnknownFormatFlagsException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class UnknownFormatFlagsExceptionTest extends TestCase {
-
- /**
- * java.util.UnknownFormatFlagsException#UnknownFormatFlagsException(String)
- */
- public void test_unknownFormatFlagsException() {
-
- try {
- new UnknownFormatFlagsException(null);
- fail("should throw NullPointerExcepiton");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * java.util.UnknownFormatFlagsException#getFlags()
- */
- public void test_getFlags() {
- String s = "MYTESTSTRING";
- UnknownFormatFlagsException UnknownFormatFlagsException = new UnknownFormatFlagsException(
- s);
- assertEquals(s, UnknownFormatFlagsException.getFlags());
- }
-
- /**
- * java.util.UnknownFormatFlagsException#getMessage()
- */
- public void test_getMessage() {
- String s = "MYTESTSTRING";
- UnknownFormatFlagsException UnknownFormatFlagsException = new UnknownFormatFlagsException(
- s);
- assertNotNull(UnknownFormatFlagsException.getMessage());
- }
-
- // comparator for comparing UnknownFormatFlagsException objects
- private static final SerializableAssert exComparator = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- UnknownFormatFlagsException initEx = (UnknownFormatFlagsException) initial;
- UnknownFormatFlagsException desrEx = (UnknownFormatFlagsException) deserialized;
-
- assertEquals("Flags", initEx.getFlags(), desrEx.getFlags());
- }
- };
-
- /**
- * serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new UnknownFormatFlagsException(
- "MYTESTSTRING"), exComparator);
- }
-
- /**
- * serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new UnknownFormatFlagsException(
- "MYTESTSTRING"), exComparator);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java
deleted file mode 100644
index 928c5a9..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/VectorTest.java
+++ /dev/null
@@ -1,1308 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Vector;
-
-import tests.support.Support_ListTest;
-
-public class VectorTest extends junit.framework.TestCase {
-
- private Vector tVector = new Vector();
-
- Object[] objArray;
-
- private String vString = "[Test 0, Test 1, Test 2, Test 3, Test 4, Test 5, Test 6, Test 7, Test 8, Test 9, Test 10, Test 11, Test 12, Test 13, Test 14, Test 15, Test 16, Test 17, Test 18, Test 19, Test 20, Test 21, Test 22, Test 23, Test 24, Test 25, Test 26, Test 27, Test 28, Test 29, Test 30, Test 31, Test 32, Test 33, Test 34, Test 35, Test 36, Test 37, Test 38, Test 39, Test 40, Test 41, Test 42, Test 43, Test 44, Test 45, Test 46, Test 47, Test 48, Test 49, Test 50, Test 51, Test 52, Test 53, Test 54, Test 55, Test 56, Test 57, Test 58, Test 59, Test 60, Test 61, Test 62, Test 63, Test 64, Test 65, Test 66, Test 67, Test 68, Test 69, Test 70, Test 71, Test 72, Test 73, Test 74, Test 75, Test 76, Test 77, Test 78, Test 79, Test 80, Test 81, Test 82, Test 83, Test 84, Test 85, Test 86, Test 87, Test 88, Test 89, Test 90, Test 91, Test 92, Test 93, Test 94, Test 95, Test 96, Test 97, Test 98, Test 99]";
-
- /**
- * java.util.Vector#Vector()
- */
- public void test_Constructor() {
- // Test for method java.util.Vector()
-
- Vector tv = new Vector(100);
- for (int i = 0; i < 100; i++)
- tv.addElement(new Integer(i));
- new Support_ListTest("", tv).runTest();
-
- tv = new Vector(200);
- for (int i = -50; i < 150; i++)
- tv.addElement(new Integer(i));
- new Support_ListTest("", tv.subList(50, 150)).runTest();
-
- Vector v = new Vector();
- assertEquals("Vector creation failed", 0, v.size());
- assertEquals("Wrong capacity", 10, v.capacity());
- }
-
- /**
- * java.util.Vector#Vector(int)
- */
- public void test_ConstructorI() {
- // Test for method java.util.Vector(int)
-
- Vector v = new Vector(100);
- assertEquals("Vector creation failed", 0, v.size());
- assertEquals("Wrong capacity", 100, v.capacity());
- }
-
- /**
- * java.util.Vector#Vector(int, int)
- */
- public void test_ConstructorII() {
- // Test for method java.util.Vector(int, int)
-
- Vector v = new Vector(2, 10);
- v.addElement(new Object());
- v.addElement(new Object());
- v.addElement(new Object());
-
- assertEquals("Failed to inc capacity by proper amount",
- 12, v.capacity());
-
- Vector grow = new Vector(3, -1);
- grow.addElement("one");
- grow.addElement("two");
- grow.addElement("three");
- grow.addElement("four");
- assertEquals("Wrong size", 4, grow.size());
- assertEquals("Wrong capacity", 6, grow.capacity());
-
- Vector emptyVector = new Vector(0, 0);
- emptyVector.addElement("one");
- assertEquals("Wrong size", 1, emptyVector.size());
- emptyVector.addElement("two");
- emptyVector.addElement("three");
- assertEquals("Wrong size", 3, emptyVector.size());
-
- try {
- Vector negativeVector = new Vector(-1, 0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#Vector(java.util.Collection)
- */
- public void test_ConstructorLjava_util_Collection() {
- // Test for method java.util.Vector(java.util.Collection)
- Collection l = new LinkedList();
- for (int i = 0; i < 100; i++)
- l.add("Test " + i);
- Vector myVector = new Vector(l);
- assertTrue("Vector is not correct size",
- myVector.size() == objArray.length);
- for (int counter = 0; counter < objArray.length; counter++)
- assertTrue("Vector does not contain correct elements", myVector
- .contains(((List) l).get(counter)));
- }
-
- /**
- * java.util.Vector#add(int, java.lang.Object)
- */
- public void test_addILjava_lang_Object() {
- // Test for method void java.util.Vector.add(int, java.lang.Object)
- Object o = new Object();
- Object prev = tVector.get(45);
- tVector.add(45, o);
- assertTrue("Failed to add Object", tVector.get(45) == o);
- assertTrue("Failed to fix-up existing indices", tVector.get(46) == prev);
- assertEquals("Wrong size after add", 101, tVector.size());
-
- prev = tVector.get(50);
- tVector.add(50, null);
- assertNull("Failed to add null", tVector.get(50));
- assertTrue("Failed to fix-up existing indices after adding null",
- tVector.get(51) == prev);
- assertEquals("Wrong size after add", 102, tVector.size());
- }
-
- /**
- * java.util.Vector#add(java.lang.Object)
- */
- public void test_addLjava_lang_Object() {
- // Test for method boolean java.util.Vector.add(java.lang.Object)
- Object o = new Object();
- tVector.add(o);
- assertTrue("Failed to add Object", tVector.lastElement() == o);
- assertEquals("Wrong size after add", 101, tVector.size());
-
- tVector.add(null);
- assertNull("Failed to add null", tVector.lastElement());
- assertEquals("Wrong size after add", 102, tVector.size());
- }
-
- /**
- * java.util.Vector#addAll(int, java.util.Collection)
- */
- public void test_addAllILjava_util_Collection() {
- // Test for method boolean java.util.Vector.addAll(int,
- // java.util.Collection)
- Collection l = new LinkedList();
- for (int i = 0; i < 100; i++)
- l.add("Test " + i);
- Vector v = new Vector();
- tVector.addAll(50, l);
- for (int i = 50; i < 100; i++)
- assertTrue("Failed to add all elements",
- tVector.get(i) == ((List) l).get(i - 50));
- v = new Vector();
- v.add("one");
- int r = 0;
- try {
- v.addAll(3, Arrays.asList(new String[] { "two", "three" }));
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- } catch (IndexOutOfBoundsException e) {
- r = 2;
- }
- assertTrue("Invalid add: " + r, r == 1);
- l = new LinkedList();
- l.add(null);
- l.add("gah");
- l.add(null);
- tVector.addAll(50, l);
- assertNull("Wrong element at position 50--wanted null",
- tVector.get(50));
- assertEquals("Wrong element at position 51--wanted 'gah'", "gah", tVector
- .get(51));
- assertNull("Wrong element at position 52--wanted null",
- tVector.get(52));
-
- try {
- v.addAll(0, null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Excepted
- }
-
- try {
- v.addAll(-1, null);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#addAll(java.util.Collection)
- */
- public void test_addAllLjava_util_Collection() {
- // Test for method boolean java.util.Vector.addAll(java.util.Collection)
- Vector v = new Vector();
- Collection l = new LinkedList();
- for (int i = 0; i < 100; i++)
- l.add("Test " + i);
- v.addAll(l);
- assertTrue("Failed to add all elements", tVector.equals(v));
-
- v.addAll(l);
- int vSize = tVector.size();
- for (int counter = vSize - 1; counter >= 0; counter--)
- assertTrue("Failed to add elements correctly", v.get(counter) == v
- .get(counter + vSize));
-
- l = new LinkedList();
- l.add(null);
- l.add("gah");
- l.add(null);
- tVector.addAll(l);
- assertNull("Wrong element at 3rd last position--wanted null", tVector
- .get(vSize));
- assertEquals("Wrong element at 2nd last position--wanted 'gah'", "gah", tVector
- .get(vSize + 1));
- assertNull("Wrong element at last position--wanted null", tVector
- .get(vSize + 2));
-
- try {
- v.addAll(null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#addElement(java.lang.Object)
- */
- public void test_addElementLjava_lang_Object() {
- // Test for method void java.util.Vector.addElement(java.lang.Object)
- Vector v = vectorClone(tVector);
- v.addElement("Added Element");
- assertTrue("Failed to add element", v.contains("Added Element"));
- assertEquals("Added Element to wrong slot", "Added Element", ((String) v.elementAt(100))
- );
- v.addElement(null);
- assertTrue("Failed to add null", v.contains(null));
- assertNull("Added null to wrong slot", v.elementAt(101));
- }
-
- /**
- * java.util.Vector#addElement(java.lang.Object)
- */
- public void test_addElementLjava_lang_Object_subtest0() {
- // Test for method void java.util.Vector.addElement(java.lang.Object)
- Vector v = vectorClone(tVector);
- v.addElement("Added Element");
- assertTrue("Failed to add element", v.contains("Added Element"));
- assertEquals("Added Element to wrong slot", "Added Element", ((String) v.elementAt(100))
- );
- v.addElement(null);
- assertTrue("Failed to add null", v.contains(null));
- assertNull("Added null to wrong slot", v.elementAt(101));
- }
-
- /**
- * java.util.Vector#capacity()
- */
- public void test_capacity() {
- // Test for method int java.util.Vector.capacity()
-
- Vector v = new Vector(9);
- assertEquals("Incorrect capacity returned", 9, v.capacity());
- }
-
- /**
- * java.util.Vector#clear()
- */
- public void test_clear() {
- // Test for method void java.util.Vector.clear()
- Vector orgVector = vectorClone(tVector);
- tVector.clear();
- assertEquals("a) Cleared Vector has non-zero size", 0, tVector.size());
- Enumeration e = orgVector.elements();
- while (e.hasMoreElements())
- assertTrue("a) Cleared vector contained elements", !tVector
- .contains(e.nextElement()));
-
- tVector.add(null);
- tVector.clear();
- assertEquals("b) Cleared Vector has non-zero size", 0, tVector.size());
- e = orgVector.elements();
- while (e.hasMoreElements())
- assertTrue("b) Cleared vector contained elements", !tVector
- .contains(e.nextElement()));
- }
-
- /**
- * java.util.Vector#clone()
- */
- public void test_clone() {
- // Test for method java.lang.Object java.util.Vector.clone()
- tVector.add(25, null);
- tVector.add(75, null);
- Vector v = (Vector) tVector.clone();
- Enumeration orgNum = tVector.elements();
- Enumeration cnum = v.elements();
-
- while (orgNum.hasMoreElements()) {
- assertTrue("Not enough elements copied", cnum.hasMoreElements());
- assertTrue("Vector cloned improperly, elements do not match",
- orgNum.nextElement() == cnum.nextElement());
- }
- assertTrue("Not enough elements copied", !cnum.hasMoreElements());
-
- }
-
- /**
- * java.util.Vector#contains(java.lang.Object)
- */
- public void test_containsLjava_lang_Object() {
- // Test for method boolean java.util.Vector.contains(java.lang.Object)
- assertTrue("Did not find element", tVector.contains("Test 42"));
- assertTrue("Found bogus element", !tVector.contains("Hello"));
- assertTrue(
- "Returned true looking for null in vector without null element",
- !tVector.contains(null));
- tVector.insertElementAt(null, 20);
- assertTrue(
- "Returned false looking for null in vector with null element",
- tVector.contains(null));
- }
-
- /**
- * java.util.Vector#containsAll(java.util.Collection)
- */
- public void test_containsAllLjava_util_Collection() {
- // Test for method boolean
- // java.util.Vector.containsAll(java.util.Collection)
- Collection s = new HashSet();
- for (int i = 0; i < 100; i++)
- s.add("Test " + i);
-
- assertTrue("Returned false for valid collection", tVector
- .containsAll(s));
- s.add(null);
- assertTrue("Returned true for invlaid collection containing null",
- !tVector.containsAll(s));
- tVector.add(25, null);
- assertTrue("Returned false for valid collection containing null",
- tVector.containsAll(s));
- s = new HashSet();
- s.add(new Object());
- assertTrue("Returned true for invalid collection", !tVector
- .containsAll(s));
- }
-
- /**
- * java.util.Vector#copyInto(java.lang.Object[])
- */
- public void test_copyInto$Ljava_lang_Object() {
- // Test for method void java.util.Vector.copyInto(java.lang.Object [])
-
- Object[] a = new Object[100];
- tVector.setElementAt(null, 20);
- tVector.copyInto(a);
-
- for (int i = 0; i < 100; i++)
- assertTrue("copyInto failed", a[i] == tVector.elementAt(i));
- }
-
- /**
- * java.util.Vector#elementAt(int)
- */
- public void test_elementAtI() {
- // Test for method java.lang.Object java.util.Vector.elementAt(int)
- assertEquals("Incorrect element returned", "Test 18", ((String) tVector
- .elementAt(18)));
- tVector.setElementAt(null, 20);
- assertNull("Incorrect element returned--wanted null", tVector
- .elementAt(20));
-
- }
-
- /**
- * java.util.Vector#elements()
- */
- public void test_elements() {
- // Test for method java.util.Enumeration java.util.Vector.elements()
- tVector.insertElementAt(null, 20);
- Enumeration e = tVector.elements();
- int i = 0;
- while (e.hasMoreElements()) {
- assertTrue("Enumeration returned incorrect element at pos: " + i, e
- .nextElement() == tVector.elementAt(i));
- i++;
- }
- assertTrue("Invalid enumeration", i == tVector.size());
- }
-
- /**
- * java.util.Vector#elements()
- */
- public void test_elements_subtest0() {
- final int iterations = 10000;
- final Vector v = new Vector();
- Thread t1 = new Thread() {
- public void run() {
- for (int i = 0; i < iterations; i++) {
- synchronized (v) {
- v.addElement(String.valueOf(i));
- v.removeElementAt(0);
- }
- }
- }
- };
- t1.start();
- for (int i = 0; i < iterations; i++) {
- Enumeration en = v.elements();
- try {
- while (true) {
- Object result = en.nextElement();
- if (result == null) {
- fail("Null result: " + i);
- }
- }
- } catch (NoSuchElementException e) {
- }
- }
- }
-
- /**
- * java.util.Vector#ensureCapacity(int)
- */
- public void test_ensureCapacityI() {
- // Test for method void java.util.Vector.ensureCapacity(int)
-
- Vector v = new Vector(9);
- v.ensureCapacity(20);
- assertEquals("ensureCapacity failed to set correct capacity", 20, v
- .capacity());
- v = new Vector(100);
- assertEquals("ensureCapacity reduced capacity", 100, v.capacity());
-
- v.ensureCapacity(150);
- assertEquals(
- "ensuieCapacity failed to set to be twice the old capacity",
- 200, v.capacity());
-
- v = new Vector(9, -1);
- v.ensureCapacity(20);
- assertEquals("ensureCapacity failed to set to be minCapacity", 20, v
- .capacity());
- v.ensureCapacity(15);
- assertEquals("ensureCapacity reduced capacity", 20, v.capacity());
- v.ensureCapacity(35);
- assertEquals(
- "ensuieCapacity failed to set to be twice the old capacity",
- 40, v.capacity());
-
- v = new Vector(9, 4);
- v.ensureCapacity(11);
- assertEquals("ensureCapacity failed to set correct capacity", 13, v
- .capacity());
- v.ensureCapacity(5);
- assertEquals("ensureCapacity reduced capacity", 13, v.capacity());
- v.ensureCapacity(20);
- assertEquals(
- "ensuieCapacity failed to set to be twice the old capacity",
- 20, v.capacity());
- }
-
- /**
- * java.util.Vector#equals(java.lang.Object)
- */
- public void test_equalsLjava_lang_Object() {
- // Test for method boolean java.util.Vector.equals(java.lang.Object)
- Vector v = new Vector();
- for (int i = 0; i < 100; i++)
- v.addElement("Test " + i);
- assertTrue("a) Equal vectors returned false", tVector.equals(v));
- v.addElement(null);
- assertTrue("b) UnEqual vectors returned true", !tVector.equals(v));
- tVector.addElement(null);
- assertTrue("c) Equal vectors returned false", tVector.equals(v));
- tVector.removeElementAt(22);
- assertTrue("d) UnEqual vectors returned true", !tVector.equals(v));
- assertTrue("e) Equal vectors returned false", tVector.equals(tVector));
- assertFalse("f) UnEqual vectors returned true", tVector
- .equals(new Object()));
- assertFalse("g) Unequal vectors returned true", tVector.equals(null));
- }
-
- /**
- * java.util.Vector#firstElement()
- */
- public void test_firstElement() {
- // Test for method java.lang.Object java.util.Vector.firstElement()
- assertEquals("Returned incorrect firstElement", "Test 0", tVector.firstElement()
- );
- tVector.insertElementAt(null, 0);
- assertNull("Returned incorrect firstElement--wanted null", tVector
- .firstElement());
-
- Vector v = new Vector();
- try {
- v.firstElement();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#get(int)
- */
- public void test_getI() {
- // Test for method java.lang.Object java.util.Vector.get(int)
- assertEquals("Get returned incorrect object",
- "Test 80", tVector.get(80));
- tVector.add(25, null);
- assertNull("Returned incorrect element--wanted null",
- tVector.get(25));
- }
-
- /**
- * java.util.Vector#hashCode()
- */
- public void test_hashCode() {
- // Test for method int java.util.Vector.hashCode()
- int hashCode = 1; // one
- tVector.insertElementAt(null, 20);
- for (int i = 0; i < tVector.size(); i++) {
- Object obj = tVector.elementAt(i);
- hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
- }
- assertTrue("Incorrect hashCode returned. Wanted: " + hashCode
- + " got: " + tVector.hashCode(), tVector.hashCode() == hashCode);
- }
-
- /**
- * java.util.Vector#indexOf(java.lang.Object)
- */
- public void test_indexOfLjava_lang_Object() {
- // Test for method int java.util.Vector.indexOf(java.lang.Object)
- assertEquals("Incorrect index returned", 10, tVector.indexOf("Test 10"));
- assertEquals("Index returned for invalid Object", -1, tVector
- .indexOf("XXXXXXXXXXX"));
- tVector.setElementAt(null, 20);
- tVector.setElementAt(null, 40);
- assertTrue("Incorrect indexOf returned for null: "
- + tVector.indexOf(null), tVector.indexOf(null) == 20);
- }
-
- /**
- * java.util.Vector#indexOf(java.lang.Object, int)
- */
- public void test_indexOfLjava_lang_ObjectI() {
- // Test for method int java.util.Vector.indexOf(java.lang.Object, int)
- assertEquals("Failed to find correct index", tVector.indexOf("Test 98",
- 50), 98);
- assertTrue("Found index of bogus element", (tVector.indexOf(
- "Test 1001", 50) == -1));
- tVector.setElementAt(null, 20);
- tVector.setElementAt(null, 40);
- tVector.setElementAt(null, 60);
- assertTrue("a) Incorrect indexOf returned for null: "
- + tVector.indexOf(null, 25), tVector.indexOf(null, 25) == 40);
- assertTrue("b) Incorrect indexOf returned for null: "
- + tVector.indexOf(null, 20), tVector.indexOf(null, 20) == 20);
- try {
- tVector.indexOf("Test 98", -1);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
-
- }
- assertEquals(-1, tVector.indexOf("Test 98", 1000));
- assertEquals(-1, tVector.indexOf("Test 98", Integer.MAX_VALUE));
- assertEquals(-1, tVector.indexOf("Test 98", tVector.size()));
- assertEquals(98, tVector.indexOf("Test 98", 0));
- try {
- tVector.indexOf("Test 98", Integer.MIN_VALUE);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
-
- }
- }
-
- /**
- * java.util.Vector#insertElementAt(java.lang.Object, int)
- */
- public void test_insertElementAtLjava_lang_ObjectI() {
- // Test for method void
- // java.util.Vector.insertElementAt(java.lang.Object, int)
- Vector v = vectorClone(tVector);
- String prevElement = (String) v.elementAt(99);
- v.insertElementAt("Inserted Element", 99);
- assertEquals("Element not inserted", "Inserted Element", ((String) v.elementAt(99))
- );
- assertTrue("Elements shifted incorrectly", ((String) v.elementAt(100))
- .equals(prevElement));
- v.insertElementAt(null, 20);
- assertNull("null not inserted", v.elementAt(20));
-
- try {
- tVector.insertElementAt("Inserted Element", -1);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- tVector.insertElementAt(null, -1);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- tVector.insertElementAt("Inserted Element", tVector.size() + 1);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- tVector.insertElementAt(null, tVector.size() + 1);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#isEmpty()
- */
- public void test_isEmpty() {
- // Test for method boolean java.util.Vector.isEmpty()Vector
- Vector v = new java.util.Vector();
- assertTrue("Empty vector returned false", v.isEmpty());
- v.addElement(new Object());
- assertTrue("non-Empty vector returned true", !v.isEmpty());
- }
-
- /**
- * java.util.Vector#isEmpty()
- */
- public void test_isEmpty_subtest0() {
- final Vector v = new Vector();
- v.addElement("initial");
- Thread t1 = new Thread() {
- public void run() {
- while (!v.isEmpty())
- ;
- v.addElement("final");
- }
- };
- t1.start();
- for (int i = 0; i < 10000; i++) {
- synchronized (v) {
- v.removeElementAt(0);
- v.addElement(String.valueOf(i));
- }
- int size;
- if ((size = v.size()) != 1) {
- String result = "Size is not 1: " + size + " " + v;
- // terminate the thread
- v.removeAllElements();
- fail(result);
- }
- }
- // terminate the thread
- v.removeElementAt(0);
- }
-
- /**
- * java.util.Vector#lastElement()
- */
- public void test_lastElement() {
- // Test for method java.lang.Object java.util.Vector.lastElement()
- assertEquals("Incorrect last element returned", "Test 99", tVector.lastElement()
- );
- tVector.addElement(null);
- assertNull("Incorrect last element returned--wanted null", tVector
- .lastElement());
-
- Vector vector = new Vector();
- try {
- vector.lastElement();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#lastIndexOf(java.lang.Object)
- */
- public void test_lastIndexOfLjava_lang_Object() {
- // Test for method int java.util.Vector.lastIndexOf(java.lang.Object)
- Vector v = new Vector(9);
- for (int i = 0; i < 9; i++)
- v.addElement("Test");
- v.addElement("z");
- assertEquals("Failed to return correct index", 8, v.lastIndexOf("Test"));
- tVector.setElementAt(null, 20);
- tVector.setElementAt(null, 40);
- assertTrue("Incorrect lastIndexOf returned for null: "
- + tVector.lastIndexOf(null), tVector.lastIndexOf(null) == 40);
- }
-
- /**
- * java.util.Vector#lastIndexOf(java.lang.Object, int)
- */
- public void test_lastIndexOfLjava_lang_ObjectI() {
- // Test for method int java.util.Vector.lastIndexOf(java.lang.Object,
- // int)
- assertEquals("Failed to find object",
- 0, tVector.lastIndexOf("Test 0", 0));
- assertTrue("Found Object outside of index", (tVector.lastIndexOf(
- "Test 0", 10) > -1));
- tVector.setElementAt(null, 20);
- tVector.setElementAt(null, 40);
- tVector.setElementAt(null, 60);
- assertTrue("Incorrect lastIndexOf returned for null: "
- + tVector.lastIndexOf(null, 15),
- tVector.lastIndexOf(null, 15) == -1);
- assertTrue("Incorrect lastIndexOf returned for null: "
- + tVector.lastIndexOf(null, 45),
- tVector.lastIndexOf(null, 45) == 40);
-
- assertEquals(-1, tVector.lastIndexOf("Test 98", -1));
- assertEquals(-1, tVector.lastIndexOf("Test 98", 0));
- try {
- assertEquals(-1, tVector.lastIndexOf("Test 98", 1000));
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- }
- try {
- assertEquals(-1, tVector.lastIndexOf("Test 98", Integer.MAX_VALUE));
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- }
- try {
- tVector.lastIndexOf("Test 98", tVector.size());
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- }
- try {
- tVector.indexOf("Test 98", Integer.MIN_VALUE);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- }
-
- /**
- * java.util.Vector#remove(int)
- */
- public void test_removeI() {
- // Test for method java.lang.Object java.util.Vector.remove(int)
- Object removeElement = tVector.get(36);
- Object result = tVector.remove(36);
- assertFalse("Contained element after remove", tVector
- .contains("Test 36"));
- assertEquals("Should return the element that was removed",
- removeElement, result);
- assertEquals("Failed to decrement size after remove",
- 99, tVector.size());
- tVector.add(20, null);
- removeElement = tVector.get(19);
- result = tVector.remove(19);
- assertNull("Didn't move null element over", tVector.get(19));
- assertEquals("Should return the element that was removed",
- removeElement, result);
- removeElement = tVector.get(19);
- result = tVector.remove(19);
- assertNotNull("Didn't remove null element", tVector.get(19));
- assertEquals("Should return the element that was removed",
- removeElement, result);
- assertEquals("Failed to decrement size after removing null", 98, tVector
- .size());
-
- try {
- tVector.remove(-1);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- tVector.remove(tVector.size());
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#remove(java.lang.Object)
- */
- public void test_removeLjava_lang_Object() {
- // Test for method boolean java.util.Vector.remove(java.lang.Object)
- tVector.remove("Test 0");
- assertTrue("Contained element after remove", !tVector
- .contains("Test 0"));
- assertEquals("Failed to decrement size after remove",
- 99, tVector.size());
- tVector.add(null);
- tVector.remove(null);
- assertTrue("Contained null after remove", !tVector.contains(null));
- assertEquals("Failed to decrement size after removing null", 99, tVector
- .size());
- }
-
- /**
- * java.util.Vector#removeAll(java.util.Collection)
- */
- public void test_removeAllLjava_util_Collection() {
- // Test for method boolean
- // java.util.Vector.removeAll(java.util.Collection)
- Vector v = new Vector();
- Collection l = new LinkedList();
- for (int i = 0; i < 5; i++)
- l.add("Test " + i);
- v.addElement(l);
-
- Collection s = new HashSet();
- Object o;
- s.add(o = v.firstElement());
- v.removeAll(s);
- assertTrue("Failed to remove items in collection", !v.contains(o));
- v.removeAll(l);
- assertTrue("Failed to remove all elements", v.isEmpty());
-
- v.add(null);
- v.add(null);
- v.add("Boom");
- v.removeAll(s);
- assertEquals("Should not have removed any elements", 3, v.size());
- l = new LinkedList();
- l.add(null);
- v.removeAll(l);
- assertEquals("Should only have one element", 1, v.size());
- assertEquals("Element should be 'Boom'", "Boom", v.firstElement());
- }
-
- /**
- * java.util.Vector#removeAllElements()
- */
- public void test_removeAllElements() {
- // Test for method void java.util.Vector.removeAllElements()
- Vector v = vectorClone(tVector);
- v.removeAllElements();
- assertEquals("Failed to remove all elements", 0, v.size());
- }
-
- /**
- * java.util.Vector#removeElement(java.lang.Object)
- */
- public void test_removeElementLjava_lang_Object() {
- // Test for method boolean
- // java.util.Vector.removeElement(java.lang.Object)
- Vector v = vectorClone(tVector);
- v.removeElement("Test 98");
- assertEquals("Element not removed", "Test 99", ((String) v.elementAt(98))
- );
- assertTrue("Vector is wrong size after removal: " + v.size(),
- v.size() == 99);
- tVector.addElement(null);
- v.removeElement(null);
- assertTrue("Vector is wrong size after removing null: " + v.size(), v
- .size() == 99);
- }
-
- /**
- * java.util.Vector#removeElementAt(int)
- */
- public void test_removeElementAtI() {
- // Test for method void java.util.Vector.removeElementAt(int)
- Vector v = vectorClone(tVector);
- int size = v.size();
- v.removeElementAt(50);
- assertEquals("Failed to remove element", -1, v.indexOf("Test 50", 0));
- assertEquals("Test 51", v.get(50));
- assertEquals(size - 1, v.size());
-
- tVector.insertElementAt(null, 60);
- assertNull(tVector.get(60));
- size = tVector.size();
- tVector.removeElementAt(60);
- assertNotNull("Element at 60 should not be null after removal", tVector
- .elementAt(60));
- assertEquals(size - 1, tVector.size());
-
- try {
- tVector.removeElementAt(-1);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- tVector.removeElementAt(tVector.size());
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
- }
-
- /**
- * {@link java.util.Vector#removeRange(int, int)}
- */
- public void test_removeRange() {
- MockVector myVector = new MockVector();
- myVector.removeRange(0, 0);
-
- try {
- myVector.removeRange(0, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Excepted
- }
-
- int[] data = { 1, 2, 3, 4 };
- for (int i = 0; i < data.length; i++) {
- myVector.add(i, data[i]);
- }
-
- myVector.removeRange(0, 2);
- assertEquals(data[2], myVector.get(0));
- assertEquals(data[3], myVector.get(1));
-
- try {
- myVector.removeRange(-1, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- myVector.removeRange(0, -1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- myVector.removeRange(1, 0);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- myVector.removeRange(2, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#retainAll(java.util.Collection)
- */
- public void test_retainAllLjava_util_Collection() {
- // Test for method boolean
- // java.util.Vector.retainAll(java.util.Collection)
- Object o = tVector.firstElement();
- tVector.add(null);
- Collection s = new HashSet();
- s.add(o);
- s.add(null);
- tVector.retainAll(s);
- assertTrue("Retained items other than specified", tVector.size() == 2
- && tVector.contains(o) && tVector.contains(null));
- }
-
- /**
- * java.util.Vector#set(int, java.lang.Object)
- */
- public void test_setILjava_lang_Object() {
- // Test for method java.lang.Object java.util.Vector.set(int,
- // java.lang.Object)
- Object o = new Object();
- Object previous = tVector.get(23);
- Object result = tVector.set(23, o);
- assertEquals(
- "Should return the element previously at the specified position",
- previous, result);
- assertTrue("Failed to set Object", tVector.get(23) == o);
-
- previous = tVector.get(0);
- result = tVector.set(0, null);
- assertEquals(
- "Should return the element previously at the specified position",
- previous, result);
- assertNull("Failed to set Object", tVector.get(0));
-
- try {
- tVector.set(-1, o);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- tVector.set(-1, null);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- tVector.set(tVector.size(), o);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- tVector.set(tVector.size(), null);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#setElementAt(java.lang.Object, int)
- */
- public void test_setElementAtLjava_lang_ObjectI() {
- // Test for method void java.util.Vector.setElementAt(java.lang.Object,
- // int)
- Vector v = vectorClone(tVector);
- v.setElementAt("Inserted Element", 99);
- assertEquals("Element not set", "Inserted Element", ((String) v.elementAt(99))
- );
-
- v.setElementAt(null, 0);
- assertNull("Null element not set", v.elementAt(0));
-
- try {
- v.setElementAt("Inserted Element", -1);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- v.setElementAt(null, -1);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- v.setElementAt("Inserted Element", v.size());
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
-
- try {
- v.setElementAt(null, v.size());
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#setSize(int)
- */
- public void test_setSizeI() {
- // Test for method void java.util.Vector.setSize(int)
- Vector v = vectorClone(tVector);
- int oldSize = v.size();
- Object preElement = v.get(10);
- v.setSize(10);
- assertEquals("Failed to set size", 10, v.size());
- assertEquals(
- "All components at index newSize and greater should be discarded",
- -1, v.indexOf(preElement));
- try {
- v.get(oldSize - 1);
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted;
- }
-
- oldSize = v.size();
- v.setSize(20);
- assertEquals("Failed to set size", 20, v.size());
- for (int i = oldSize; i < v.size(); i++) {
- assertNull(v.get(i));
- }
-
- try {
- v.setSize(-1);
- fail("Should throw ArrayIndexOutOfBoundsException");
- } catch (ArrayIndexOutOfBoundsException e) {
- // Excepted
- }
- }
-
- /**
- * java.util.Vector#size()
- */
- public void test_size() {
- // Test for method int java.util.Vector.size()
- assertEquals("Returned incorrect size", 100, tVector.size());
-
- final Vector v = new Vector();
- v.addElement("initial");
- Thread t1 = new Thread() {
- public void run() {
- while (v.size() > 0)
- ;
- v.addElement("final");
- }
- };
- t1.start();
- for (int i = 0; i < 10000; i++) {
- synchronized (v) {
- v.removeElementAt(0);
- v.addElement(String.valueOf(i));
- }
- int size;
- if ((size = v.size()) != 1) {
- String result = "Size is not 1: " + size + " " + v;
- // terminate the thread
- v.removeAllElements();
- fail(result);
- }
- }
- // terminate the thread
- v.removeElementAt(0);
- }
-
- /**
- * java.util.Vector#subList(int, int)
- */
- public void test_subListII() {
- // Test for method java.util.List java.util.Vector.subList(int, int)
- List sl = tVector.subList(10, 25);
- assertEquals("Returned sublist of incorrect size", 15, sl.size());
- for (int i = 10; i < 25; i++)
- assertTrue("Returned incorrect sublist", sl
- .contains(tVector.get(i)));
-
- assertEquals("Not synchronized random access", "java.util.Collections$SynchronizedRandomAccessList", sl.getClass().getName()
- );
-
- }
-
- /**
- * java.util.Vector#toArray()
- */
- public void test_toArray() {
- // Test for method java.lang.Object [] java.util.Vector.toArray()
- assertTrue("Returned incorrect array", Arrays.equals(objArray, tVector
- .toArray()));
- }
-
- /**
- * java.util.Vector#toArray(java.lang.Object[])
- */
- public void test_toArray$Ljava_lang_Object() {
- // Test for method java.lang.Object []
- // java.util.Vector.toArray(java.lang.Object [])
- Object[] o = new Object[1000];
- Object f = new Object();
- for (int i = 0; i < o.length; i++)
- o[i] = f;
- tVector.toArray(o);
- assertNull("Failed to set slot to null", o[100]);
- for (int i = 0; i < tVector.size(); i++)
- assertTrue("Returned incorrect array", tVector.elementAt(i) == o[i]);
- }
-
-
-
- class SubVector<E> extends Vector<E> {
-
- private static final long serialVersionUID = 1L;
-
- public SubVector() {
- super();
- }
-
- public synchronized boolean add(E obj) {
- super.addElement(obj);
- return true;
- }
-
- public synchronized void addElement(E obj) {
- super.add(obj);
- }
-
- public void test_add() {
- SubVector<String> subvector = new SubVector<String>();
- subvector.add("foo");
- subvector.addElement("bar");
- assertEquals("Expected two elements in vector", 2, subvector.size());
- }
-
- }
-
- /**
- * java.util.Vector#toString()
- */
- public void test_toString() {
- // Ensure toString works with self-referencing elements.
- Vector<Object> vec = new Vector<Object>(3);
- vec.add(null);
- vec.add(new Object());
- vec.add(vec);
- assertNotNull(vec.toString());
-
- // Test for method java.lang.String java.util.Vector.toString()
- assertTrue("Incorrect String returned", tVector.toString().equals(
- vString));
-
- Vector v = new Vector();
- v.addElement("one");
- v.addElement(v);
- v.addElement("3");
- // test last element
- v.addElement(v);
- String result = v.toString();
- assertTrue("should contain self ref", result.indexOf("(this") > -1);
- }
-
- public void test_override_size() throws Exception {
- Vector v = new Vector();
- Vector testv = new MockVector();
- // though size is overriden, it should passed without exception
- testv.add(1);
- testv.add(2);
- testv.clear();
-
- testv.add(1);
- testv.add(2);
- v.add(1);
- v.add(2);
- // RI's bug here
- assertTrue(testv.equals(v));
- }
-
- /**
- * java.util.Vector#trimToSize()
- */
- public void test_trimToSize() {
- // Test for method void java.util.Vector.trimToSize()
- Vector v = new Vector(10);
- v.addElement(new Object());
- v.trimToSize();
- assertEquals("Failed to trim capacity", 1, v.capacity());
- }
-
- protected Vector vectorClone(Vector s) {
- return (Vector) s.clone();
- }
-
- public class MockVector extends Vector{
- @Override
- public synchronized int size() {
- return 0;
- }
-
- public void removeRange(int start, int end) {
- super.removeRange(start, end);
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- for (int i = 0; i < 100; i++) {
- tVector.addElement("Test " + i);
- }
- objArray = new Object[100];
- for (int i = 0; i < 100; i++) {
- objArray[i] = "Test " + i;
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/WeakHashMapTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/util/WeakHashMapTest.java
deleted file mode 100644
index c17e7a5..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/util/WeakHashMapTest.java
+++ /dev/null
@@ -1,482 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.util;
-
-import java.util.AbstractMap;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-
-import tests.support.Support_MapTest2;
-
-public class WeakHashMapTest extends junit.framework.TestCase {
- class MockMap extends AbstractMap {
- public Set entrySet() {
- return null;
- }
- public int size(){
- return 0;
- }
- }
-
- Object[] keyArray = new Object[100];
-
- Object[] valueArray = new Object[100];
-
- WeakHashMap whm;
-
- Object[] KEY_ARRAY;
-
- Object[] VALUE_ARRAY;
-
- /**
- * java.util.WeakHashMap#WeakHashMap()
- */
- public void test_Constructor() {
- // Test for method java.util.WeakHashMap()
- new Support_MapTest2(new WeakHashMap()).runTest();
-
- whm = new WeakHashMap();
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
- for (int i = 0; i < 100; i++)
- assertTrue("Incorrect value retrieved",
- whm.get(keyArray[i]) == valueArray[i]);
-
- }
-
- /**
- * java.util.WeakHashMap#WeakHashMap(int)
- */
- public void test_ConstructorI() {
- // Test for method java.util.WeakHashMap(int)
- whm = new WeakHashMap(50);
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
- for (int i = 0; i < 100; i++)
- assertTrue("Incorrect value retrieved",
- whm.get(keyArray[i]) == valueArray[i]);
-
- WeakHashMap empty = new WeakHashMap(0);
- assertNull("Empty weakhashmap access", empty.get("nothing"));
- empty.put("something", "here");
- assertTrue("cannot get element", empty.get("something") == "here");
- }
-
- /**
- * java.util.WeakHashMap#WeakHashMap(int, float)
- */
- public void test_ConstructorIF() {
- // Test for method java.util.WeakHashMap(int, float)
- whm = new WeakHashMap(50, 0.5f);
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
- for (int i = 0; i < 100; i++)
- assertTrue("Incorrect value retrieved",
- whm.get(keyArray[i]) == valueArray[i]);
-
- WeakHashMap empty = new WeakHashMap(0, 0.75f);
- assertNull("Empty hashtable access", empty.get("nothing"));
- empty.put("something", "here");
- assertTrue("cannot get element", empty.get("something") == "here");
- }
-
- /**
- * java.util.WeakHashMap#WeakHashMap(java.util.Map)
- */
- public void test_ConstructorLjava_util_Map() {
- Map mockMap = new MockMap();
- WeakHashMap map = new WeakHashMap(mockMap);
- assertEquals("Size should be 0", 0, map.size());
- }
-
- /**
- * java.util.WeakHashMap#clear()
- */
- public void test_clear() {
- // Test for method boolean java.util.WeakHashMap.clear()
- whm = new WeakHashMap();
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
- whm.clear();
- assertTrue("Cleared map should be empty", whm.isEmpty());
- for (int i = 0; i < 100; i++)
- assertNull("Cleared map should only return null", whm
- .get(keyArray[i]));
-
- }
-
- /**
- * java.util.WeakHashMap#containsKey(java.lang.Object)
- */
- public void test_containsKeyLjava_lang_Object() {
- // Test for method boolean java.util.WeakHashMap.containsKey()
- whm = new WeakHashMap();
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
- for (int i = 0; i < 100; i++)
- assertTrue("Should contain referenced key", whm
- .containsKey(keyArray[i]));
- keyArray[25] = null;
- keyArray[50] = null;
- }
-
- /**
- * java.util.WeakHashMap#containsValue(java.lang.Object)
- */
- public void test_containsValueLjava_lang_Object() {
- // Test for method boolean java.util.WeakHashMap.containsValue()
- whm = new WeakHashMap();
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
- for (int i = 0; i < 100; i++)
- assertTrue("Should contain referenced value", whm
- .containsValue(valueArray[i]));
- keyArray[25] = null;
- keyArray[50] = null;
- }
-
- /**
- * java.util.WeakHashMap#entrySet()
- */
- public void test_entrySet() {
- WeakHashMap<Object, Object> weakMap = new WeakHashMap<Object, Object>();
- KEY_ARRAY = new Object[100];
- VALUE_ARRAY = new Object[100];
- for (int i = 0; i < 100; i++) {
- KEY_ARRAY[i] = new Integer(i);
- VALUE_ARRAY[i] = new Long(i);
- weakMap.put(KEY_ARRAY[i], VALUE_ARRAY[i]);
- }
-
- List<Object> keys = Arrays.asList(KEY_ARRAY);
- List<Object> values = Arrays.asList(VALUE_ARRAY);
-
- // Check the entry set has correct size & content
- Set<Map.Entry<Object, Object>> entrySet = weakMap.entrySet();
- assertEquals("Assert 0: Incorrect number of entries returned", 100,
- entrySet.size());
- Iterator<Map.Entry<Object, Object>> it = entrySet.iterator();
- while (it.hasNext()) {
- Map.Entry<Object, Object> entry = it.next();
- assertTrue("Assert 1: Invalid map entry key returned", keys
- .contains(entry.getKey()));
- assertTrue("Assert 2: Invalid map entry value returned", values
- .contains(entry.getValue()));
- assertTrue("Assert 3: Entry not in entry set", entrySet
- .contains(entry));
- }
-
- // Dereference list of key/value objects
- keys = values = null;
-
- // Dereference a single key, then try to
- // force a collection of the weak ref'd obj
- KEY_ARRAY[50] = null;
- int count = 0;
- do {
- System.gc();
- System.gc();
- Runtime.getRuntime().runFinalization();
- count++;
- } while (count <= 5 && entrySet.size() == 100);
-
- if ((count == 5) && (entrySet.size() == 100)) {
- // We failed (or entrySet broken), so further tests not valid.
- return;
- }
-
- assertEquals("Assert 4: Incorrect number of entries after gc", 99,
- entrySet.size());
- assertSame("Assert 5: Entries not identical", entrySet.iterator()
- .next(), entrySet.iterator().next());
-
- // remove alternate entries using the iterator, and ensure the
- // iteration count is consistent
- int size = entrySet.size();
- it = entrySet.iterator();
- while (it.hasNext()) {
- it.next();
- it.remove();
- size--;
- if (it.hasNext()) {
- it.next();
- }
-
- }
- assertEquals("Assert 6: entry set count mismatch", size, entrySet
- .size());
-
- int entries = 0;
- it = entrySet.iterator();
- while (it.hasNext()) {
- it.next();
- entries++;
- }
- assertEquals("Assert 6: count mismatch", size, entries);
-
- it = entrySet.iterator();
- while (it.hasNext()) {
- it.next();
- it.remove();
- }
- assertEquals("Assert 7: entry set not empty", 0, entrySet.size());
- assertTrue("Assert 8: iterator not empty", !entrySet.iterator()
- .hasNext());
- }
-
- /**
- * java.util.WeakHashMap#entrySet()
- */
- public void test_entrySet_2() {
- // Test for method java.util.Set java.util.WeakHashMap.entrySet()
- whm = new WeakHashMap();
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
- List keys = Arrays.asList(keyArray);
- List values = Arrays.asList(valueArray);
- Set entrySet = whm.entrySet();
- assertTrue("Incorrect number of entries returned--wanted 100, got: "
- + entrySet.size(), entrySet.size() == 100);
- Iterator it = entrySet.iterator();
- while (it.hasNext()) {
- Map.Entry entry = (Map.Entry) it.next();
- assertTrue("Invalid map entry returned--bad key", keys
- .contains(entry.getKey()));
- assertTrue("Invalid map entry returned--bad key", values
- .contains(entry.getValue()));
- }
- keys = null;
- values = null;
- keyArray[50] = null;
-
- int count = 0;
- do {
- System.gc();
- System.gc();
- Runtime.getRuntime().runFinalization();
- count++;
- } while (count <= 5 && entrySet.size() == 100);
-
- assertTrue(
- "Incorrect number of entries returned after gc--wanted 99, got: "
- + entrySet.size(), entrySet.size() == 99);
- }
-
- /**
- * java.util.WeakHashMap#get(java.lang.Object)
- */
- public void test_getLjava_lang_Object() {
- // Test for method java.lang.Object
- // java.util.WeakHashMap.get(java.lang.Object)
- assertTrue("Used to test", true);
- }
-
- /**
- * java.util.WeakHashMap#isEmpty()
- */
- public void test_isEmpty() {
- // Test for method boolean java.util.WeakHashMap.isEmpty()
- whm = new WeakHashMap();
- assertTrue("New map should be empty", whm.isEmpty());
- Object myObject = new Object();
- whm.put(myObject, myObject);
- assertTrue("Map should not be empty", !whm.isEmpty());
- whm.remove(myObject);
- assertTrue("Map with elements removed should be empty", whm.isEmpty());
- }
-
- /**
- * java.util.WeakHashMap#put(java.lang.Object, java.lang.Object)
- */
- public void test_putLjava_lang_ObjectLjava_lang_Object() {
- // Test for method java.lang.Object
- // java.util.WeakHashMap.put(java.lang.Object, java.lang.Object)
- WeakHashMap map = new WeakHashMap();
- map.put(null, "value"); // add null key
- System.gc();
- System.runFinalization();
- map.remove("nothing"); // Cause objects in queue to be removed
- assertEquals("null key was removed", 1, map.size());
- }
-
- /**
- * java.util.WeakHashMap#putAll(java.util.Map)
- */
- public void test_putAllLjava_util_Map() {
- Map mockMap=new MockMap();
- WeakHashMap map = new WeakHashMap();
- map.putAll(mockMap);
- assertEquals("Size should be 0", 0, map.size());
- }
-
- /**
- * java.util.WeakHashMap#remove(java.lang.Object)
- */
- public void test_removeLjava_lang_Object() {
- // Test for method java.lang.Object
- // java.util.WeakHashMap.remove(java.lang.Object)
- whm = new WeakHashMap();
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
-
- assertTrue("Remove returned incorrect value",
- whm.remove(keyArray[25]) == valueArray[25]);
- assertNull("Remove returned incorrect value",
- whm.remove(keyArray[25]));
- assertEquals("Size should be 99 after remove", 99, whm.size());
- }
-
- /**
- * java.util.WeakHashMap#size()
- */
- public void test_size() {
- // Test for method int java.util.WeakHashMap.size()
- assertTrue("Used to test", true);
- }
-
- /**
- * java.util.WeakHashMap#keySet()
- */
- public void test_keySet() {
- // Test for method java.util.Set java.util.WeakHashMap.keySet()
- whm = new WeakHashMap();
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
-
- List keys = Arrays.asList(keyArray);
- List values = Arrays.asList(valueArray);
-
- Set keySet = whm.keySet();
- assertEquals("Incorrect number of keys returned,", 100, keySet.size());
- Iterator it = keySet.iterator();
- while (it.hasNext()) {
- Object key = it.next();
- assertTrue("Invalid map entry returned--bad key", keys
- .contains(key));
- }
- keys = null;
- values = null;
- keyArray[50] = null;
-
- int count = 0;
- do {
- System.gc();
- System.gc();
- Runtime.getRuntime().runFinalization();
- count++;
- } while (count <= 5 && keySet.size() == 100);
-
- assertEquals("Incorrect number of keys returned after gc,", 99, keySet
- .size());
- }
-
- /**
- * Regression test for HARMONY-3883
- * java.util.WeakHashMap#keySet()
- */
- public void test_keySet_hasNext() {
- WeakHashMap map = new WeakHashMap();
- ConstantHashClass cl = new ConstantHashClass(2);
- map.put(new ConstantHashClass(1), null);
- map.put(cl, null);
- map.put(new ConstantHashClass(3), null);
- Iterator iter = map.keySet().iterator();
- iter.next();
- iter.next();
- System.gc();
- assertFalse("Wrong hasNext() value", iter.hasNext());
- }
-
- static class ConstantHashClass {
- private int id = 0;
-
- public ConstantHashClass(int id) {
- this.id = id;
- }
-
- public int hashCode() {
- return 0;
- }
-
- public String toString() {
- return "ConstantHashClass[id=" + id + "]";
- }
- }
-
-
- /**
- * java.util.WeakHashMap#values()
- */
- public void test_values() {
- // Test for method java.util.Set java.util.WeakHashMap.values()
- whm = new WeakHashMap();
- for (int i = 0; i < 100; i++)
- whm.put(keyArray[i], valueArray[i]);
-
- List keys = Arrays.asList(keyArray);
- List values = Arrays.asList(valueArray);
-
- Collection valuesCollection = whm.values();
- assertEquals("Incorrect number of keys returned,", 100,
- valuesCollection.size());
- Iterator it = valuesCollection.iterator();
- while (it.hasNext()) {
- Object value = it.next();
- assertTrue("Invalid map entry returned--bad value", values
- .contains(value));
- }
- keys = null;
- values = null;
- keyArray[50] = null;
-
- int count = 0;
- do {
- System.gc();
- System.gc();
- Runtime.getRuntime().runFinalization();
- count++;
- } while (count <= 5 && valuesCollection.size() == 100);
-
- assertEquals("Incorrect number of keys returned after gc,", 99,
- valuesCollection.size());
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- for (int i = 0; i < 100; i++) {
- keyArray[i] = new Object();
- valueArray[i] = new Object();
- }
-
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}