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

The following examples show how to use com.google.common.collect.testing.features.CollectionSize. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public Test testModelImpl(String name, ModelFactory factory) {
	try {
		return SetTestSuiteBuilder.using(new TestModelGenerator(factory))
				.named(name)
				.withFeatures(CollectionSize.ANY, CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
						CollectionFeature.SERIALIZABLE, CollectionFeature.SUPPORTS_ADD,
						CollectionFeature.SUPPORTS_ITERATOR_REMOVE, CollectionFeature.SUPPORTS_REMOVE,
						CollectionFeature.NON_STANDARD_TOSTRING)
				// FIXME suppressing test on iterator element remove behavior
				.suppressing(CollectionIteratorTester.class
						.getDeclaredMethod("testIterator_unknownOrderRemoveSupported"))
				.createTestSuite();
	} catch (NoSuchMethodException | SecurityException e) {
		throw new RuntimeException(e);
	}
}
 
Example 2
public Test testsForPatriciaTrie() {
  return MapTestSuiteBuilder
      .using(new TestStringMapGenerator() {
        @Override
        protected Map<String, String> create(
            final Entry<String, String>[] entries) {
          return populate(new PatriciaTrie<String>(), entries);
        }
      })
      .named("PatriciaTrie")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          MapFeature.ALLOWS_NULL_ENTRY_QUERIES,
          MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          // Assumes Insertion Order if you don't implement SortedMap
          // CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForPatriciaTrie())
      .createTestSuite();
}
 
Example 3
Source Project: unsafe   Source File: UnsafeArrayListTest.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static TestSuite suite() {

      return ListTestSuiteBuilder
          .using(new TestStringListGenerator() {

            @Override
            protected List<String> create(String[] elements) {
              return new UnsafeArrayList<>(String.class, Arrays.asList(elements));
            }
          })

          .named("UnsafeArrayList")

          // Guava has a host of "features" in the
          // com.google.common.collect.testing.features package. Use
          // them to specify how the collection should behave, and
          // what operations are supported.
          .withFeatures(ListFeature.GENERAL_PURPOSE, CollectionSize.ANY).createTestSuite();
    }
 
Example 4
Source Project: cyclops   Source File: QueueXTestSuite.java    License: Apache License 2.0 6 votes vote down vote up
public Test testForOneToWayUseMySet() {
    return QueueTestSuiteBuilder
            .using(new QueueXGenerator())
            .named("QueueX test")
            .withFeatures(
                    CollectionSize.ANY,
                    CollectionFeature.ALLOWS_NULL_VALUES,
                    CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                    CollectionFeature.SUPPORTS_ADD,

                    CollectionFeature.SUPPORTS_REMOVE,
                    CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
                    CollectionFeature.SUPPORTS_REMOVE
            )
            .createTestSuite();
}
 
Example 5
Source Project: cyclops   Source File: ListXTestSuite.java    License: Apache License 2.0 6 votes vote down vote up
public Test testForOneToWayUseMySet() {
    return ListTestSuiteBuilder
            .using(new ListXGenerator())
            .named("listX test")
            .withFeatures(
                    CollectionSize.ANY,
                    CollectionFeature.ALLOWS_NULL_VALUES,
                    CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                    CollectionFeature.SUPPORTS_ADD,
                    ListFeature.SUPPORTS_SET,
                    CollectionFeature.SUPPORTS_REMOVE,
                    CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
                    CollectionFeature.SUPPORTS_REMOVE
            )
            .createTestSuite();
}
 
Example 6
Source Project: cyclops   Source File: DequeXTestSuite.java    License: Apache License 2.0 6 votes vote down vote up
public Test testForOneToWayUseMySet() {
    return QueueTestSuiteBuilder
            .using(new DequeXGenerator())
            .named("DequeX test")
            .withFeatures(
                    CollectionSize.ANY,
                    CollectionFeature.ALLOWS_NULL_VALUES,
                    CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                    CollectionFeature.SUPPORTS_ADD,

                    CollectionFeature.SUPPORTS_REMOVE,
                    CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
                    CollectionFeature.SUPPORTS_REMOVE
            )
            .createTestSuite();
}
 
Example 7
Source Project: caffeine   Source File: SingleConsumerQueueTests.java    License: Apache License 2.0 6 votes vote down vote up
private static TestSuite queueTest(boolean optimistic) {
  return QueueTestSuiteBuilder
      .using(new TestStringQueueGenerator() {
          @Override public Queue<String> create(String[] elements) {
            Queue<String> queue = optimistic
                ? SingleConsumerQueue.optimistic()
                : SingleConsumerQueue.linearizable();
            queue.addAll(MinimalCollection.of(elements));
            return queue;
          }
        })
      .named(SingleConsumerQueue.class.getSimpleName())
      .withFeatures(
          CollectionFeature.ALLOWS_NULL_QUERIES,
          CollectionFeature.GENERAL_PURPOSE,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.KNOWN_ORDER,
          CollectionSize.ANY)
      .createTestSuite();
}
 
