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

项目:guava-mock    文件:TestsForListsInJavaUtil.java   
public Test testsForArraysAsList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              return Arrays.asList(elements.clone());
            }
          })
      .named("Arrays.asList")
      .withFeatures(
          ListFeature.SUPPORTS_SET,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ANY)
      .suppressing(suppressForArraysAsList())
      .createTestSuite();
}
项目:guava-mock    文件:TestsForListsInJavaUtil.java   
public Test testsForArrayList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              return new ArrayList<String>(MinimalCollection.of(elements));
            }
          })
      .named("ArrayList")
      .withFeatures(
          ListFeature.GENERAL_PURPOSE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
          CollectionSize.ANY)
      .suppressing(suppressForArrayList())
      .createTestSuite();
}
项目:guava-mock    文件:TestsForListsInJavaUtil.java   
public Test testsForCopyOnWriteArrayList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              return new CopyOnWriteArrayList<String>(MinimalCollection.of(elements));
            }
          })
      .named("CopyOnWriteArrayList")
      .withFeatures(
          ListFeature.SUPPORTS_ADD_WITH_INDEX,
          ListFeature.SUPPORTS_REMOVE_WITH_INDEX,
          ListFeature.SUPPORTS_SET,
          CollectionFeature.SUPPORTS_ADD,
          CollectionFeature.SUPPORTS_REMOVE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ANY)
      .suppressing(suppressForCopyOnWriteArrayList())
      .createTestSuite();
}
项目:guava-mock    文件:TestsForListsInJavaUtil.java   
public Test testsForCheckedList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              List<String> innerList = new ArrayList<String>();
              Collections.addAll(innerList, elements);
              return Collections.checkedList(innerList, String.class);
            }
          })
      .named("checkedList/ArrayList")
      .withFeatures(
          ListFeature.GENERAL_PURPOSE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.RESTRICTS_ELEMENTS,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ANY)
      .suppressing(suppressForCheckedList())
      .createTestSuite();
}
项目:guava-mock    文件:TestsForListsInJavaUtil.java   
private Test testsForVector() {
  return ListTestSuiteBuilder
      .using(new TestStringListGenerator() {
        @Override
        protected List<String> create(String[] elements) {
          return new Vector<String>(MinimalCollection.of(elements));
        }
      })
      .named("Vector")
      .withFeatures(
          ListFeature.GENERAL_PURPOSE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .createTestSuite();
}
项目:googles-monorepo-demo    文件:TestsForListsInJavaUtil.java   
public Test testsForArraysAsList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              return Arrays.asList(elements.clone());
            }
          })
      .named("Arrays.asList")
      .withFeatures(
          ListFeature.SUPPORTS_SET,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ANY)
      .suppressing(suppressForArraysAsList())
      .createTestSuite();
}
项目:googles-monorepo-demo    文件:TestsForListsInJavaUtil.java   
public Test testsForLinkedList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              return new LinkedList<String>(MinimalCollection.of(elements));
            }
          })
      .named("LinkedList")
      .withFeatures(
          ListFeature.GENERAL_PURPOSE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
          CollectionSize.ANY)
      .suppressing(suppressForLinkedList())
      .createTestSuite();
}
项目:googles-monorepo-demo    文件:TestsForListsInJavaUtil.java   
public Test testsForCopyOnWriteArrayList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              return new CopyOnWriteArrayList<String>(MinimalCollection.of(elements));
            }
          })
      .named("CopyOnWriteArrayList")
      .withFeatures(
          ListFeature.SUPPORTS_ADD_WITH_INDEX,
          ListFeature.SUPPORTS_REMOVE_WITH_INDEX,
          ListFeature.SUPPORTS_SET,
          CollectionFeature.SUPPORTS_ADD,
          CollectionFeature.SUPPORTS_REMOVE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ANY)
      .suppressing(suppressForCopyOnWriteArrayList())
      .createTestSuite();
}
项目:googles-monorepo-demo    文件:TestsForListsInJavaUtil.java   
public Test testsForCheckedList() {
  return ListTestSuiteBuilder.using(
          new TestStringListGenerator() {
            @Override
            public List<String> create(String[] elements) {
              List<String> innerList = new ArrayList<String>();
              Collections.addAll(innerList, elements);
              return Collections.checkedList(innerList, String.class);
            }
          })
      .named("checkedList/ArrayList")
      .withFeatures(
          ListFeature.GENERAL_PURPOSE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.RESTRICTS_ELEMENTS,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionSize.ANY)
      .suppressing(suppressForCheckedList())
      .createTestSuite();
}
项目:googles-monorepo-demo    文件:TestsForListsInJavaUtil.java   
private Test testsForVector() {
  return ListTestSuiteBuilder
      .using(new TestStringListGenerator() {
        @Override
        protected List<String> create(String[] elements) {
          return new Vector<String>(MinimalCollection.of(elements));
        }
      })
      .named("Vector")
      .withFeatures(
          ListFeature.GENERAL_PURPOSE,
          CollectionFeature.ALLOWS_NULL_VALUES,
          CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .createTestSuite();
}
项目:googles-monorepo-demo    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testAddAllAtIndex_end() {
  assertTrue(
      "addAll(end, disjoint) should return true",
      getList().addAll(getNumElements(), createDisjointCollection()));
  expectAdded(getNumElements(), createDisjointCollection());
}
项目:guava-mock    文件:ListMultimapTestSuiteBuilder.java   
@Override
Set<Feature<?>> computeMultimapGetFeatures(Set<Feature<?>> multimapFeatures) {
  Set<Feature<?>> derivedFeatures = super.computeMultimapGetFeatures(multimapFeatures);
  if (derivedFeatures.contains(CollectionFeature.SUPPORTS_ADD)) {
    derivedFeatures.add(ListFeature.SUPPORTS_ADD_WITH_INDEX);
  }
  if (derivedFeatures.contains(CollectionFeature.GENERAL_PURPOSE)) {
    derivedFeatures.add(ListFeature.GENERAL_PURPOSE);
  }
  return derivedFeatures;
}
项目:guava-mock    文件:ListRemoveAtIndexTester.java   
@ListFeature.Require(absent = SUPPORTS_REMOVE_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAtIndex_unsupported() {
  try {
    getList().remove(0);
    fail("remove(i) should throw");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListRemoveAtIndexTester.java   
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
public void testRemoveAtIndex_negative() {
  try {
    getList().remove(-1);
    fail("remove(-1) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListRemoveAtIndexTester.java   
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
public void testRemoveAtIndex_tooLarge() {
  try {
    getList().remove(getNumElements());
    fail("remove(size) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListRemoveAtIndexTester.java   
@CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testRemoveAtIndexConcurrentWithIteration() {
  try {
    Iterator<E> iterator = collection.iterator();
    getList().remove(getNumElements() / 2);
    iterator.next();
    fail("Expected ConcurrentModificationException");
  } catch (ConcurrentModificationException expected) {
    // success
  }
}
项目:guava-mock    文件:ListReplaceAllTester.java   
@CollectionSize.Require(absent = ZERO)
@ListFeature.Require(absent = SUPPORTS_SET)
public void testReplaceAll_unsupported() {
  try {
    getList().replaceAll(e -> e);
    fail("replaceAll() should throw UnsupportedOperationException");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListAddAtIndexTester.java   
@ListFeature.Require(absent = SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
/*
 * absent = ZERO isn't required, since unmodList.add() must
 * throw regardless, but it keeps the method name accurate.
 */
public void testAddAtIndex_unsupportedPresent() {
  try {
    getList().add(0, e0());
    fail("add(n, present) should throw");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
}
项目: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    文件:ListAddAtIndexTester.java   
@CollectionFeature.Require(FAILS_FAST_ON_CONCURRENT_MODIFICATION)
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
public void testAddAtIndexConcurrentWithIteration() {
  try {
    Iterator<E> iterator = collection.iterator();
    getList().add(0, e3());
    iterator.next();
    fail("Expected ConcurrentModificationException");
  } catch (ConcurrentModificationException expected) {
    // success
  }
}
项目:googles-monorepo-demo    文件:ListSetTester.java   
@CollectionSize.Require(absent = ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
@ListFeature.Require(SUPPORTS_SET)
public void testSet_replacingNull() {
  E[] elements = createSamplesArray();
  int i = aValidIndex();
  elements[i] = null;
  collection = getSubjectGenerator().create(elements);

  doTestSet(e3());
}
项目:guava-mock    文件:ListAddAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
@CollectionFeature.Require(absent = ALLOWS_NULL_VALUES)
public void testAddAtIndex_nullUnsupported() {
  try {
    getList().add(0, null);
    fail("add(n, null) should throw");
  } catch (NullPointerException expected) {
  }
  expectUnchanged();
  expectNullMissingWhenNullUnsupported("Should not contain null after unsupported add(n, null)");
}
项目:guava-mock    文件:ListAddAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
public void testAddAtIndex_negative() {
  try {
    getList().add(-1, e3());
    fail("add(-1, e) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
  expectMissing(e3());
}
项目:guava-mock    文件:ListAddAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
public void testAddAtIndex_tooLarge() {
  try {
    getList().add(getNumElements() + 1, e3());
    fail("add(size + 1, e) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
  expectMissing(e3());
}
项目:guava-mock    文件:ListSubListTester.java   
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
@CollectionSize.Require(absent = ZERO)
public void testSubList_subListRemoveAffectsOriginal() {
  List<E> subList = getList().subList(0, 1);
  subList.remove(0);
  List<E> expected = Arrays.asList(createSamplesArray()).subList(1, getNumElements());
  expectContents(expected);
}
项目:googles-monorepo-demo    文件:ListSetTester.java   
@CollectionSize.Require(absent = ZERO)
@ListFeature.Require(SUPPORTS_SET)
@CollectionFeature.Require(absent = ALLOWS_NULL_VALUES)
public void testSet_nullUnsupported() {
  try {
    getList().set(aValidIndex(), null);
    fail("set(null) should throw NullPointerException");
  } catch (NullPointerException expected) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListSubListTester.java   
@ListFeature.Require(SUPPORTS_SET)
@CollectionSize.Require(absent = ZERO)
public void testSubList_subListSetAffectsOriginal() {
  List<E> subList = getList().subList(0, 1);
  subList.set(0, e3());
  List<E> expected = Helpers.copyToList(createSamplesArray());
  expected.set(0, e3());
  expectContents(expected);
}
项目:googles-monorepo-demo    文件:ListSetTester.java   
@CollectionSize.Require(absent = ZERO)
@ListFeature.Require(absent = SUPPORTS_SET)
public void testSet_unsupported() {
  try {
    getList().set(aValidIndex(), e3());
    fail("set() should throw UnsupportedOperationException");
  } catch (UnsupportedOperationException expected) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListSubListTester.java   
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testSubList_subListRemoveAffectsOriginalLargeList() {
  List<E> subList = getList().subList(1, 3);
  subList.remove(e2());
  List<E> expected = Helpers.copyToList(createSamplesArray());
  expected.remove(2);
  expectContents(expected);
}
项目:guava-mock    文件:ListSubListTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testSubList_subListAddAtIndexAffectsOriginalLargeList() {
  List<E> subList = getList().subList(2, 3);
  subList.add(0, e3());
  expectAdded(2, e3());
}
项目:guava-mock    文件:ListSubListTester.java   
@ListFeature.Require(SUPPORTS_SET)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testSubList_subListSetAffectsOriginalLargeList() {
  List<E> subList = getList().subList(1, 2);
  subList.set(0, e3());
  List<E> expected = Helpers.copyToList(createSamplesArray());
  expected.set(1, e3());
  expectContents(expected);
}
项目:guava-mock    文件:ListSubListTester.java   
@ListFeature.Require(SUPPORTS_SET)
@CollectionSize.Require(absent = {ZERO, ONE})
public void testSubList_originalListSetAffectsSubListLargeList() {
  List<E> subList = getList().subList(1, 3);
  getList().set(1, e3());
  assertEquals(
      "A set() call to a list after a sublist has been created "
          + "should be reflected in the sublist",
      Arrays.asList(e3(), e2()),
      subList);
}
项目: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(absent = SUPPORTS_ADD_WITH_INDEX)
public void testAddAllAtIndex_unsupportedNothing() {
  try {
    assertFalse(
        "addAll(n, nothing) should return false or throw",
        getList().addAll(0, emptyCollection()));
  } catch (UnsupportedOperationException tolerated) {
  }
  expectUnchanged();
}
项目:guava-mock    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testAddAllAtIndex_nullSupported() {
  List<E> containsNull = singletonList(null);
  assertTrue("addAll(n, containsNull) should return true", getList().addAll(0, containsNull));
  /*
   * We need (E) to force interpretation of null as the single element of a
   * varargs array, not the array itself
   */
  expectAdded(0, (E) null);
}
项目:guava-mock    文件:ListAddAllAtIndexTester.java   
@ListFeature.Require(SUPPORTS_ADD_WITH_INDEX)
@CollectionFeature.Require(absent = ALLOWS_NULL_VALUES)
public void testAddAllAtIndex_nullUnsupported() {
  List<E> containsNull = singletonList(null);
  try {
    getList().addAll(0, containsNull);
    fail("addAll(n, containsNull) should throw");
  } catch (NullPointerException expected) {
  }
  expectUnchanged();
  expectNullMissingWhenNullUnsupported(
      "Should not contain null after unsupported addAll(n, containsNull)");
}
项目: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());
}