Java Code Examples for com.google.common.collect.testing.features.ListFeature

The following are top voted examples for showing how to use com.google.common.collect.testing.features.ListFeature. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: guava-mock   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 2
Project: guava-mock   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 3
Project: guava-mock   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 4
Project: guava-mock   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 5
Project: guava-mock   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 6
Project: googles-monorepo-demo   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 7
Project: googles-monorepo-demo   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 8
Project: googles-monorepo-demo   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 9
Project: googles-monorepo-demo   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 10
Project: googles-monorepo-demo   File: TestsForListsInJavaUtil.java   View source code 6 votes vote down vote up
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();
}
 
Example 11
Project: googles-monorepo-demo   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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());
}
 
Example 12
Project: guava-mock   File: ListMultimapTestSuiteBuilder.java   View source code 5 votes vote down vote up
@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;
}
 
Example 13
Project: guava-mock   File: ListRemoveAtIndexTester.java   View source code 5 votes vote down vote up
@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();
}
 
Example 14
Project: guava-mock   File: ListRemoveAtIndexTester.java   View source code 5 votes vote down vote up
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
public void testRemoveAtIndex_negative() {
  try {
    getList().remove(-1);
    fail("remove(-1) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
}
 
Example 15
Project: guava-mock   File: ListRemoveAtIndexTester.java   View source code 5 votes vote down vote up
@ListFeature.Require(SUPPORTS_REMOVE_WITH_INDEX)
public void testRemoveAtIndex_tooLarge() {
  try {
    getList().remove(getNumElements());
    fail("remove(size) should throw");
  } catch (IndexOutOfBoundsException expected) {
  }
  expectUnchanged();
}
 
Example 16
Project: guava-mock   File: ListRemoveAtIndexTester.java   View source code 5 votes vote down vote up
@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
  }
}
 
Example 17
Project: guava-mock   File: ListReplaceAllTester.java   View source code 5 votes vote down vote up
@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();
}
 
Example 18
Project: guava-mock   File: ListAddAtIndexTester.java   View source code 5 votes vote down vote up
@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();
}
 
Example 19
Project: googles-monorepo-demo   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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());
}
 
Example 20
Project: guava-mock   File: ListAddAtIndexTester.java   View source code 5 votes vote down vote up
@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
  }
}
 
Example 21
Project: googles-monorepo-demo   File: ListSetTester.java   View source code 5 votes vote down vote up
@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());
}
 
Example 22
Project: guava-mock   File: ListAddAtIndexTester.java   View source code 5 votes vote down vote up
@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)");
}
 
Example 23
Project: guava-mock   File: ListAddAtIndexTester.java   View source code 5 votes vote down vote up
@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());
}
 
Example 24
Project: guava-mock   File: ListAddAtIndexTester.java   View source code 5 votes vote down vote up
@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());
}
 
Example 25
Project: guava-mock   File: ListSubListTester.java   View source code 5 votes vote down vote up
@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);
}
 
Example 26
Project: googles-monorepo-demo   File: ListSetTester.java   View source code 5 votes vote down vote up
@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();
}
 
Example 27
Project: guava-mock   File: ListSubListTester.java   View source code 5 votes vote down vote up
@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);
}
 
Example 28
Project: googles-monorepo-demo   File: ListSetTester.java   View source code 5 votes vote down vote up
@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();
}
 
Example 29
Project: guava-mock   File: ListSubListTester.java   View source code 5 votes vote down vote up
@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);
}
 
Example 30
Project: guava-mock   File: ListSubListTester.java   View source code 5 votes vote down vote up
@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());
}
 
Example 31
Project: guava-mock   File: ListSubListTester.java   View source code 5 votes vote down vote up
@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);
}
 
Example 32
Project: guava-mock   File: ListSubListTester.java   View source code 5 votes vote down vote up
@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);
}
 
Example 33
Project: guava-mock   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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());
}
 
Example 34
Project: guava-mock   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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();
}
 
Example 35
Project: guava-mock   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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());
}
 
Example 36
Project: guava-mock   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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());
}
 
Example 37
Project: guava-mock   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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();
}
 
Example 38
Project: guava-mock   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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);
}
 
Example 39
Project: guava-mock   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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)");
}
 
Example 40
Project: googles-monorepo-demo   File: ListAddAllAtIndexTester.java   View source code 5 votes vote down vote up
@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());
}