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

项目:guava-mock    文件:IteratorsTest.java   
@GwtIncompatible // unreasonably slow
public void testFilterUsingIteratorTester() {
  final List<Integer> list = asList(1, 2, 3, 4, 5);
  final Predicate<Integer> isEven = new Predicate<Integer>() {
    @Override
    public boolean apply(Integer integer) {
      return integer % 2 == 0;
    }
  };
  new IteratorTester<Integer>(5, UNMODIFIABLE, asList(2, 4),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<Integer> newTargetIterator() {
      return Iterators.filter(list.iterator(), isEven);
    }
  }.test();
}
项目:guava-mock    文件:MinMaxPriorityQueueTest.java   
private <T extends Comparable<T>> void runIterator(
    final List<T> values, int steps) throws Exception {
  IteratorTester<T> tester =
      new IteratorTester<T>(
          steps,
          IteratorFeature.MODIFIABLE,
          Lists.newLinkedList(values),
          IteratorTester.KnownOrder.UNKNOWN_ORDER) {
        private MinMaxPriorityQueue<T> mmHeap;
        @Override protected Iterator<T> newTargetIterator() {
          mmHeap = MinMaxPriorityQueue.create(values);
          return mmHeap.iterator();
        }
        @Override protected void verify(List<T> elements) {
          assertEquals(Sets.newHashSet(elements),
              Sets.newHashSet(mmHeap.iterator()));
          assertTrue("Invalid MinMaxHeap: " + mmHeap, mmHeap.isIntact());
        }
      };
  tester.test();
}
项目:guava-mock    文件:ListsTest.java   
public void testAsList1Small() {
  List<String> list = Lists.asList("foo", new String[0]);
  assertThat(list).contains("foo");
  assertEquals(1, list.size());
  assertIndexIsOutOfBounds(list, -1);
  assertEquals("foo", list.get(0));
  assertIndexIsOutOfBounds(list, 1);
  assertTrue(list instanceof RandomAccess);

  new IteratorTester<String>(3, UNMODIFIABLE, singletonList("foo"),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<String> newTargetIterator() {
      return Lists.asList("foo", new String[0]).iterator();
    }
  }.test();
}
项目:guava-mock    文件:ListsTest.java   
@GwtIncompatible // SerializableTester
public void testAsList2Small() {
  List<String> list = Lists.asList("foo", "bar", new String[0]);
  assertThat(list).containsExactly("foo", "bar").inOrder();
  assertEquals(2, list.size());
  assertIndexIsOutOfBounds(list, -1);
  assertEquals("foo", list.get(0));
  assertEquals("bar", list.get(1));
  assertIndexIsOutOfBounds(list, 2);
  SerializableTester.reserializeAndAssert(list);
  assertTrue(list instanceof RandomAccess);

  new IteratorTester<String>(5, UNMODIFIABLE, asList("foo", "bar"),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<String> newTargetIterator() {
      return Lists.asList("foo", "bar", new String[0]).iterator();
    }
  }.test();
}
项目:guava-mock    文件:LinkedHashMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testGetIteration() {
  new IteratorTester<Integer>(6, MODIFIABLE,
      newLinkedHashSet(asList(2, 3, 4, 7, 8)),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<Integer> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3, 4));
      multimap.putAll("bar", asList(5, 6));
      multimap.putAll("foo", asList(7, 8));
      return multimap.get("foo").iterator();
    }

    @Override protected void verify(List<Integer> elements) {
      assertEquals(newHashSet(elements), multimap.get("foo"));
    }
  }.test();
}
项目:guava-mock    文件:LinkedHashMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testKeysIteration() {
  new IteratorTester<String>(6, MODIFIABLE, newArrayList("foo", "foo", "bar",
      "bar", "foo"), IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      return multimap.keys().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(elements, Lists.newArrayList(multimap.keys()));
    }
  }.test();
}
项目:guava-mock    文件:LinkedHashMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testValuesIteration() {
  new IteratorTester<Integer>(6, MODIFIABLE, newArrayList(2, 3, 4, 5, 6),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<Integer> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      return multimap.values().iterator();
    }

    @Override protected void verify(List<Integer> elements) {
      assertEquals(elements, Lists.newArrayList(multimap.values()));
    }
  }.test();
}
项目:guava-mock    文件:LinkedHashMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testKeySetIteration() {
  new IteratorTester<String>(6, MODIFIABLE,
      newLinkedHashSet(asList("foo", "bar", "baz", "dog", "cat")),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      multimap.putAll("baz", asList(7, 8));
      multimap.putAll("dog", asList(9));
      multimap.putAll("bar", asList(10, 11));
      multimap.putAll("cat", asList(12, 13, 14));
      return multimap.keySet().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(newHashSet(elements), multimap.keySet());
    }
  }.test();
}
项目:guava-mock    文件:LinkedListMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testKeysIteration() {
  new IteratorTester<String>(6, MODIFIABLE, newArrayList("foo", "foo", "bar",
      "bar", "foo"), IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      return multimap.keys().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(elements, Lists.newArrayList(multimap.keys()));
    }
  }.test();
}
项目:guava-mock    文件:LinkedListMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testKeySetIteration() {
  new IteratorTester<String>(6, MODIFIABLE, newLinkedHashSet(asList(
      "foo", "bar", "baz", "dog", "cat")),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      multimap.putAll("baz", asList(7, 8));
      multimap.putAll("dog", asList(9));
      multimap.putAll("bar", asList(10, 11));
      multimap.putAll("cat", asList(12, 13, 14));
      return multimap.keySet().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(newHashSet(elements), multimap.keySet());
    }
  }.test();
}
项目:guava-mock    文件:MultimapsTest.java   
public void testForMapGetIteration() {
  IteratorTester<Integer> tester =
      new IteratorTester<Integer>(4, MODIFIABLE, newHashSet(1),
          IteratorTester.KnownOrder.KNOWN_ORDER) {
        private Multimap<String, Integer> multimap;

        @Override protected Iterator<Integer> newTargetIterator() {
          Map<String, Integer> map = Maps.newHashMap();
          map.put("foo", 1);
          map.put("bar", 2);
          multimap = Multimaps.forMap(map);
          return multimap.get("foo").iterator();
        }

        @Override protected void verify(List<Integer> elements) {
          assertEquals(newHashSet(elements), multimap.get("foo"));
        }
      };

  tester.test();
}
项目:guava-mock    文件:SetsTest.java   
@GwtIncompatible // too slow for GWT
public void testPowerSetIteration_iteratorTester() {
  ImmutableSet<Integer> elements = ImmutableSet.of(1, 2);

  Set<Set<Integer>> expected = newLinkedHashSet();
  expected.add(ImmutableSet.<Integer>of());
  expected.add(ImmutableSet.of(1));
  expected.add(ImmutableSet.of(2));
  expected.add(ImmutableSet.of(1, 2));

  final Set<Set<Integer>> powerSet = powerSet(elements);
  new IteratorTester<Set<Integer>>(6, UNMODIFIABLE, expected, KNOWN_ORDER) {
    @Override protected Iterator<Set<Integer>> newTargetIterator() {
      return powerSet.iterator();
    }
  }.test();
}
项目:guava-mock    文件:SetsTest.java   
public void testPowerSetIteration_iteratorTester_fast() {
  ImmutableSet<Integer> elements = ImmutableSet.of(1, 2);

  Set<Set<Integer>> expected = newLinkedHashSet();
  expected.add(ImmutableSet.<Integer>of());
  expected.add(ImmutableSet.of(1));
  expected.add(ImmutableSet.of(2));
  expected.add(ImmutableSet.of(1, 2));

  final Set<Set<Integer>> powerSet = powerSet(elements);
  new IteratorTester<Set<Integer>>(4, UNMODIFIABLE, expected, KNOWN_ORDER) {
    @Override protected Iterator<Set<Integer>> newTargetIterator() {
      return powerSet.iterator();
    }
  }.test();
}
项目:googles-monorepo-demo    文件:IteratorsTest.java   
@GwtIncompatible // unreasonably slow
public void testFilterUsingIteratorTester() {
  final List<Integer> list = asList(1, 2, 3, 4, 5);
  final Predicate<Integer> isEven = new Predicate<Integer>() {
    @Override
    public boolean apply(Integer integer) {
      return integer % 2 == 0;
    }
  };
  new IteratorTester<Integer>(5, UNMODIFIABLE, asList(2, 4),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<Integer> newTargetIterator() {
      return Iterators.filter(list.iterator(), isEven);
    }
  }.test();
}
项目:googles-monorepo-demo    文件:MinMaxPriorityQueueTest.java   
private <T extends Comparable<T>> void runIterator(
    final List<T> values, int steps) throws Exception {
  IteratorTester<T> tester =
      new IteratorTester<T>(
          steps,
          IteratorFeature.MODIFIABLE,
          Lists.newLinkedList(values),
          IteratorTester.KnownOrder.UNKNOWN_ORDER) {
        private MinMaxPriorityQueue<T> mmHeap;
        @Override protected Iterator<T> newTargetIterator() {
          mmHeap = MinMaxPriorityQueue.create(values);
          return mmHeap.iterator();
        }
        @Override protected void verify(List<T> elements) {
          assertEquals(Sets.newHashSet(elements),
              Sets.newHashSet(mmHeap.iterator()));
          assertTrue("Invalid MinMaxHeap: " + mmHeap, mmHeap.isIntact());
        }
      };
  tester.test();
}
项目:googles-monorepo-demo    文件:ListsTest.java   
public void testAsList1Small() {
  List<String> list = Lists.asList("foo", new String[0]);
  assertThat(list).contains("foo");
  assertEquals(1, list.size());
  assertIndexIsOutOfBounds(list, -1);
  assertEquals("foo", list.get(0));
  assertIndexIsOutOfBounds(list, 1);
  assertTrue(list instanceof RandomAccess);

  new IteratorTester<String>(3, UNMODIFIABLE, singletonList("foo"),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<String> newTargetIterator() {
      return Lists.asList("foo", new String[0]).iterator();
    }
  }.test();
}
项目:googles-monorepo-demo    文件:ListsTest.java   
@GwtIncompatible // SerializableTester
public void testAsList2Small() {
  List<String> list = Lists.asList("foo", "bar", new String[0]);
  assertThat(list).containsExactly("foo", "bar").inOrder();
  assertEquals(2, list.size());
  assertIndexIsOutOfBounds(list, -1);
  assertEquals("foo", list.get(0));
  assertEquals("bar", list.get(1));
  assertIndexIsOutOfBounds(list, 2);
  SerializableTester.reserializeAndAssert(list);
  assertTrue(list instanceof RandomAccess);

  new IteratorTester<String>(5, UNMODIFIABLE, asList("foo", "bar"),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<String> newTargetIterator() {
      return Lists.asList("foo", "bar", new String[0]).iterator();
    }
  }.test();
}
项目:googles-monorepo-demo    文件:LinkedHashMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testGetIteration() {
  new IteratorTester<Integer>(6, MODIFIABLE,
      newLinkedHashSet(asList(2, 3, 4, 7, 8)),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<Integer> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3, 4));
      multimap.putAll("bar", asList(5, 6));
      multimap.putAll("foo", asList(7, 8));
      return multimap.get("foo").iterator();
    }

    @Override protected void verify(List<Integer> elements) {
      assertEquals(newHashSet(elements), multimap.get("foo"));
    }
  }.test();
}
项目:googles-monorepo-demo    文件:LinkedHashMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testKeysIteration() {
  new IteratorTester<String>(6, MODIFIABLE, newArrayList("foo", "foo", "bar",
      "bar", "foo"), IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      return multimap.keys().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(elements, Lists.newArrayList(multimap.keys()));
    }
  }.test();
}
项目:googles-monorepo-demo    文件:LinkedHashMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testValuesIteration() {
  new IteratorTester<Integer>(6, MODIFIABLE, newArrayList(2, 3, 4, 5, 6),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<Integer> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      return multimap.values().iterator();
    }

    @Override protected void verify(List<Integer> elements) {
      assertEquals(elements, Lists.newArrayList(multimap.values()));
    }
  }.test();
}
项目:googles-monorepo-demo    文件:LinkedHashMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testKeySetIteration() {
  new IteratorTester<String>(6, MODIFIABLE,
      newLinkedHashSet(asList("foo", "bar", "baz", "dog", "cat")),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      multimap.putAll("baz", asList(7, 8));
      multimap.putAll("dog", asList(9));
      multimap.putAll("bar", asList(10, 11));
      multimap.putAll("cat", asList(12, 13, 14));
      return multimap.keySet().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(newHashSet(elements), multimap.keySet());
    }
  }.test();
}
项目:googles-monorepo-demo    文件:LinkedListMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testKeysIteration() {
  new IteratorTester<String>(6, MODIFIABLE, newArrayList("foo", "foo", "bar",
      "bar", "foo"), IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      return multimap.keys().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(elements, Lists.newArrayList(multimap.keys()));
    }
  }.test();
}
项目:googles-monorepo-demo    文件:LinkedListMultimapTest.java   
@GwtIncompatible // unreasonably slow
public void testKeySetIteration() {
  new IteratorTester<String>(6, MODIFIABLE, newLinkedHashSet(asList(
      "foo", "bar", "baz", "dog", "cat")),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      multimap.putAll("baz", asList(7, 8));
      multimap.putAll("dog", asList(9));
      multimap.putAll("bar", asList(10, 11));
      multimap.putAll("cat", asList(12, 13, 14));
      return multimap.keySet().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(newHashSet(elements), multimap.keySet());
    }
  }.test();
}
项目:googles-monorepo-demo    文件:MultimapsTest.java   
public void testForMapGetIteration() {
  IteratorTester<Integer> tester =
      new IteratorTester<Integer>(4, MODIFIABLE, newHashSet(1),
          IteratorTester.KnownOrder.KNOWN_ORDER) {
        private Multimap<String, Integer> multimap;

        @Override protected Iterator<Integer> newTargetIterator() {
          Map<String, Integer> map = Maps.newHashMap();
          map.put("foo", 1);
          map.put("bar", 2);
          multimap = Multimaps.forMap(map);
          return multimap.get("foo").iterator();
        }

        @Override protected void verify(List<Integer> elements) {
          assertEquals(newHashSet(elements), multimap.get("foo"));
        }
      };

  tester.test();
}
项目:googles-monorepo-demo    文件:SetsTest.java   
@GwtIncompatible // too slow for GWT
public void testPowerSetIteration_iteratorTester() {
  ImmutableSet<Integer> elements = ImmutableSet.of(1, 2);

  Set<Set<Integer>> expected = newLinkedHashSet();
  expected.add(ImmutableSet.<Integer>of());
  expected.add(ImmutableSet.of(1));
  expected.add(ImmutableSet.of(2));
  expected.add(ImmutableSet.of(1, 2));

  final Set<Set<Integer>> powerSet = powerSet(elements);
  new IteratorTester<Set<Integer>>(6, UNMODIFIABLE, expected, KNOWN_ORDER) {
    @Override protected Iterator<Set<Integer>> newTargetIterator() {
      return powerSet.iterator();
    }
  }.test();
}
项目:googles-monorepo-demo    文件:SetsTest.java   
public void testPowerSetIteration_iteratorTester_fast() {
  ImmutableSet<Integer> elements = ImmutableSet.of(1, 2);

  Set<Set<Integer>> expected = newLinkedHashSet();
  expected.add(ImmutableSet.<Integer>of());
  expected.add(ImmutableSet.of(1));
  expected.add(ImmutableSet.of(2));
  expected.add(ImmutableSet.of(1, 2));

  final Set<Set<Integer>> powerSet = powerSet(elements);
  new IteratorTester<Set<Integer>>(4, UNMODIFIABLE, expected, KNOWN_ORDER) {
    @Override protected Iterator<Set<Integer>> newTargetIterator() {
      return powerSet.iterator();
    }
  }.test();
}
项目:miniguava    文件:ListsTest.java   
public void testAsList1Small() {
  List<String> list = Lists.asList("foo", new String[0]);
  assertThat(list).contains("foo");
  assertEquals(1, list.size());
  assertIndexIsOutOfBounds(list, -1);
  assertEquals("foo", list.get(0));
  assertIndexIsOutOfBounds(list, 1);
  assertTrue(list instanceof RandomAccess);

  new IteratorTester<String>(3, UNMODIFIABLE, singletonList("foo"),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<String> newTargetIterator() {
      return Lists.asList("foo", new String[0]).iterator();
    }
  }.test();
}
项目:miniguava    文件:SetsTest.java   
public void testPowerSetIteration_iteratorTester() {
  ImmutableSet<Integer> elements = ImmutableSet.of(1, 2);

  Set<Set<Integer>> expected = new LinkedHashSet<Set<Integer>>();
  expected.add(ImmutableSet.<Integer>of());
  expected.add(ImmutableSet.of(1));
  expected.add(ImmutableSet.of(2));
  expected.add(ImmutableSet.of(1, 2));

  final Set<Set<Integer>> powerSet = powerSet(elements);
  new IteratorTester<Set<Integer>>(6, UNMODIFIABLE, expected, KNOWN_ORDER) {
    @Override protected Iterator<Set<Integer>> newTargetIterator() {
      return powerSet.iterator();
    }
  }.test();
}
项目:miniguava    文件:SetsTest.java   
public void testPowerSetIteration_iteratorTester_fast() {
  ImmutableSet<Integer> elements = ImmutableSet.of(1, 2);

  Set<Set<Integer>> expected = new LinkedHashSet<Set<Integer>>();
  expected.add(ImmutableSet.<Integer>of());
  expected.add(ImmutableSet.of(1));
  expected.add(ImmutableSet.of(2));
  expected.add(ImmutableSet.of(1, 2));

  final Set<Set<Integer>> powerSet = powerSet(elements);
  new IteratorTester<Set<Integer>>(4, UNMODIFIABLE, expected, KNOWN_ORDER) {
    @Override protected Iterator<Set<Integer>> newTargetIterator() {
      return powerSet.iterator();
    }
  }.test();
}
项目:guava-libraries    文件:ListsTest.java   
public void testAsList1Small() {
  List<String> list = Lists.asList("foo", new String[0]);
  assertThat(list).contains("foo");
  assertEquals(1, list.size());
  assertIndexIsOutOfBounds(list, -1);
  assertEquals("foo", list.get(0));
  assertIndexIsOutOfBounds(list, 1);
  assertTrue(list instanceof RandomAccess);

  new IteratorTester<String>(3, UNMODIFIABLE, singletonList("foo"),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<String> newTargetIterator() {
      return Lists.asList("foo", new String[0]).iterator();
    }
  }.test();
}
项目:guava-libraries    文件:MultimapsTest.java   
public void testForMapGetIteration() {
  IteratorTester<Integer> tester =
      new IteratorTester<Integer>(4, MODIFIABLE, newHashSet(1),
          IteratorTester.KnownOrder.KNOWN_ORDER) {
        private Multimap<String, Integer> multimap;

        @Override protected Iterator<Integer> newTargetIterator() {
          Map<String, Integer> map = Maps.newHashMap();
          map.put("foo", 1);
          map.put("bar", 2);
          multimap = Multimaps.forMap(map);
          return multimap.get("foo").iterator();
        }

        @Override protected void verify(List<Integer> elements) {
          assertEquals(newHashSet(elements), multimap.get("foo"));
        }
      };

  tester.test();
}
项目:guava-libraries    文件:SetsTest.java   
public void testPowerSetIteration_iteratorTester_fast() {
  ImmutableSet<Integer> elements = ImmutableSet.of(1, 2);

  Set<Set<Integer>> expected = newLinkedHashSet();
  expected.add(ImmutableSet.<Integer>of());
  expected.add(ImmutableSet.of(1));
  expected.add(ImmutableSet.of(2));
  expected.add(ImmutableSet.of(1, 2));

  final Set<Set<Integer>> powerSet = powerSet(elements);
  new IteratorTester<Set<Integer>>(4, UNMODIFIABLE, expected, KNOWN_ORDER) {
    @Override protected Iterator<Set<Integer>> newTargetIterator() {
      return powerSet.iterator();
    }
  }.test();
}
项目:guava-libraries    文件:IteratorsTest.java   
@GwtIncompatible("unreasonably slow")
public void testFilterUsingIteratorTester() {
  final List<Integer> list = asList(1, 2, 3, 4, 5);
  final Predicate<Integer> isEven = new Predicate<Integer>() {
    @Override
    public boolean apply(Integer integer) {
      return integer % 2 == 0;
    }
  };
  new IteratorTester<Integer>(5, UNMODIFIABLE, asList(2, 4),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<Integer> newTargetIterator() {
      return Iterators.filter(list.iterator(), isEven);
    }
  }.test();
}
项目:guava-libraries    文件:MinMaxPriorityQueueTest.java   
private <T extends Comparable<T>> void runIterator(
    final List<T> values, int steps) throws Exception {
  IteratorTester<T> tester =
      new IteratorTester<T>(
          steps,
          IteratorFeature.MODIFIABLE,
          Lists.newLinkedList(values),
          IteratorTester.KnownOrder.UNKNOWN_ORDER) {
        private MinMaxPriorityQueue<T> mmHeap;
        @Override protected Iterator<T> newTargetIterator() {
          mmHeap = MinMaxPriorityQueue.create(values);
          return mmHeap.iterator();
        }
        @Override protected void verify(List<T> elements) {
          assertEquals(Sets.newHashSet(elements),
              Sets.newHashSet(mmHeap.iterator()));
          assertTrue("Invalid MinMaxHeap: " + mmHeap, mmHeap.isIntact());
        }
      };
  tester.test();
}
项目:guava-libraries    文件:ListsTest.java   
public void testAsList1Small() {
  List<String> list = Lists.asList("foo", new String[0]);
  assertThat(list).contains("foo");
  assertEquals(1, list.size());
  assertIndexIsOutOfBounds(list, -1);
  assertEquals("foo", list.get(0));
  assertIndexIsOutOfBounds(list, 1);
  assertTrue(list instanceof RandomAccess);

  new IteratorTester<String>(3, UNMODIFIABLE, singletonList("foo"),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<String> newTargetIterator() {
      return Lists.asList("foo", new String[0]).iterator();
    }
  }.test();
}
项目:guava-libraries    文件:ListsTest.java   
@GwtIncompatible("SerializableTester")
public void testAsList2Small() {
  List<String> list = Lists.asList("foo", "bar", new String[0]);
  assertThat(list).containsExactly("foo", "bar").inOrder();
  assertEquals(2, list.size());
  assertIndexIsOutOfBounds(list, -1);
  assertEquals("foo", list.get(0));
  assertEquals("bar", list.get(1));
  assertIndexIsOutOfBounds(list, 2);
  SerializableTester.reserializeAndAssert(list);
  assertTrue(list instanceof RandomAccess);

  new IteratorTester<String>(5, UNMODIFIABLE, asList("foo", "bar"),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    @Override protected Iterator<String> newTargetIterator() {
      return Lists.asList("foo", "bar", new String[0]).iterator();
    }
  }.test();
}
项目:guava-libraries    文件:LinkedHashMultimapTest.java   
@GwtIncompatible("unreasonably slow")
public void testGetIteration() {
  new IteratorTester<Integer>(6, MODIFIABLE,
      newLinkedHashSet(asList(2, 3, 4, 7, 8)),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<Integer> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3, 4));
      multimap.putAll("bar", asList(5, 6));
      multimap.putAll("foo", asList(7, 8));
      return multimap.get("foo").iterator();
    }

    @Override protected void verify(List<Integer> elements) {
      assertEquals(newHashSet(elements), multimap.get("foo"));
    }
  }.test();
}
项目:guava-libraries    文件:LinkedHashMultimapTest.java   
@GwtIncompatible("unreasonably slow")
public void testKeysIteration() {
  new IteratorTester<String>(6, MODIFIABLE, newArrayList("foo", "foo", "bar",
      "bar", "foo"), IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      return multimap.keys().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(elements, Lists.newArrayList(multimap.keys()));
    }
  }.test();
}
项目:guava-libraries    文件:LinkedHashMultimapTest.java   
@GwtIncompatible("unreasonably slow")
public void testValuesIteration() {
  new IteratorTester<Integer>(6, MODIFIABLE, newArrayList(2, 3, 4, 5, 6),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<Integer> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      return multimap.values().iterator();
    }

    @Override protected void verify(List<Integer> elements) {
      assertEquals(elements, Lists.newArrayList(multimap.values()));
    }
  }.test();
}
项目:guava-libraries    文件:LinkedHashMultimapTest.java   
@GwtIncompatible("unreasonably slow")
public void testKeySetIteration() {
  new IteratorTester<String>(6, MODIFIABLE,
      newLinkedHashSet(asList("foo", "bar", "baz", "dog", "cat")),
      IteratorTester.KnownOrder.KNOWN_ORDER) {
    private Multimap<String, Integer> multimap;

    @Override protected Iterator<String> newTargetIterator() {
      multimap = LinkedHashMultimap.create();
      multimap.putAll("foo", asList(2, 3));
      multimap.putAll("bar", asList(4, 5));
      multimap.putAll("foo", asList(6));
      multimap.putAll("baz", asList(7, 8));
      multimap.putAll("dog", asList(9));
      multimap.putAll("bar", asList(10, 11));
      multimap.putAll("cat", asList(12, 13, 14));
      return multimap.keySet().iterator();
    }

    @Override protected void verify(List<String> elements) {
      assertEquals(newHashSet(elements), multimap.keySet());
    }
  }.test();
}