Java 类com.google.common.collect.testing.MinimalCollection 实例源码

项目:guava-mock    文件:CollectionRetainAllTester.java   
@Override
public void setUp() throws Exception {
  super.setUp();

  empty = new Target(emptyCollection(), "empty");
  /*
   * We test that nullSingleton.retainAll(disjointList) does NOT throw a
   * NullPointerException when disjointList does not, so we can't use
   * MinimalCollection, which throws NullPointerException on calls to
   * contains(null).
   */
  List<E> disjointList = Arrays.asList(e3(), e4());
  disjoint = new Target(disjointList, "disjoint");
  superset = new Target(MinimalCollection.of(e0(), e1(), e2(), e3(), e4()), "superset");
  nonEmptyProperSubset = new Target(MinimalCollection.of(e1()), "subset");
  sameElements = new Target(Arrays.asList(createSamplesArray()), "sameElements");
  containsDuplicates =
      new Target(MinimalCollection.of(e0(), e0(), e3(), e3()), "containsDuplicates");
  partialOverlap = new Target(MinimalCollection.of(e2(), e3()), "partialOverlap");
  nullSingleton = new Target(Collections.<E>singleton(null), "nullSingleton");
}
项目:googles-monorepo-demo    文件:CollectionRetainAllTester.java   
@Override
public void setUp() throws Exception {
  super.setUp();

  empty = new Target(emptyCollection(), "empty");
  /*
   * We test that nullSingleton.retainAll(disjointList) does NOT throw a
   * NullPointerException when disjointList does not, so we can't use
   * MinimalCollection, which throws NullPointerException on calls to
   * contains(null).
   */
  List<E> disjointList = Arrays.asList(e3(), e4());
  disjoint = new Target(disjointList, "disjoint");
  superset = new Target(MinimalCollection.of(e0(), e1(), e2(), e3(), e4()), "superset");
  nonEmptyProperSubset = new Target(MinimalCollection.of(e1()), "subset");
  sameElements = new Target(Arrays.asList(createSamplesArray()), "sameElements");
  containsDuplicates =
      new Target(MinimalCollection.of(e0(), e0(), e3(), e3()), "containsDuplicates");
  partialOverlap = new Target(MinimalCollection.of(e2(), e3()), "partialOverlap");
  nullSingleton = new Target(Collections.<E>singleton(null), "nullSingleton");
}
项目:googles-monorepo-demo    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_unsupportedAllPresent() {
  try {
    getList().addAll(0, MinimalCollection.of(e0()));
    fail("addAll(n, allPresent) should throw");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
}
项目:googles-monorepo-demo    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_supportedSomePresent() {
  assertTrue(
      "addAll(n, allPresent) should return true",
      getList().addAll(0, MinimalCollection.of(e0(), e3())));
  expectAdded(0, e0(), e3());
}
项目:guava-mock    文件:CollectionContainsAllTester.java   
@CollectionFeature.Require(absent = ALLOWS_NULL_QUERIES)
public void testContainsAll_nullNotAllowed() {
  try {
    assertFalse(collection.containsAll(MinimalCollection.of((E) null)));
  } catch (NullPointerException tolerated) {
  }
}
项目:googles-monorepo-demo    文件:ImmutableListTest.java   
public void testCopyOf_collectionContainingNull() {
  Collection<String> c = MinimalCollection.of("a", null, "b");
  try {
    ImmutableList.copyOf(c);
    fail();
  } catch (NullPointerException expected) {
  }
}
项目:googles-monorepo-demo    文件:AbstractImmutableSetTest.java   
public void testCopyOf_collection_general() {
  Collection<String> c = MinimalCollection.of("a", "b", "a");
  Set<String> set = copyOf(c);
  assertEquals(2, set.size());
  assertTrue(set.contains("a"));
  assertTrue(set.contains("b"));
}
项目:guava-mock    文件:ListRemoveAllTester.java   
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRemoveAll_duplicate() {
  ArrayWithDuplicate<E> arrayAndDuplicate = createArrayWithDuplicateElement();
  collection = getSubjectGenerator().create(arrayAndDuplicate.elements);
  E duplicate = arrayAndDuplicate.duplicate;

  assertTrue(
      "removeAll(intersectingCollection) should return true",
      getList().removeAll(MinimalCollection.of(duplicate)));
  assertFalse(
      "after removeAll(e), a collection should not contain e even "
          + "if it initially contained e more than once.",
      getList().contains(duplicate));
}
项目:guava-mock    文件:CollectionRemoveAllTester.java   
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemoveAll_emptyCollection() {
  assertFalse(
      "removeAll(emptyCollection) should return false",
      collection.removeAll(MinimalCollection.of()));
  expectUnchanged();
}
项目:googles-monorepo-demo    文件:ListRetainAllTester.java   
@SuppressWarnings("unchecked")
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(SEVERAL)
public void testRetainAll_duplicatesRemoved() {
  E[] array = createSamplesArray();
  array[1] = e0();
  collection = getSubjectGenerator().create(array);
  assertTrue(
      "containsDuplicates.retainAll(subset) should return true",
      collection.retainAll(MinimalCollection.of(e2())));
  expectContents(e2());
}
项目:guava-mock    文件:CollectionRemoveAllTester.java   
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_allPresent() {
  assertTrue(
      "removeAll(intersectingCollection) should return true",
      collection.removeAll(MinimalCollection.of(e0())));
  expectMissing(e0());
}
项目:guava-mock    文件:CollectionRemoveAllTester.java   
@CollectionFeature.Require({SUPPORTS_REMOVE, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
@CollectionSize.Require(SEVERAL)
public void testRemoveAllSomePresentConcurrentWithIteration() {
  try {
    Iterator<E> iterator = collection.iterator();
    assertTrue(collection.removeAll(MinimalCollection.of(e0(), e3())));
    iterator.next();
    fail("Expected ConcurrentModificationException");
  } catch (ConcurrentModificationException expected) {
    // success
  }
}
项目:guava-mock    文件:CollectionRemoveAllTester.java   
/** Trigger the {@code other.size() >= this.size()} case in {@link AbstractSet#removeAll()}. */
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_somePresentLargeCollectionToRemove() {
  assertTrue(
      "removeAll(largeIntersectingCollection) should return true",
      collection.removeAll(MinimalCollection.of(e0(), e0(), e0(), e3(), e3(), e3())));
  expectMissing(e0());
}
项目:googles-monorepo-demo    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
public void testAddAllAtIndex_negative() {
  try {
    getList().addAll(-1, MinimalCollection.of(e3()));
    fail("addAll(-1, e) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
  expectMissing(e3());
}
项目:guava-mock    文件:CollectionRemoveAllTester.java   
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
public void testRemoveAll_unsupportedNonePresent() {
  try {
    assertFalse(
        "removeAll(disjointCollection) should return false or throw "
            + "UnsupportedOperationException",
        collection.removeAll(MinimalCollection.of(e3())));
  } catch (UnsupportedOperationException tolerated) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:CollectionRemoveAllTester.java   
@CollectionFeature.Require(absent = SUPPORTS_REMOVE)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAll_unsupportedPresent() {
  try {
    collection.removeAll(MinimalCollection.of(e0()));
    fail("removeAll(intersectingCollection) should throw UnsupportedOperationException");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
  assertTrue(collection.contains(e0()));
}
项目:guava-mock    文件:CollectionRemoveAllTester.java   
@CollectionFeature.Require(value = SUPPORTS_REMOVE, absent = ALLOWS_NULL_QUERIES)
public void testRemoveAll_containsNullNo() {
  MinimalCollection<?> containsNull = MinimalCollection.of((Object) null);
  try {
    assertFalse(
        "removeAll(containsNull) should return false or throw",
        collection.removeAll(containsNull));
  } catch (NullPointerException tolerated) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:CollectionRemoveAllTester.java   
@CollectionFeature.Require(SUPPORTS_REMOVE)
public void testRemoveAll_containsWrongType() {
  try {
    assertFalse(
        "removeAll(containsWrongType) should return false or throw",
        collection.removeAll(MinimalCollection.of(WrongType.VALUE)));
  } catch (ClassCastException tolerated) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListAddAllTester.java   
@CollectionFeature.Require(SUPPORTS_ADD)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_supportedAllPresent() {
  assertTrue(
      "addAll(allPresent) should return true", getList().addAll(MinimalCollection.of(e0())));
  expectAdded(e0());
}
项目:googles-monorepo-demo    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_unsupportedSomePresent() {
  try {
    getList().addAll(0, MinimalCollection.of(e0(), e3()));
    fail("addAll(n, allPresent) should throw");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
  expectMissing(e3());
}
项目:googles-monorepo-demo    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_supportedAllPresent() {
  assertTrue(
      "addAll(n, allPresent) should return true",
      getList().addAll(0, MinimalCollection.of(e0())));
  expectAdded(0, e0());
}
项目:googles-monorepo-demo    文件:CollectionAddAllTester.java   
@CollectionFeature.Require({SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
@CollectionSize.Require(absent = ZERO)
public void testAddAllConcurrentWithIteration() {
  try {
    Iterator<E> iterator = collection.iterator();
    assertTrue(collection.addAll(MinimalCollection.of(e3(), e0())));
    iterator.next();
    fail("Expected ConcurrentModificationException");
  } catch (ConcurrentModificationException expected) {
    // success
  }
}
项目:guava-mock    文件:MapPutAllTester.java   
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutAll_unsupportedSomePresent() {
  try {
    putAll(MinimalCollection.of(e3(), e0()));
    fail("putAll(somePresent) should throw");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:MapPutAllTester.java   
@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testPutAll_unsupportedAllPresent() {
  try {
    putAll(MinimalCollection.of(e0()));
  } catch (UnsupportedOperationException tolerated) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListRetainAllTester.java   
@CollectionFeature.Require(SUPPORTS_REMOVE)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testRetainAll_duplicatesKept() {
  E[] array = createSamplesArray();
  array[1] = e0();
  collection = getSubjectGenerator().create(array);
  assertFalse(
      "containsDuplicates.retainAll(superset) should return false",
      collection.retainAll(MinimalCollection.of(createSamplesArray())));
  expectContents(array);
}
项目:googles-monorepo-demo    文件:AbstractImmutableSetTest.java   
public void testCopyOf_collectionContainingNull() {
  Collection<String> c = MinimalCollection.of("a", null, "b");
  try {
    copyOf(c);
    fail();
  } catch (NullPointerException expected) {
  }
}
项目:guava-mock    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_supportedAllPresent() {
  assertTrue(
      "addAll(n, allPresent) should return true",
      getList().addAll(0, MinimalCollection.of(e0())));
  expectAdded(0, e0());
}
项目:guava-mock    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_unsupportedAllPresent() {
  try {
    getList().addAll(0, MinimalCollection.of(e0()));
    fail("addAll(n, allPresent) should throw");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_supportedSomePresent() {
  assertTrue(
      "addAll(n, allPresent) should return true",
      getList().addAll(0, MinimalCollection.of(e0(), e3())));
  expectAdded(0, e0(), e3());
}
项目:guava-mock    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_unsupportedSomePresent() {
  try {
    getList().addAll(0, MinimalCollection.of(e0(), e3()));
    fail("addAll(n, allPresent) should throw");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
  expectMissing(e3());
}
项目:guava-mock    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
public void testAddAllAtIndex_negative() {
  try {
    getList().addAll(-1, MinimalCollection.of(e3()));
    fail("addAll(-1, e) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
  expectMissing(e3());
}
项目:guava-mock    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
public void testAddAllAtIndex_tooLarge() {
  try {
    getList().addAll(getNumElements() + 1, MinimalCollection.of(e3()));
    fail("addAll(size + 1, e) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
  expectMissing(e3());
}
项目:googles-monorepo-demo    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
public void testAddAllAtIndex_tooLarge() {
  try {
    getList().addAll(getNumElements() + 1, MinimalCollection.of(e3()));
    fail("addAll(size + 1, e) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
  expectMissing(e3());
}
项目:guava-mock    文件:CollectionAddAllTester.java   
@CollectionFeature.Require(absent = SUPPORTS_ADD)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_unsupportedSomePresent() {
  try {
    collection.addAll(MinimalCollection.of(e3(), e0()));
    fail("addAll(somePresent) should throw");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:CollectionAddAllTester.java   
@CollectionFeature.Require({SUPPORTS_ADD, FAILS_FAST_ON_CONCURRENT_MODIFICATION})
@CollectionSize.Require(absent = ZERO)
public void testAddAllConcurrentWithIteration() {
  try {
    Iterator<E> iterator = collection.iterator();
    assertTrue(collection.addAll(MinimalCollection.of(e3(), e0())));
    iterator.next();
    fail("Expected ConcurrentModificationException");
  } catch (ConcurrentModificationException expected) {
    // success
  }
}
项目:guava-mock    文件:CollectionAddAllTester.java   
@CollectionFeature.Require(absent = SUPPORTS_ADD)
@CollectionSize.Require(absent = ZERO)
public void testAddAll_unsupportedAllPresent() {
  try {
    assertFalse(
        "addAll(allPresent) should return false or throw",
        collection.addAll(MinimalCollection.of(e0())));
  } catch (UnsupportedOperationException tolerated) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ImmutableMultisetTest.java   
public void testCopyOf_collectionContainingNull() {
  Collection<String> c = MinimalCollection.of("a", null, "b");
  try {
    ImmutableMultiset.copyOf(c);
    fail();
  } catch (NullPointerException expected) {}
}
项目:guava-mock    文件:ImmutableListTest.java   
public void testCopyOf_collectionContainingNull() {
  Collection<String> c = MinimalCollection.of("a", null, "b");
  try {
    ImmutableList.copyOf(c);
    fail();
  } catch (NullPointerException expected) {
  }
}
项目:guava-mock    文件:ImmutableListTest.java   
public void testSortedCopyOf_natural_containsNull() {
  Collection<Integer> c = MinimalCollection.of(1, 3, null, 2);
  try {
    ImmutableList.sortedCopyOf(c);
    fail("Expected NPE");
  } catch (NullPointerException expected) {
  }
}
项目:guava-mock    文件:ImmutableListTest.java   
public void testSortedCopyOf_containsNull() {
  Collection<String> c = MinimalCollection.of("a", "b", "A", null, "c");
  try {
    ImmutableList.sortedCopyOf(String.CASE_INSENSITIVE_ORDER, c);
    fail("Expected NPE");
  } catch (NullPointerException expected) {
  }
}