Skip to content

Commit

Permalink
Updated java.util tests to libcore nougat release.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=160439870
  • Loading branch information
tomball committed Jul 14, 2017
1 parent bed7661 commit 4668297
Show file tree
Hide file tree
Showing 15 changed files with 953 additions and 288 deletions.

This file was deleted.

Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package tests.api.java.util;
package org.apache.harmony.tests.java.util;

import java.util.AbstractMap;
import java.util.AbstractSet;
Expand Down Expand Up @@ -134,6 +134,94 @@ public int compare(Object object1, Object object2) {
assertSame("MyMap", valueOut, specialValue);
}

/**
* java.util.AbstractMap#clear()
*/
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
}
}

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

/**
* 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));
}

/**
* java.util.AbstractMap#values()
*/
Expand Down Expand Up @@ -183,11 +271,11 @@ public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError(e); // android-changed
fail("Clone must be supported");
return null;
}
}
}
;
MyMap map = new MyMap();
map.put("one", "1");
Map.Entry entry = (Map.Entry) map.entrySet().iterator().next();
Expand All @@ -201,7 +289,7 @@ public class AMT extends AbstractMap {

// Very crude AbstractMap implementation
Vector values = new Vector();
Vector keys = new Vector();
Vector keys = new Vector();

public Set entrySet() {
return new AbstractSet() {
Expand Down Expand Up @@ -260,7 +348,7 @@ public Object put(Object k, Object v) {
* {@link java.util.AbstractMap#putAll(Map)}
*/
public void test_putAllLMap() {
Hashtable ht = new Hashtable();
Hashtable ht = new Hashtable();
AMT amt = new AMT();
ht.put("this", "that");
amt.putAll(ht);
Expand Down

0 comments on commit 4668297

Please sign in to comment.