Package com.google.common.collect.testing

Examples of com.google.common.collect.testing.TestStringListGenerator


  @GwtIncompatible("suite")
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ListsTest.class);

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            String[] rest = new String[elements.length - 1];
            System.arraycopy(elements, 1, rest, 0, elements.length - 1);
            return Lists.asList(elements[0], rest);
          }
        })
        .named("Lists.asList, 2 parameter")
        .withFeatures(CollectionSize.SEVERAL, CollectionSize.ONE,
            CollectionFeature.SERIALIZABLE,
            CollectionFeature.ALLOWS_NULL_VALUES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            String[] rest = new String[elements.length - 2];
            System.arraycopy(elements, 2, rest, 0, elements.length - 2);
            return Lists.asList(elements[0], elements[1], rest);
          }
        })
        .named("Lists.asList, 3 parameter")
        .withFeatures(CollectionSize.SEVERAL,
            CollectionFeature.SERIALIZABLE,
            CollectionFeature.ALLOWS_NULL_VALUES)
        .createTestSuite());

    final Function<String, String> removeFirst
        = new RemoveFirstFunction();

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newArrayList();
            for (String element : elements) {
              fromList.add("q" + checkNotNull(element));
            }
            return Lists.transform(fromList, removeFirst);
          }
        })
        .named("Lists.transform, random access, no nulls")
        .withFeatures(CollectionSize.ANY,
            ListFeature.REMOVE_OPERATIONS,
            CollectionFeature.SERIALIZABLE,
            CollectionFeature.ALLOWS_NULL_QUERIES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newLinkedList();
            for (String element : elements) {
              fromList.add("q" + checkNotNull(element));
            }
            return Lists.transform(fromList, removeFirst);
          }
        })
        .named("Lists.transform, sequential access, no nulls")
        .withFeatures(CollectionSize.ANY,
            ListFeature.REMOVE_OPERATIONS,
            CollectionFeature.SERIALIZABLE,
            CollectionFeature.ALLOWS_NULL_QUERIES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newArrayList(elements);
            return Lists.transform(fromList, Functions.<String>identity());
          }
        })
        .named("Lists.transform, random access, nulls")
        .withFeatures(CollectionSize.ANY,
            ListFeature.REMOVE_OPERATIONS,
            CollectionFeature.SERIALIZABLE,
            CollectionFeature.ALLOWS_NULL_VALUES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            List<String> fromList =
                Lists.newLinkedList(asList(elements));
            return Lists.transform(fromList, Functions.<String>identity());
          }
        })
        .named("Lists.transform, sequential access, nulls")
        .withFeatures(CollectionSize.ANY,
            ListFeature.REMOVE_OPERATIONS,
            CollectionFeature.SERIALIZABLE,
            CollectionFeature.ALLOWS_NULL_VALUES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
      @Override protected List<String> create(String[] elements) {
        List<String> list = Lists.newArrayList();
        for (int i = elements.length - 1; i >= 0; i--)
          list.add(elements[i]);
        return Lists.reverse(list);
      }
    }).named("Lists.reverse[ArrayList]").withFeatures(CollectionSize.ANY,
        CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.GENERAL_PURPOSE)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
      @Override protected List<String> create(String[] elements) {
        String[] reverseElements = new String[elements.length];
        for (int i = elements.length - 1, j = 0; i >= 0; i--, j++)
          reverseElements[j] = elements[i];
        return Lists.reverse(asList(reverseElements));
      }
    }).named("Lists.reverse[Arrays.asList]").withFeatures(CollectionSize.ANY,
        CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.SUPPORTS_SET)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
      @Override protected List<String> create(String[] elements) {
        List<String> list = Lists.newLinkedList();
        for (int i = elements.length - 1; i >= 0; i--)
          list.add(elements[i]);
        return Lists.reverse(list);
      }
    }).named("Lists.reverse[LinkedList]").withFeatures(CollectionSize.ANY,
        CollectionFeature.ALLOWS_NULL_VALUES, ListFeature.GENERAL_PURPOSE)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
      @Override protected List<String> create(String[] elements) {
        ImmutableList.Builder<String> builder = ImmutableList.builder();
        for (int i = elements.length - 1; i >= 0; i--)
          builder.add(elements[i]);
        return Lists.reverse(builder.build());
View Full Code Here


    assertEquals(newArrayList("b", "d"), list);
  }

  @GwtIncompatible("ListTestSuiteBuilder")
  private static Test testsForRemoveAllAndRetainAll() {
    return ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override public List<String> create(final String[] elements) {
            final List<String> delegate = newArrayList(elements);
            return new ForwardingList<String>() {
              @Override protected List<String> delegate() {
                return delegate;
View Full Code Here

        })
        .named("TreeMultimap.get")
        .withFeatures(COLLECTION_FEATURES_ORDER)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            ListMultimap<Integer, String> multimap
                = ArrayListMultimap.create();
            populateMultimapForGet(multimap, elements);
            return multimap.get(3);
          }
        })
        .named("ArrayListMultimap.get")
        .withFeatures(LIST_FEATURES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            ListMultimap<Integer, String> multimap
                = Multimaps.synchronizedListMultimap(
                ArrayListMultimap.<Integer, String>create());
            populateMultimapForGet(multimap, elements);
            return multimap.get(3);
          }
        })
        .named("synchronized ArrayListMultimap.get")
        .withFeatures(LIST_FEATURES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            ListMultimap<Integer, String> multimap
                = LinkedListMultimap.create();
            populateMultimapForGet(multimap, elements);
            return multimap.get(3);
          }
        })
        .named("LinkedListMultimap.get")
        .withFeatures(LIST_FEATURES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            ImmutableListMultimap.Builder<Integer, String> builder
                = ImmutableListMultimap.builder();
            ListMultimap<Integer, String> multimap
                = builder.put(2, "foo")
View Full Code Here

* @author Jared Levy
*/
public class ImmutableListTest extends TestCase {
  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            return ImmutableList.of(elements);
          }
        })
        .named("ImmutableList")
        .withFeatures(CollectionSize.ANY)
        .createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            Builder<String> builder = ImmutableList.<String>builder();
            for (String element : elements) {
              builder.add(element);
            }
            return builder.build();
          }
        })
        .named("ImmutableList, built with Builder.add")
        .withFeatures(CollectionSize.ANY)
        .createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            return ImmutableList.<String>builder()
                .addAll(asList(elements))
                .build();
          }
        })
        .named("ImmutableList, built with Builder.addAll")
        .withFeatures(CollectionSize.ANY)
        .createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            return SerializableTester.reserialize(ImmutableList.of(elements));
          }
        })
        .named("ImmutableList, reserialized")
        .withFeatures(CollectionSize.ANY)
        .createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            String[] suffix = {"f", "g"};
            String[] all = concat(elements, suffix, String.class);
            return ImmutableList.of(all)
                .subList(0, elements.length);
          }
        })
        .named("ImmutableList, head subList")
        .withFeatures(CollectionSize.ANY)
        .createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            String[] prefix = {"f", "g"};
            String[] all = concat(prefix, elements, String.class);
            return ImmutableList.of(all)
                .subList(2, elements.length + 2);
          }
        })
        .named("ImmutableList, tail subList")
        .withFeatures(CollectionSize.ANY)
        .createTestSuite());
    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            String[] prefix = {"f", "g"};
            String[] suffix = {"h", "i"};
            String[] all = concat(prefix,
                concat(elements, suffix, String.class), String.class);
