1/*
2 * Copyright (C) 2007 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.common.collect;
18
19import static com.google.common.base.Preconditions.checkArgument;
20
21import com.google.common.collect.testing.features.CollectionFeature;
22import com.google.common.collect.testing.features.CollectionSize;
23import com.google.common.collect.testing.features.MapFeature;
24import com.google.common.collect.testing.google.SetMultimapTestSuiteBuilder;
25import com.google.common.collect.testing.google.TestStringSetMultimapGenerator;
26
27import junit.framework.Test;
28import junit.framework.TestCase;
29
30import java.io.Serializable;
31import java.util.Map.Entry;
32
33/**
34 * Tests for {@link MapConstraints#constrainedSetMultimap} not accounted for in
35 * {@link MapConstraintsTest}.
36 *
37 * @author Jared Levy
38 */
39public class ConstrainedSetMultimapTest extends TestCase {
40  private enum Constraint implements Serializable, MapConstraint<String, String> {
41    INSTANCE;
42
43    @Override
44    public void checkKeyValue(String key, String value) {
45      checkArgument(!"test".equals(key));
46      checkArgument(!"test".equals(value));
47    }
48  }
49
50  public static Test suite() {
51    return SetMultimapTestSuiteBuilder.using(
52        new TestStringSetMultimapGenerator() {
53
54          @Override
55          protected SetMultimap<String, String> create(Entry<String, String>[] entries) {
56            SetMultimap<String, String> multimap = HashMultimap.create();
57            for (Entry<String, String> entry : entries) {
58              multimap.put(entry.getKey(), entry.getValue());
59            }
60            return MapConstraints.constrainedSetMultimap(multimap, Constraint.INSTANCE);
61          }
62        })
63        .named("MapConstraints.constrainedSetMultimap")
64        .withFeatures(
65            MapFeature.ALLOWS_NULL_KEYS,
66            MapFeature.ALLOWS_NULL_VALUES,
67            MapFeature.ALLOWS_ANY_NULL_QUERIES,
68            MapFeature.GENERAL_PURPOSE,
69            CollectionSize.ANY,
70            CollectionFeature.SERIALIZABLE,
71            CollectionFeature.SUPPORTS_ITERATOR_REMOVE)
72        .createTestSuite();
73  }
74}
75