| Index: third_party/protobuf/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
|
| diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
|
| index efb8f3e20aa5f759bb09daf1a9acc3454b46c3f1..60c85450c3c7c570c9855121b3040dbfbc01fb6a 100644
|
| --- a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
|
| +++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/IntArrayListTest.java
|
| @@ -32,43 +32,43 @@ package com.google.protobuf;
|
|
|
| import static java.util.Arrays.asList;
|
|
|
| -import junit.framework.TestCase;
|
| -
|
| import java.util.Collections;
|
| import java.util.ConcurrentModificationException;
|
| import java.util.Iterator;
|
| +import junit.framework.TestCase;
|
|
|
| /**
|
| * Tests for {@link IntArrayList}.
|
| - *
|
| + *
|
| * @author dweis@google.com (Daniel Weis)
|
| */
|
| public class IntArrayListTest extends TestCase {
|
| -
|
| - private static final IntArrayList UNARY_LIST = newImmutableIntArrayList(1);
|
| +
|
| + private static final IntArrayList UNARY_LIST =
|
| + newImmutableIntArrayList(1);
|
| private static final IntArrayList TERTIARY_LIST =
|
| newImmutableIntArrayList(1, 2, 3);
|
| -
|
| +
|
| private IntArrayList list;
|
| -
|
| +
|
| @Override
|
| protected void setUp() throws Exception {
|
| list = new IntArrayList();
|
| }
|
| -
|
| +
|
| public void testEmptyListReturnsSameInstance() {
|
| assertSame(IntArrayList.emptyList(), IntArrayList.emptyList());
|
| }
|
| -
|
| +
|
| public void testEmptyListIsImmutable() {
|
| assertImmutable(IntArrayList.emptyList());
|
| }
|
| -
|
| +
|
| public void testMakeImmutable() {
|
| - list.addInt(2);
|
| + list.addInt(3);
|
| list.addInt(4);
|
| - list.addInt(6);
|
| - list.addInt(8);
|
| + list.addInt(5);
|
| + list.addInt(7);
|
| list.makeImmutable();
|
| assertImmutable(list);
|
| }
|
| @@ -81,7 +81,7 @@ public class IntArrayListTest extends TestCase {
|
| assertEquals(1, (int) iterator.next());
|
| list.set(0, 1);
|
| assertEquals(2, (int) iterator.next());
|
| -
|
| +
|
| list.remove(0);
|
| try {
|
| iterator.next();
|
| @@ -99,19 +99,19 @@ public class IntArrayListTest extends TestCase {
|
| // expected
|
| }
|
| }
|
| -
|
| +
|
| public void testGet() {
|
| assertEquals(1, (int) TERTIARY_LIST.get(0));
|
| assertEquals(2, (int) TERTIARY_LIST.get(1));
|
| assertEquals(3, (int) TERTIARY_LIST.get(2));
|
| -
|
| +
|
| try {
|
| TERTIARY_LIST.get(-1);
|
| fail();
|
| } catch (IndexOutOfBoundsException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| TERTIARY_LIST.get(3);
|
| fail();
|
| @@ -119,19 +119,19 @@ public class IntArrayListTest extends TestCase {
|
| // expected
|
| }
|
| }
|
| -
|
| +
|
| public void testGetInt() {
|
| assertEquals(1, TERTIARY_LIST.getInt(0));
|
| assertEquals(2, TERTIARY_LIST.getInt(1));
|
| assertEquals(3, TERTIARY_LIST.getInt(2));
|
| -
|
| +
|
| try {
|
| TERTIARY_LIST.get(-1);
|
| fail();
|
| } catch (IndexOutOfBoundsException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| TERTIARY_LIST.get(3);
|
| fail();
|
| @@ -139,35 +139,35 @@ public class IntArrayListTest extends TestCase {
|
| // expected
|
| }
|
| }
|
| -
|
| +
|
| public void testSize() {
|
| assertEquals(0, IntArrayList.emptyList().size());
|
| assertEquals(1, UNARY_LIST.size());
|
| assertEquals(3, TERTIARY_LIST.size());
|
|
|
| - list.addInt(2);
|
| + list.addInt(3);
|
| list.addInt(4);
|
| list.addInt(6);
|
| list.addInt(8);
|
| assertEquals(4, list.size());
|
| -
|
| +
|
| list.remove(0);
|
| assertEquals(3, list.size());
|
| -
|
| - list.add(16);
|
| +
|
| + list.add(17);
|
| assertEquals(4, list.size());
|
| }
|
| -
|
| +
|
| public void testSet() {
|
| list.addInt(2);
|
| list.addInt(4);
|
| -
|
| - assertEquals(2, (int) list.set(0, 0));
|
| - assertEquals(0, list.getInt(0));
|
| +
|
| + assertEquals(2, (int) list.set(0, 3));
|
| + assertEquals(3, list.getInt(0));
|
|
|
| assertEquals(4, (int) list.set(1, 0));
|
| assertEquals(0, list.getInt(1));
|
| -
|
| +
|
| try {
|
| list.set(-1, 0);
|
| fail();
|
| @@ -182,17 +182,17 @@ public class IntArrayListTest extends TestCase {
|
| // expected
|
| }
|
| }
|
| -
|
| +
|
| public void testSetInt() {
|
| - list.addInt(2);
|
| - list.addInt(4);
|
| -
|
| - assertEquals(2, list.setInt(0, 0));
|
| + list.addInt(1);
|
| + list.addInt(3);
|
| +
|
| + assertEquals(1, list.setInt(0, 0));
|
| assertEquals(0, list.getInt(0));
|
|
|
| - assertEquals(4, list.setInt(1, 0));
|
| + assertEquals(3, list.setInt(1, 0));
|
| assertEquals(0, list.getInt(1));
|
| -
|
| +
|
| try {
|
| list.setInt(-1, 0);
|
| fail();
|
| @@ -207,7 +207,7 @@ public class IntArrayListTest extends TestCase {
|
| // expected
|
| }
|
| }
|
| -
|
| +
|
| public void testAdd() {
|
| assertEquals(0, list.size());
|
|
|
| @@ -217,28 +217,30 @@ public class IntArrayListTest extends TestCase {
|
| assertTrue(list.add(3));
|
| list.add(0, 4);
|
| assertEquals(asList(4, 2, 3), list);
|
| -
|
| +
|
| list.add(0, 1);
|
| list.add(0, 0);
|
| // Force a resize by getting up to 11 elements.
|
| for (int i = 0; i < 6; i++) {
|
| - list.add(5 + i);
|
| + list.add(Integer.valueOf(5 + i));
|
| }
|
| - assertEquals(asList(0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10), list);
|
| -
|
| + assertEquals(
|
| + asList(0, 1, 4, 2, 3, 5, 6, 7, 8, 9, 10),
|
| + list);
|
| +
|
| try {
|
| list.add(-1, 5);
|
| } catch (IndexOutOfBoundsException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.add(4, 5);
|
| } catch (IndexOutOfBoundsException e) {
|
| // expected
|
| }
|
| }
|
| -
|
| +
|
| public void testAddInt() {
|
| assertEquals(0, list.size());
|
|
|
| @@ -248,7 +250,7 @@ public class IntArrayListTest extends TestCase {
|
| list.addInt(3);
|
| assertEquals(asList(2, 3), list);
|
| }
|
| -
|
| +
|
| public void testAddAll() {
|
| assertEquals(0, list.size());
|
|
|
| @@ -256,17 +258,17 @@ public class IntArrayListTest extends TestCase {
|
| assertEquals(1, list.size());
|
| assertEquals(1, (int) list.get(0));
|
| assertEquals(1, list.getInt(0));
|
| -
|
| +
|
| assertTrue(list.addAll(asList(2, 3, 4, 5, 6)));
|
| assertEquals(asList(1, 2, 3, 4, 5, 6), list);
|
| -
|
| +
|
| assertTrue(list.addAll(TERTIARY_LIST));
|
| assertEquals(asList(1, 2, 3, 4, 5, 6, 1, 2, 3), list);
|
|
|
| assertFalse(list.addAll(Collections.<Integer>emptyList()));
|
| assertFalse(list.addAll(IntArrayList.emptyList()));
|
| }
|
| -
|
| +
|
| public void testRemove() {
|
| list.addAll(TERTIARY_LIST);
|
| assertEquals(1, (int) list.remove(0));
|
| @@ -280,96 +282,96 @@ public class IntArrayListTest extends TestCase {
|
|
|
| assertEquals(2, (int) list.remove(0));
|
| assertEquals(asList(), list);
|
| -
|
| +
|
| try {
|
| list.remove(-1);
|
| fail();
|
| } catch (IndexOutOfBoundsException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.remove(0);
|
| } catch (IndexOutOfBoundsException e) {
|
| // expected
|
| }
|
| }
|
| -
|
| +
|
| private void assertImmutable(IntArrayList list) {
|
| if (list.contains(1)) {
|
| throw new RuntimeException("Cannot test the immutability of lists that contain 1.");
|
| }
|
| -
|
| +
|
| try {
|
| list.add(1);
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.add(0, 1);
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.addAll(Collections.<Integer>emptyList());
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.addAll(Collections.singletonList(1));
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.addAll(new IntArrayList());
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.addAll(UNARY_LIST);
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.addAll(0, Collections.singleton(1));
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.addAll(0, UNARY_LIST);
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.addAll(0, Collections.<Integer>emptyList());
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.addInt(0);
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.clear();
|
| fail();
|
| @@ -383,63 +385,63 @@ public class IntArrayListTest extends TestCase {
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.remove(new Object());
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.removeAll(Collections.<Integer>emptyList());
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.removeAll(Collections.singleton(1));
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.removeAll(UNARY_LIST);
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.retainAll(Collections.<Integer>emptyList());
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.retainAll(Collections.singleton(1));
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.retainAll(UNARY_LIST);
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.set(0, 0);
|
| fail();
|
| } catch (UnsupportedOperationException e) {
|
| // expected
|
| }
|
| -
|
| +
|
| try {
|
| list.setInt(0, 0);
|
| fail();
|
| @@ -447,7 +449,7 @@ public class IntArrayListTest extends TestCase {
|
| // expected
|
| }
|
| }
|
| -
|
| +
|
| private static IntArrayList newImmutableIntArrayList(int... elements) {
|
| IntArrayList list = new IntArrayList();
|
| for (int element : elements) {
|
|
|