View Full Code Here

        list.iterator(), newArrayList("b", "e", "d")));
    assertEquals(newArrayList("b", "d"), list);
  }

  private static Test testsForRemoveAllAndRetainAll() {
    return ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override public List<String> create(final String[] elements) {
            final List<String> delegate = newArrayList(elements);
            return new ForwardingList<String>() {
              @Override protected List<String> delegate() {
                return delegate;
View Full Code Here

  public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ListsTest.class);

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            String[] rest = new String[elements.length - 1];
            System.arraycopy(elements, 1, rest, 0, elements.length - 1);
            return Lists.asList(elements[0], rest);
          }
        })
        .named("Lists.asList, 2 parameter")
        .withFeatures(CollectionSize.SEVERAL, CollectionSize.ONE,
            CollectionFeature.ALLOWS_NULL_VALUES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            String[] rest = new String[elements.length - 2];
            System.arraycopy(elements, 2, rest, 0, elements.length - 2);
            return Lists.asList(elements[0], elements[1], rest);
          }
        })
        .named("Lists.asList, 3 parameter")
        .withFeatures(CollectionSize.SEVERAL,
            CollectionFeature.ALLOWS_NULL_VALUES)
        .createTestSuite());

    final Function<String, String> removeFirst
        = new Function<String, String>() {
            public String apply(String from) {
              return (from.length() == 0) ? from : from.substring(1);
            }
          };

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newArrayList();
            for (String element : elements) {
              fromList.add("q" + checkNotNull(element));
            }
            return Lists.transform(fromList, removeFirst);
          }
        })
        .named("Lists.transform, random access, no nulls")
        .withFeatures(CollectionSize.ANY,
            ListFeature.REMOVE_OPERATIONS)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newLinkedList();
            for (String element : elements) {
              fromList.add("q" + checkNotNull(element));
            }
            return Lists.transform(fromList, removeFirst);
          }
        })
        .named("Lists.transform, sequential access, no nulls")
        .withFeatures(CollectionSize.ANY,
            ListFeature.REMOVE_OPERATIONS)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            List<String> fromList = Lists.newArrayList(elements);
            return Lists.transform(fromList, Functions.<String>identity());
          }
        })
        .named("Lists.transform, random access, nulls")
        .withFeatures(CollectionSize.ANY,
            ListFeature.REMOVE_OPERATIONS,
            CollectionFeature.ALLOWS_NULL_VALUES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            List<String> fromList =
                Lists.newLinkedList(asList(elements));
            return Lists.transform(fromList, Functions.<String>identity());
          }