Example 8
Source Project: caffeine   Source File: LinkedDequeTests.java    License: Apache License 2.0 6 votes vote down vote up
static Test suite(String name, Supplier<LinkedDeque<LinkedValue>> supplier) {
  return QueueTestSuiteBuilder
      .using(new TestLinkedValueGenerator() {
        @Override public Queue<LinkedValue> create(LinkedValue[] elements) {
          Deque<LinkedValue> deque = useTarget ? supplier.get() : new ArrayDeque<>();
          deque.addAll(MinimalCollection.of(elements));
          useTarget = false;
          return deque;
        }
      })
      .named(name)
      .withFeatures(
          CollectionFeature.ALLOWS_NULL_QUERIES,
          CollectionFeature.GENERAL_PURPOSE,
          CollectionFeature.KNOWN_ORDER,
          CollectionSize.ANY)
      .withSetUp(() -> useTarget = true)
      .withTearDown(() -> {
        Arrays.asList(a, b, c, d, e).forEach(value -> {
          value.setNextInAccessOrder(null);
          value.setPreviousInAccessOrder(null);
        });
      })
      .createTestSuite();
}
 
Example 9
public Test testsForPauselessHashMap() {
    return MapTestSuiteBuilder
            .using(new TestStringMapGenerator() {
                @Override
                protected Map<String, String> create(
                        Map.Entry<String, String>[] entries) {
                    return toHashMap(entries);
                }
            })
            .named("HashMap")
            .withFeatures(
                    MapFeature.GENERAL_PURPOSE,
                    MapFeature.ALLOWS_NULL_KEYS,
                    MapFeature.ALLOWS_NULL_VALUES,
                    MapFeature.ALLOWS_ANY_NULL_QUERIES,
                    MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                    CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
                    CollectionFeature.SERIALIZABLE,
                    CollectionSize.ANY)
            .suppressing(suppressForHashMap())
            .createTestSuite();
}
 
Example 10
Source Project: JCTools   Source File: NonBlockingHashMapTest.java    License: Apache License 2.0 6 votes vote down vote up
private static <T> TestSuite mapTestSuite(TestMapGenerator<T, T> testMapGenerator, String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }

        @Override
        protected List<Class<? extends AbstractTester>> getTesters()
        {
            List<Class<? extends AbstractTester>> testers = new ArrayList<>(super.getTesters());
            // NonBlockingHashMap doesn't support null in putIfAbsent and provides putIfAbsentAllowsNull instead
            testers.remove(MapReplaceEntryTester.class);
            testers.remove(MapReplaceTester.class);
            return testers;
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 11
Source Project: xtext-lib   Source File: MapExtensionsTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static TestSuite suite() {
	return MapTestSuiteBuilder
			// The create method is called with an array of elements
			// that should populate the collection.
			.using(new TestStringMapGenerator() {
				@Override
				protected Map<String, String> create(Entry<String, String>[] source) {
					Map<String, String> left = Maps.newHashMap();
					Map<String, String> right = Maps.newHashMap();
					for(int i = 0; i < source.length; i++) {
						Entry<String, String> entry = source[i];
						if (right.containsKey(entry.getKey())) {
							left.put(entry.getKey(), right.get(entry.getKey()));
							right.put(entry.getKey(), entry.getValue());
						} else if (i % 2 != 0) {
							left.put(entry.getKey(), entry.getValue());	
						} else {
							right.put(entry.getKey(), entry.getValue());
							if (i % 4 != 0) {
								left.put(entry.getKey(), "will be ignored");
							}
						}
					}
					return new UnmodifiableMergingMapView(left, right);
				}
			}).named("Guava-based UnmodifiableMergingMapView tests")
			.withFeatures(
					MapFeature.ALLOWS_NULL_KEYS,
					MapFeature.ALLOWS_NULL_VALUES,
					MapFeature.ALLOWS_ANY_NULL_QUERIES,
					MapFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
					CollectionFeature.ALLOWS_NULL_QUERIES,
					CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
					CollectionSize.ANY)
			.createTestSuite();
}
 
Example 12
Source Project: cyclops   Source File: SetXTestSuite.java    License: Apache License 2.0 5 votes vote down vote up
public Test testForOneToWayUseMySet() {
    return SetTestSuiteBuilder
            .using(new SetXGenerator())
            .named("setX test")
            .withFeatures(
                    CollectionSize.ANY,
                    CollectionFeature.ALLOWS_NULL_VALUES,
                    CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                    CollectionFeature.SUPPORTS_ADD,
                    CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
                    CollectionFeature.SUPPORTS_REMOVE
            )
            .createTestSuite();
}
 
Example 13
Source Project: cyclops   Source File: SortedSetTestSuite.java    License: Apache License 2.0 5 votes vote down vote up
public Test testForOneToWayUseMySet() {
    return SetTestSuiteBuilder
            .using(new SetXGenerator())
            .named("setX test")
            .withFeatures(
                    CollectionSize.ANY,
                    CollectionFeature.ALLOWS_NULL_VALUES,
                    CollectionFeature.FAILS_FAST_ON_CONCURRENT_MODIFICATION,
                    CollectionFeature.SUPPORTS_ADD,
                    CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
                    CollectionFeature.SUPPORTS_REMOVE
            )
            .createTestSuite();
}
 
Example 14
Source Project: caffeine   Source File: MapTestFactory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a test suite.
 *
 * @param name the name of the cache type under test
 * @param generator the map generator
 * @return a suite of tests
 */
public static Test suite(String name, TestMapGenerator<?, ?> generator) {
  return ConcurrentMapTestSuiteBuilder
      .using(generator)
      .named(name)
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          MapFeature.ALLOWS_NULL_ENTRY_QUERIES,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionSize.ANY)
      .createTestSuite();
}
 
