summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2014-05-12 13:56:54 +0100
committerNeil Fuller <nfuller@google.com>2014-05-12 14:05:42 +0100
commit4df29e1e1cf169ff6c77b8dd247de8c79b81d552 (patch)
treeb1e62f08bb13f2e6d0f493e22f9c05a79f6317fd
parent567dcb29cba8be9abf154f21e9c1ff47a81ad9cc (diff)
downloadlibcore-4df29e1e1cf169ff6c77b8dd247de8c79b81d552.zip
libcore-4df29e1e1cf169ff6c77b8dd247de8c79b81d552.tar.gz
libcore-4df29e1e1cf169ff6c77b8dd247de8c79b81d552.tar.bz2
Fix Hashtable CTS test
The test assumed that the Enumeration returned from element() and keys() could be cast to Iterator. Even if it was previously ok, it isn't now and it is not part of the public API. Bug: 13747624 Change-Id: I552a886711178708cbe7b6d87a976b6c1a839467
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/HashtableTest.java106
1 files changed, 18 insertions, 88 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/HashtableTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/HashtableTest.java
index d71decd..2c81f65 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/HashtableTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/HashtableTest.java
@@ -240,11 +240,9 @@ public class HashtableTest extends junit.framework.TestCase {
assertEquals("All keys not retrieved", 10, ht10.size());
- // cast Enumeration to Iterator
- Iterator iterator = (Iterator) elms;
- assertFalse(iterator.hasNext());
+ assertFalse(elms.hasMoreElements());
try {
- iterator.next();
+ elms.nextElement();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
@@ -431,11 +429,9 @@ public class HashtableTest extends junit.framework.TestCase {
assertEquals("All keys not retrieved", 10, ht10.size());
- // cast Enumeration to Iterator
- Iterator iterator = (Iterator) keys;
- assertFalse(iterator.hasNext());
+ assertFalse(keys.hasMoreElements());
try {
- iterator.next();
+ keys.nextElement();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
@@ -832,41 +828,17 @@ public class HashtableTest extends junit.framework.TestCase {
String value = "value";
hashTable.put(key, value);
- Iterator iterator = (Iterator) hashTable.keys();
- assertTrue(iterator.hasNext());
- try {
- iterator.remove();
- fail("should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // Expected
- }
- iterator.next();
- try {
- iterator.remove();
- fail("should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // Expected
- }
- assertFalse(iterator.hasNext());
+ Enumeration enumeration = hashTable.keys();
+ assertTrue(enumeration.hasMoreElements());
+ enumeration.nextElement();
+ assertFalse(enumeration.hasMoreElements());
- iterator = (Iterator) hashTable.elements();
- assertTrue(iterator.hasNext());
- try {
- iterator.remove();
- fail("should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // Expected
- }
- iterator.next();
- try {
- iterator.remove();
- fail("should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // Expected
- }
- assertFalse(iterator.hasNext());
+ enumeration = hashTable.elements();
+ assertTrue(enumeration.hasMoreElements());
+ enumeration.nextElement();
+ assertFalse(enumeration.hasMoreElements());
- iterator = hashTable.keySet().iterator();
+ Iterator iterator = hashTable.keySet().iterator();
assertTrue(iterator.hasNext());
try {
iterator.remove();
@@ -883,81 +855,39 @@ public class HashtableTest extends junit.framework.TestCase {
hashTable.put(key + i, value + i);
}
- // cast Enumeration to Iterator
- Enumeration enumeration = hashTable.keys();
- iterator = (Iterator) enumeration;
+ enumeration = hashTable.keys();
assertTrue(enumeration.hasMoreElements());
- assertTrue(iterator.hasNext());
for (int i = 0; i < 10; i++) {
- if (i % 2 == 0) {
- enumeration.nextElement();
- } else {
- iterator.next();
- }
+ enumeration.nextElement();
}
assertFalse(enumeration.hasMoreElements());
- assertFalse(iterator.hasNext());
try {
enumeration.nextElement();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
- try {
- iterator.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- // cast Enumeration to Iterator
enumeration = hashTable.elements();
- iterator = (Iterator) enumeration;
assertTrue(enumeration.hasMoreElements());
- assertTrue(iterator.hasNext());
for (int i = 0; i < 10; i++) {
- if (i % 2 == 0) {
- enumeration.nextElement();
- } else {
- iterator.next();
- }
+ enumeration.nextElement();
}
assertFalse(enumeration.hasMoreElements());
- assertFalse(iterator.hasNext());
try {
enumeration.nextElement();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {
// Expected
}
- try {
- iterator.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- // cast Iterator to Enumeration
- enumeration = (Enumeration) hashTable.keySet().iterator();
- iterator = (Iterator) enumeration;
- assertTrue(enumeration.hasMoreElements());
+ iterator = hashTable.keySet().iterator();
assertTrue(iterator.hasNext());
for (int i = 0; i < 10; i++) {
- if (i % 2 == 0) {
- enumeration.nextElement();
- } else {
- iterator.next();
- }
+ iterator.next();
}
- assertFalse(enumeration.hasMoreElements());
assertFalse(iterator.hasNext());
try {
- enumeration.nextElement();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
iterator.next();
fail("should throw NoSuchElementException");
} catch (NoSuchElementException e) {