View Full Code Here

      .withFeatures(CollectionSize.ANY,
          CollectionFeature.SERIALIZABLE_INCLUDING_VIEWS,
          CollectionFeature.ALLOWS_NULL_QUERIES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
        @Override
        protected List<String> create(String[] elements) {
          return ImmutableSortedMultiset.copyOf(elements).asList();
        }

        @Override
        public List<String> order(List<String> insertionOrder) {
          return Ordering.natural().sortedCopy(insertionOrder);
        }
      })
      .named("ImmutableSortedMultiset.asList")
      .withFeatures(CollectionSize.ANY,
          CollectionFeature.SERIALIZABLE,
          CollectionFeature.ALLOWS_NULL_QUERIES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
        @Override
        protected List<String> create(String[] elements) {
          Set<String> set = Sets.newHashSet();
          ImmutableSortedMultiset.Builder<String> builder = ImmutableSortedMultiset.naturalOrder();
          for (String s : elements) {
View Full Code Here

        .withFeatures(CollectionSize.ANY,
            CollectionFeature.SERIALIZABLE,
            CollectionFeature.ALLOWS_NULL_QUERIES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            return ImmutableMultiset.copyOf(elements).asList();
          }

          @Override
          public List<String> order(List<String> insertionOrder) {
            List<String> order = new ArrayList<String>();
            for (String s : insertionOrder) {
              int index = order.indexOf(s);
              if (index == -1) {
                order.add(s);
              } else {
                order.add(index, s);
              }
            }
            return order;
          }
        })
        .named("ImmutableMultiset.asList")
        .withFeatures(CollectionSize.ANY,
            CollectionFeature.SERIALIZABLE,
            CollectionFeature.ALLOWS_NULL_QUERIES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            Set<String> set = new HashSet<String>();
            ImmutableMultiset.Builder<String> builder = ImmutableMultiset.builder();
            for (String s : elements) {
              checkArgument(set.add(s));
View Full Code Here

        })
        .named("TreeMultimap.get")
        .withFeatures(COLLECTION_FEATURES_ORDER)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            ListMultimap<Integer, String> multimap
                = ArrayListMultimap.create();
            populateMultimapForGet(multimap, elements);
            return multimap.get(3);
          }
        })
        .named("ArrayListMultimap.get")
        .withFeatures(LIST_FEATURES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            ListMultimap<Integer, String> multimap
                = Multimaps.synchronizedListMultimap(
                ArrayListMultimap.<Integer, String>create());
            populateMultimapForGet(multimap, elements);
            return multimap.get(3);
          }
        })
        .named("synchronized ArrayListMultimap.get")
        .withFeatures(LIST_FEATURES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            ListMultimap<Integer, String> multimap
                = LinkedListMultimap.create();
            populateMultimapForGet(multimap, elements);
            return multimap.get(3);
          }
        })
        .named("LinkedListMultimap.get")
        .withFeatures(LIST_FEATURES)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override protected List<String> create(String[] elements) {
            ImmutableListMultimap.Builder<Integer, String> builder
                = ImmutableListMultimap.builder();
            ListMultimap<Integer, String> multimap
                = builder.put(2, "foo")
                .putAll(3, elements)
                .build();
            return multimap.get(3);
          }
        })
        .named("ImmutableListMultimap.get")
        .withFeatures(CollectionSize.ANY)
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(
        new TestStringSetGenerator() {
          @Override protected Set<String> create(String[] elements) {
            PopulatableMapAsMultimap<Integer, String> multimap
                = PopulatableMapAsMultimap.create();
            populateMultimapForGet(multimap, elements);
            return multimap.build().get(3);
          }
        })
        .named("Multimaps.forMap.get")
        .withFeatures(FOR_MAP_FEATURES_ONE)
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
          @Override protected Set<String> create(String[] elements) {
            SetMultimap<Integer, String> multimap
                = LinkedHashMultimap.create();
            populateMultimapForGet(multimap, elements);
            multimap.put(3, "badvalue");
            multimap.put(55556, "foo");
            return (Set<String>) Multimaps.filterEntries(multimap, FILTER_GET_PREDICATE).get(3);
          }
        })
        .named("Multimaps.filterEntries.get")
        .withFeatures(COLLECTION_FEATURES_ORDER)
        .suppressing(CollectionIteratorTester.getIteratorKnownOrderRemoveSupportedMethod())
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
          @Override protected Set<String> create(String[] elements) {
            Multimap<String, Integer> multimap = HashMultimap.create();
            populateMultimapForKeySet(multimap, elements);
            return multimap.keySet();
          }
        })
        .named("HashMultimap.keySet")
        .withFeatures(COLLECTION_FEATURES_REMOVE)
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
          @Override protected Set<String> create(String[] elements) {
            Multimap<String, Integer> multimap
                = LinkedHashMultimap.create();
            populateMultimapForKeySet(multimap, elements);
            return multimap.keySet();
          }
        })
        .named("LinkedHashMultimap.keySet")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(
        new TestStringSortedSetGenerator() {
          @Override protected SortedSet<String> create(String[] elements) {
            TreeMultimap<String, Integer> multimap =
                TreeMultimap.create(Ordering.natural().nullsFirst(),
                    Ordering.natural().nullsLast());
            populateMultimapForKeySet(multimap, elements);
            return multimap.keySet();
          }
        })
        .named("TreeMultimap.keySet")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
          @Override protected Set<String> create(String[] elements) {
            Multimap<String, Integer> multimap
                = ArrayListMultimap.create();
            populateMultimapForKeySet(multimap, elements);
            return multimap.keySet();
          }
        })
        .named("ArrayListMultimap.keySet")
        .withFeatures(COLLECTION_FEATURES_REMOVE)
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
          @Override protected Set<String> create(String[] elements) {
            Multimap<String, Integer> multimap
                = LinkedListMultimap.create();
            populateMultimapForKeySet(multimap, elements);
            return multimap.keySet();
          }
        })
        .named("LinkedListMultimap.keySet")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(new TestStringSetGenerator() {
          @Override protected Set<String> create(String[] elements) {
            ImmutableListMultimap.Builder<String, Integer> builder
                = ImmutableListMultimap.builder();
            for (String element : elements) {
              builder.put(element, 2);
              builder.put(element, 3);
            }
            Multimap<String, Integer> multimap = builder.build();
            return multimap.keySet();
          }
        })
        .named("ImmutableListMultimap.keySet")
        .withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER)
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(
        new TestStringSetGenerator() {
          @Override protected Set<String> create(String[] elements) {
            PopulatableMapAsMultimap<String, Integer> multimap
                = PopulatableMapAsMultimap.create();
            populateMultimapForKeySet(multimap, elements);
            return multimap.build().keySet();
          }
        })
        .named("Multimaps.forMap.keySet")
        .withFeatures(FOR_MAP_FEATURES_ANY)
        .createTestSuite());

    suite.addTest(SetTestSuiteBuilder.using(
        new TestStringSetGenerator() {
        @Override protected Set<String> create(String[] elements) {
          SetMultimap<String, Integer> multimap = LinkedHashMultimap.create();
          populateMultimapForKeySet(multimap, elements);
          multimap.put("badkey", 3);
          multimap.put("a", 55556);
          return Multimaps.filterEntries(multimap, FILTER_KEYSET_PREDICATE).keySet();
          }
        })
        .named("Multimaps.filterEntries.keySet")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .suppressing(CollectionIteratorTester.getIteratorKnownOrderRemoveSupportedMethod())
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestStringCollectionGenerator() {
          @Override public Collection<String> create(String[] elements) {
            Multimap<Integer, String> multimap = HashMultimap.create();
            populateMultimapForValues(multimap, elements);
            return multimap.values();
          }
        })
        .named("HashMultimap.values")
        .withFeatures(COLLECTION_FEATURES_REMOVE)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestStringCollectionGenerator() {
          @Override public Collection<String> create(String[] elements) {
            Multimap<Integer, String> multimap
                = LinkedHashMultimap.create();
            populateMultimapForValues(multimap, elements);
            return multimap.values();
          }
        })
        .named("LinkedHashMultimap.values")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestStringCollectionGenerator() {
          @Override public Collection<String> create(String[] elements) {
            Multimap<Integer, String> multimap
                = TreeMultimap.create(Ordering.natural().nullsFirst(),
                    Ordering.natural().nullsLast());
            populateMultimapForValues(multimap, elements);
            return multimap.values();
          }
        })
        .named("TreeMultimap.values")
        .withFeatures(COLLECTION_FEATURES_REMOVE)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestStringCollectionGenerator() {
          @Override public Collection<String> create(String[] elements) {
            Multimap<Integer, String> multimap
                = ArrayListMultimap.create();
            populateMultimapForValues(multimap, elements);
            return multimap.values();
          }
        })
        .named("ArrayListMultimap.values")
        .withFeatures(COLLECTION_FEATURES_REMOVE)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(
        new TestStringListGenerator() {
          @Override public List<String> create(String[] elements) {
            LinkedListMultimap<Integer, String> multimap
                = LinkedListMultimap.create();
            populateMultimapForValues(multimap, elements);
            return multimap.values();
          }
        })
        .named("LinkedListMultimap.values")
        .withFeatures(LIST_FEATURES_REMOVE_SET)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestStringCollectionGenerator() {
          @Override public Collection<String> create(String[] elements) {
            ImmutableListMultimap.Builder<Integer, String> builder
                = ImmutableListMultimap.builder();
            for (int i = 0; i < elements.length; i++) {
              builder.put(i % 2, elements[i]);
            }
            return builder.build().values();
          }
        })
        .named("ImmutableListMultimap.values")
        .withFeatures(CollectionSize.ANY)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestStringCollectionGenerator() {
          @Override public Collection<String> create(String[] elements) {
            Multimap<Integer, String> multimap
                = LinkedHashMultimap.create();
            populateMultimapForValues(multimap, elements);
            multimap.put(3, "badvalue");
            multimap.put(55556, "foo");
            return Multimaps.filterEntries(multimap, FILTER_GET_PREDICATE).values();
          }
        })
        .named("Multimaps.filterEntries.values")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .suppressing(CollectionIteratorTester.getIteratorKnownOrderRemoveSupportedMethod())
        .createTestSuite());

    // TODO: use collection testers on Multimaps.forMap.values

    suite.addTest(MultisetTestSuiteBuilder.using(
        new TestStringMultisetGenerator() {
          @Override protected Multiset<String> create(String[] elements) {
            Multimap<String, Integer> multimap = HashMultimap.create();
            populateMultimapForKeys(multimap, elements);
            return multimap.keys();
          }
        })
        .named("HashMultimap.keys")
        .withFeatures(COLLECTION_FEATURES_REMOVE)
        .createTestSuite());

    suite.addTest(MultisetTestSuiteBuilder.using(
        new TestStringMultisetGenerator() {
          @Override protected Multiset<String> create(String[] elements) {
            Multimap<String, Integer> multimap
                = LinkedHashMultimap.create();
            populateMultimapForKeys(multimap, elements);
            return multimap.keys();
          }
        })
        .named("LinkedHashMultimap.keys")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .createTestSuite());

    suite.addTest(MultisetTestSuiteBuilder.using(
        new TestStringMultisetGenerator() {
          @Override protected Multiset<String> create(String[] elements) {
            Multimap<String, Integer> multimap
                = TreeMultimap.create(Ordering.natural().nullsFirst(),
                    Ordering.natural().nullsLast());
            populateMultimapForKeys(multimap, elements);
            return multimap.keys();
          }

          @Override public List<String> order(List<String> insertionOrder) {
            Collections.sort(insertionOrder, Ordering.natural().nullsFirst());
            return insertionOrder;
          }
        })
        .named("TreeMultimap.keys")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .createTestSuite());

    suite.addTest(MultisetTestSuiteBuilder.using(
        new TestStringMultisetGenerator() {
          @Override protected Multiset<String> create(String[] elements) {
            Multimap<String, Integer> multimap
                = ArrayListMultimap.create();
            populateMultimapForKeys(multimap, elements);
            return multimap.keys();
          }
        })
        .named("ArrayListMultimap.keys")
        .withFeatures(COLLECTION_FEATURES_REMOVE)
        .createTestSuite());

    suite.addTest(MultisetTestSuiteBuilder.using(
        new TestStringMultisetGenerator() {
          @Override protected Multiset<String> create(String[] elements) {
            Multimap<String, Integer> multimap
                = Multimaps.synchronizedListMultimap(
                    ArrayListMultimap.<String, Integer>create());
            populateMultimapForKeys(multimap, elements);
            return multimap.keys();
          }
        })
        .named("synchronized ArrayListMultimap.keys")
        .withFeatures(COLLECTION_FEATURES_REMOVE)
        .createTestSuite());

    suite.addTest(MultisetTestSuiteBuilder.using(
        new TestStringMultisetGenerator() {
          @Override protected Multiset<String> create(String[] elements) {
            Multimap<String, Integer> multimap
                = LinkedListMultimap.create();
            populateMultimapForKeys(multimap, elements);
            return multimap.keys();
          }
        })
        .named("LinkedListMultimap.keys")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .createTestSuite());

    suite.addTest(MultisetTestSuiteBuilder.using(
        new TestStringMultisetGenerator() {
          @Override protected Multiset<String> create(String[] elements) {
            ImmutableListMultimap.Builder<String, Integer> builder
                = ImmutableListMultimap.builder();
            for (int i = 0; i < elements.length; i++) {
              builder.put(elements[i], i);
            }
            Multimap<String, Integer> multimap = builder.build();
            return multimap.keys();
          }
        })
        .named("ImmutableListMultimap.keys")
        .withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER)
        .createTestSuite());

    suite.addTest(MultisetTestSuiteBuilder.using(
        new TestStringMultisetGenerator() {
          @Override protected Multiset<String> create(String[] elements) {
            PopulatableMapAsMultimap<String, Integer> multimap
                = PopulatableMapAsMultimap.create();
            populateMultimapForKeys(multimap, elements);
            return multimap.build().keys();
          }
        })
        .named("Multimaps.forMap.keys")
        .withFeatures(FOR_MAP_FEATURES_ANY)
        .suppressing(getReadsDuplicateInitializingMethods())
        .suppressing(getSetCountDuplicateInitializingMethods())
        .suppressing(getIteratorDuplicateInitializingMethods())
        .createTestSuite());

    suite.addTest(MultisetTestSuiteBuilder.using(
        new TestStringMultisetGenerator() {
        @Override protected Multiset<String> create(String[] elements) {
          SetMultimap<String, Integer> multimap = LinkedHashMultimap.create();
          populateMultimapForKeys(multimap, elements);
          multimap.put("badkey", 3);
          multimap.put("a", 55556);
          return Multimaps.filterEntries(multimap, FILTER_KEYSET_PREDICATE).keys();
          }
        })
        .named("Multimaps.filterEntries.keys")
        .withFeatures(COLLECTION_FEATURES_REMOVE_ORDER)
        .suppressing(CollectionIteratorTester.getIteratorKnownOrderRemoveSupportedMethod())
        .suppressing(MultisetWritesTester.getEntrySetIteratorMethod())
        .suppressing(getIteratorDuplicateInitializingMethods())
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestEntrySetGenerator() {
          @Override SetMultimap<String, Integer> createMultimap() {
            return HashMultimap.create();
          }
        })
        .named("HashMultimap.entries")
        .withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestEntrySetGenerator() {
          @Override SetMultimap<String, Integer> createMultimap() {
            return LinkedHashMultimap.create();
          }
        })
        .named("LinkedHashMultimap.entries")
        .withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS,
            CollectionFeature.KNOWN_ORDER)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestEntrySetGenerator() {
          @Override SetMultimap<String, Integer> createMultimap() {
            return TreeMultimap.create(Ordering.natural().nullsFirst(),
                Ordering.natural().nullsLast());
          }
        })
        .named("TreeMultimap.entries")
        .withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS,
            CollectionFeature.KNOWN_ORDER)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestEntriesGenerator() {
          @Override Multimap<String, Integer> createMultimap() {
            return ArrayListMultimap.create();
          }
        })
        .named("ArrayListMultimap.entries")
        .withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestEntriesGenerator() {
          @Override Multimap<String, Integer> createMultimap() {
            return Multimaps.synchronizedListMultimap(
                ArrayListMultimap.<String, Integer>create());
          }
        })
        .named("synchronized ArrayListMultimap.entries")
        .withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS)
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(
        new TestEntriesListGenerator() {
          @Override Multimap<String, Integer> createMultimap() {
            return LinkedListMultimap.create();
          }
        })
        .named("LinkedListMultimap.entries")
        .withFeatures(CollectionSize.ANY, ListFeature.REMOVE_OPERATIONS,
            CollectionFeature.KNOWN_ORDER)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestEntriesGenerator() {
          @Override Multimap<String, Integer> createMultimap() {
            return ImmutableListMultimap.of();
          }

          @Override public Collection<Entry<String, Integer>> create(
              Object... elements) {
            ImmutableListMultimap.Builder<String, Integer> builder
                = ImmutableListMultimap.builder();
            for (Object element : elements) {
              @SuppressWarnings("unchecked")
              Entry<String, Integer> entry = (Entry<String, Integer>) element;
              builder.put(entry.getKey(), entry.getValue());
            }
            return builder.build().entries();
          }
        })
        .named("ImmutableListMultimap.entries")
        .withFeatures(CollectionSize.ANY, CollectionFeature.KNOWN_ORDER)
        .createTestSuite());

    suite.addTest(CollectionTestSuiteBuilder.using(
        new TestEntriesGenerator() {
          @Override Multimap<String, Integer> createMultimap() {
            Multimap<String, Integer> multimap = LinkedHashMultimap.create();
            multimap.put("badkey", 3);
            multimap.put("a", 55556);
            return Multimaps.filterEntries(multimap, FILTER_KEYSET_PREDICATE);
          }
        })
        .named("Multimap.filterEntries.entries")
        .withFeatures(CollectionSize.ANY, CollectionFeature.REMOVE_OPERATIONS,
            CollectionFeature.KNOWN_ORDER)
        .suppressing(CollectionIteratorTester.getIteratorKnownOrderRemoveSupportedMethod())
        .createTestSuite());

    suite.addTest(ListTestSuiteBuilder.using(new TestStringListGenerator() {
      @Override protected List<String> create(String[] elements) {
        ListMultimap<Integer, String> multimap = ArrayListMultimap.create();
        populateMultimapForGet(multimap, elements);
        return Multimaps.transformValues(
            multimap, Functions.<String> identity()).get(3);
View Full Code Here

    assertEquals(newArrayList("b", "d"), list);
  }

  @GwtIncompatible("ListTestSuiteBuilder")
  private static Test testsForRemoveAllAndRetainAll() {
    return ListTestSuiteBuilder.using(new TestStringListGenerator() {
          @Override public List<String> create(final String[] elements) {
            final List<String> delegate = newArrayList(elements);
            return new ForwardingList<String>() {
              @Override protected List<String> delegate() {
                return delegate;
View Full Code Here

TOP

Related Classes of com.google.common.collect.testing.TestStringListGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.