Example 15
Source Project: agrona   Source File: Int2IntHashMapConformanceTest.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 16
Source Project: agrona   Source File: Long2LongHashMapConformanceTest.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 17
Source Project: agrona   Source File: Long2ObjectHashMapConformanceTest.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 18
Source Project: agrona   Source File: Object2IntHashMapConformanceTest.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 19
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 20
Source Project: agrona   Source File: Int2ObjectHashMapConformanceTest.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 21
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        MapFeature.ALLOWS_NULL_VALUES,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 22
Source Project: agrona   Source File: Object2LongHashMapConformanceTest.java    License: Apache License 2.0 5 votes vote down vote up
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 23
Source Project: agrona   Source File: ObjectHashSetConformanceTest.java    License: Apache License 2.0 5 votes vote down vote up
public static TestSuite suite()
{
    return SetTestSuiteBuilder.using(new Generator())
        .named("ObjectHashSet Tests")
        .withFeatures(CollectionSize.ANY,
            CollectionFeature.NON_STANDARD_TOSTRING,
            CollectionFeature.SUPPORTS_ADD,
            CollectionFeature.SUPPORTS_REMOVE,
            CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
            CollectionFeature.REMOVE_OPERATIONS)
        .createTestSuite();
}
 
Example 24
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        MapFeature.ALLOWS_NULL_VALUES,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 25
private static <T> TestSuite mapTestSuite(final TestMapGenerator<T, T> testMapGenerator, final String name)
{
    return new MapTestSuiteBuilder<T, T>()
    {
        {
            usingGenerator(testMapGenerator);
        }
    }.withFeatures(
        MapFeature.GENERAL_PURPOSE,
        MapFeature.ALLOWS_NULL_VALUES,
        CollectionSize.ANY,
        CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
        .named(name)
        .createTestSuite();
}
 
Example 26
Source Project: JCTools   Source File: SingleWriterHashSetTest.java    License: Apache License 2.0 5 votes vote down vote up
public static Test suite() throws Exception {
    return SetTestSuiteBuilder.using(new TestStringSetGenerator() {
        @Override
        protected Set<String> create(String[] elements) {
            Set<String> set = new SingleWriterHashSet<>(elements.length);
            Collections.addAll(set, elements);
            return set;
        }
    }).withFeatures(
            SetFeature.GENERAL_PURPOSE,
            CollectionSize.ANY,
            CollectionFeature.NON_STANDARD_TOSTRING)
      .named(SingleWriterHashSet.class.getSimpleName())
      .createTestSuite();
}
 
Example 27
Source Project: Chronicle-Map   Source File: GuavaTest.java    License: Apache License 2.0 4 votes vote down vote up
private static void configureSuite(MapTestSuiteBuilder<String, String> suite) {
    suite.withFeatures(GENERAL_PURPOSE)
            .withFeatures(CollectionSize.ANY)
            .withFeatures(CollectionFeature.REMOVE_OPERATIONS)
            .withFeatures(RESTRICTS_KEYS, RESTRICTS_VALUES);
}