diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2019-02-18 19:02:43 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-02-18 19:02:43 +0000 |
commit | bdad68a6e202a736723978fc36c36d3464b9d653 (patch) | |
tree | 0e69a7dc4e31fee3b46d480ba550783549182ef6 /harmony-tests | |
parent | c690caf0823f5b89ab46798cfa1417ad1af79843 (diff) | |
parent | 839d8ce00ffde6d688d28908c3d35c4c58680a26 (diff) |
Merge changes Ib8491242,I695758c4
* changes:
EnumSet.isEmpty(): Provide test coverage.
Lists: test coverage for misc corner cases.
Diffstat (limited to 'harmony-tests')
4 files changed, 69 insertions, 17 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/ArrayListTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/ArrayListTest.java index 7b3d7d04e3..1959c422e3 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/ArrayListTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/ArrayListTest.java @@ -16,10 +16,10 @@ */ package org.apache.harmony.tests.java.util; -import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.HashSet; import java.util.Iterator; @@ -27,6 +27,7 @@ import java.util.List; import java.util.Set; import java.util.Spliterator; import java.util.Vector; +import java.util.function.Supplier; import libcore.java.util.SpliteratorTester; import tests.support.Support_ListTest; @@ -888,6 +889,23 @@ public class ArrayListTest extends junit.framework.TestCase { list.trimToSize(); } + /** + * Checks that an element can successfully be added to an ArrayList that + * was previously {@link ArrayList#trimToSize() trimmed} to the empty size. + */ + public void test_trimToEmpty_add() { + ArrayList<String> list = new ArrayList<>(); + list.trimToSize(); // empty after construction + list.add("element"); + assertEquals(Arrays.asList("element"), list); + + list.remove("element"); + assertEquals(Collections.emptyList(), list); + list.trimToSize(); // empty after all elements have been removed + list.add("element"); + assertEquals(Arrays.asList("element"), list); + } + public void test_addAll() { ArrayList list = new ArrayList(); list.add("one"); @@ -1109,8 +1127,12 @@ public class ArrayListTest extends junit.framework.TestCase { } public void test_forEachRemaining_iterator() throws Exception { - ForEachRemainingTester.runTests(ArrayList.class, new String[] { "foo", "bar", "baz"}); - ForEachRemainingTester.runTests(ArrayList.class, new String[] { "foo" }); + ForEachRemainingTester.runTests(ArrayList::new, new String[] { "foo", "bar", "baz"}); + ForEachRemainingTester.runTests(ArrayList::new, new String[] { "foo" }); + + Supplier<List<String>> sublistSupplier = () -> new ArrayList<String>().subList(0, 0); + ForEachRemainingTester.runTests(sublistSupplier, new String[] { "foo", "bar", "baz"}); + ForEachRemainingTester.runTests(sublistSupplier, new String[] { "foo" }); } public void test_spliterator() throws Exception { diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/EnumSetTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/EnumSetTest.java index fb2cbcb5b9..baaaf71d4f 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/EnumSetTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/EnumSetTest.java @@ -17,6 +17,7 @@ package org.apache.harmony.tests.java.util; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; import java.util.Iterator; @@ -206,7 +207,6 @@ public class EnumSetTest extends TestCase { EnumSet<HugeEnum> anotherHugeSet = EnumSet.allOf(HugeEnum.class); assertEquals(hugeEnumSet, anotherHugeSet); assertNotSame(hugeEnumSet, anotherHugeSet); - } /** @@ -605,16 +605,46 @@ public class EnumSetTest extends TestCase { * java.util.EnumSet#size() */ public void test_size() { - Set<EnumFoo> set = EnumSet.noneOf(EnumFoo.class); - set.add(EnumFoo.a); - set.add(EnumFoo.b); - assertEquals("Size should be 2", 2, set.size()); + assertEmpty(EnumSet.noneOf(EnumFoo.class)); + assertSize(2, EnumSet.of(EnumFoo.a, EnumFoo.b)); - // test enum type with more than 64 elements - Set<HugeEnum> hugeSet = EnumSet.noneOf(HugeEnum.class); - hugeSet.add(HugeEnum.a); - hugeSet.add(HugeEnum.bb); - assertEquals("Size should be 2", 2, hugeSet.size()); + // enum type with more than 64 elements + assertEmpty(EnumSet.noneOf(HugeEnum.class)); + assertSize(2, EnumSet.of(HugeEnum.a, HugeEnum.bb)); + assertSize(65, EnumSet.allOf(HugeEnum.class)); + } + + public void test_size_modification_regular() { + EnumSet<EnumFoo> set = EnumSet.noneOf(EnumFoo.class); + assertEmpty(set); + set.addAll(Arrays.asList(EnumFoo.a, EnumFoo.b)); + assertSize(2, set); + set.add(EnumFoo.c); + assertSize(3, set); + set.remove(EnumFoo.d); + assertSize(3, set); + set.remove(EnumFoo.b); + assertSize(2, set); + set.clear(); + assertEmpty(set); + } + + public void test_size_modification_jumbo() { + EnumSet<HugeEnum> set = EnumSet.allOf(HugeEnum.class); + assertSize(65, set); + set.remove(HugeEnum.b); + assertSize(64, set); + set.clear(); + assertEmpty(set); + } + + private static void assertEmpty(EnumSet<?> set) { + assertSize(0, set); + } + + private static void assertSize(int expectedSize, Set<?> set) { + assertEquals(expectedSize, set.size()); + assertEquals(expectedSize == 0, set.isEmpty()); } /** diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/LinkedListTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/LinkedListTest.java index ea829c9a90..e0451615cf 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/LinkedListTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/LinkedListTest.java @@ -943,8 +943,8 @@ public class LinkedListTest extends junit.framework.TestCase { } public void test_forEachRemaining_iterator() throws Exception { - ForEachRemainingTester.runTests(LinkedList.class, new String[]{ "foo", "bar", "baz "}); - ForEachRemainingTester.runTests(LinkedList.class, new String[] { "foo" }); + ForEachRemainingTester.runTests(LinkedList::new, new String[]{ "foo", "bar", "baz "}); + ForEachRemainingTester.runTests(LinkedList::new, new String[] { "foo" }); } public void test_spliterator() throws Exception { diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/VectorTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/VectorTest.java index f889c8e7e9..d0b1f2b4d5 100644 --- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/VectorTest.java +++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/VectorTest.java @@ -1437,8 +1437,8 @@ public class VectorTest extends junit.framework.TestCase { } public void test_forEachRemaining_iterator() throws Exception { - ForEachRemainingTester.runTests(Vector.class, new String[] { "foo", "bar", "baz" }); - ForEachRemainingTester.runTests(Vector.class, new String[] { "foo" }); + ForEachRemainingTester.runTests(Vector::new, new String[] { "foo", "bar", "baz" }); + ForEachRemainingTester.runTests(Vector::new, new String[] { "foo" }); } public void test_spliterator() throws Exception { |