@GwtIncompatible("SerializableTester")
 public void testViewSerialization() {
   Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3);
   SerializableTester.reserializeAndAssert(map.entrySet());
   SerializableTester.reserializeAndAssert(map.keySet());
   assertEquals(
       Lists.newArrayList(map.values()),
       Lists.newArrayList(SerializableTester.reserialize(map.values())));
 }
Esempio n. 2
0
  public void testJavaSerialization() {
    BloomFilter<byte[]> bf = BloomFilter.create(Funnels.byteArrayFunnel(), 100);
    for (int i = 0; i < 10; i++) {
      bf.put(Ints.toByteArray(i));
    }

    BloomFilter<byte[]> copy = SerializableTester.reserialize(bf);
    for (int i = 0; i < 10; i++) {
      assertTrue(copy.mightContain(Ints.toByteArray(i)));
    }
    assertEquals(bf.expectedFpp(), copy.expectedFpp());

    SerializableTester.reserializeAndAssert(bf);
  }
 @GwtIncompatible("SerializableTester")
 @SuppressWarnings("unchecked") // varargs
 public void testOr_serializationIterable() {
   Predicate<Integer> pre = Predicates.or(Arrays.asList(TRUE, FALSE));
   Predicate<Integer> post = SerializableTester.reserializeAndAssert(pre);
   assertEquals(pre.apply(0), post.apply(0));
 }
 @GwtIncompatible("SerializableTester")
 public void testIsNull_serialization() {
   Predicate<String> pre = Predicates.isNull();
   Predicate<String> post = SerializableTester.reserializeAndAssert(pre);
   assertEquals(pre.apply("foo"), post.apply("foo"));
   assertEquals(pre.apply(null), post.apply(null));
 }
 @GwtIncompatible("SerializableTester")
 public void testComposeSerialization() {
   Function<String, String> trim = TrimStringFunction.INSTANCE;
   Predicate<String> equalsFoo = Predicates.equalTo("Foo");
   Predicate<String> trimEqualsFoo = Predicates.compose(equalsFoo, trim);
   SerializableTester.reserializeAndAssert(trimEqualsFoo);
 }
Esempio n. 6
0
 @GwtIncompatible("SerializableTester")
 public void testNewSetFromMapSerialization() {
   Set<Integer> set = Sets.newSetFromMap(new LinkedHashMap<Integer, Boolean>());
   set.addAll(SOME_COLLECTION);
   Set<Integer> copy = SerializableTester.reserializeAndAssert(set);
   assertThat(copy).containsExactly(0, 1).inOrder();
 }
Esempio n. 7
0
 @GwtIncompatible // SerializableTester
 public void testSerializationContainingSelf() {
   Multiset<Multiset<?>> multiset = HashMultiset.create();
   multiset.add(multiset, 2);
   Multiset<Multiset<?>> copy = SerializableTester.reserialize(multiset);
   assertEquals(2, copy.size());
   assertSame(copy, copy.iterator().next());
 }
 @Override
 protected SortedMap<String, Integer> makePopulatedMap() {
   NavigableMap<String, Integer> map = new SafeTreeMap<String, Integer>();
   map.put("one", 1);
   map.put("two", 2);
   map.put("three", 3);
   return SerializableTester.reserialize(map);
 }
Esempio n. 9
0
  @GwtIncompatible("SerializableTester")
  public void testImmutableEnumSet_serialized() {
    Set<SomeEnum> units = Sets.immutableEnumSet(SomeEnum.D, SomeEnum.B);

    assertThat(units).containsExactly(SomeEnum.B, SomeEnum.D).inOrder();

    Set<SomeEnum> copy = SerializableTester.reserializeAndAssert(units);
    assertTrue(copy instanceof ImmutableEnumSet);
  }
Esempio n. 10
0
  @GwtIncompatible("Predicates.assignableFrom, SerializableTester")
  public void testIsAssignableFrom_serialization() {
    Predicate<Class<?>> predicate = Predicates.assignableFrom(Integer.class);
    Predicate<Class<?>> reserialized = SerializableTester.reserializeAndAssert(predicate);

    assertEvalsLike(predicate, reserialized, Integer.class);
    assertEvalsLike(predicate, reserialized, Float.class);
    assertEvalsLike(predicate, reserialized, null);
  }
Esempio n. 11
0
 @GwtIncompatible // SerializableTester
 public void testSerializationIndirectSelfReference() {
   Multiset<MultisetHolder> multiset = HashMultiset.create();
   MultisetHolder holder = new MultisetHolder(multiset);
   multiset.add(holder, 2);
   Multiset<MultisetHolder> copy = SerializableTester.reserialize(multiset);
   assertEquals(2, copy.size());
   assertSame(copy, copy.iterator().next().member);
 }
Esempio n. 12
0
 @GwtIncompatible // SerializableTester
 public void testInverseSerialization() {
   ImmutableBiMap<String, Integer> bimap =
       ImmutableBiMap.copyOf(ImmutableMap.of(1, "one", 2, "two")).inverse();
   ImmutableBiMap<String, Integer> copy = SerializableTester.reserializeAndAssert(bimap);
   assertEquals(Integer.valueOf(1), copy.get("one"));
   assertEquals("one", copy.inverse().get(1));
   assertSame(copy, copy.inverse().inverse());
 }
 public void testAsList() {
   ImmutableSortedMultiset<String> multiset = ImmutableSortedMultiset.of("a", "a", "b", "b", "b");
   ImmutableList<String> list = multiset.asList();
   assertEquals(ImmutableList.of("a", "a", "b", "b", "b"), list);
   assertTrue(list instanceof ImmutableAsList);
   ImmutableList<String> copy = SerializableTester.reserializeAndAssert(list);
   assertTrue(copy instanceof ImmutableAsList);
   assertEquals(2, list.indexOf("b"));
   assertEquals(4, list.lastIndexOf("b"));
 }
Esempio n. 14
0
 @GwtIncompatible // SeriazableTester
 public void testSerializationOrderingKeysAndEntries() {
   Multimap<String, Integer> multimap = LinkedHashMultimap.create();
   multimap.put("a", 1);
   multimap.put("b", 2);
   multimap.put("a", 3);
   multimap.put("c", 4);
   multimap.remove("a", 1);
   multimap = SerializableTester.reserializeAndAssert(multimap);
   assertThat(multimap.keySet()).containsExactly("a", "b", "c").inOrder();
   assertThat(multimap.entries())
       .containsExactly(mapEntry("b", 2), mapEntry("a", 3), mapEntry("c", 4))
       .inOrder();
   // note that the keys and entries are in different orders
 }
Esempio n. 15
0
  @SuppressWarnings("unchecked") // varargs
  @GwtIncompatible("SerializbleTester")
  public void testCascadingSerialization() throws Exception {
    // Eclipse says Predicate<Integer>; javac says Predicate<Object>.
    Predicate<? super Integer> nasty =
        Predicates.not(
            Predicates.and(
                Predicates.or(
                    Predicates.equalTo((Object) 1),
                    Predicates.equalTo(null),
                    Predicates.alwaysFalse(),
                    Predicates.alwaysTrue(),
                    Predicates.isNull(),
                    Predicates.notNull(),
                    Predicates.in(Arrays.asList(1)))));
    assertEvalsToFalse(nasty);

    Predicate<? super Integer> stillNasty = SerializableTester.reserializeAndAssert(nasty);

    assertEvalsToFalse(stillNasty);
  }
Esempio n. 16
0
 @GwtIncompatible // SerializableTester
 public void testEmptySerialization() {
   ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.of();
   assertSame(bimap, SerializableTester.reserializeAndAssert(bimap));
 }
 @Override
 public void testSerialization() {
   SerializableTester.reserializeAndAssert(create());
 }
Esempio n. 18
0
 @GwtIncompatible // SeriazableTester
 public void testSerializationOrdering() {
   Multimap<String, Integer> multimap = initializeMultimap5();
   Multimap<String, Integer> copy = SerializableTester.reserializeAndAssert(multimap);
   assertOrderingReadOnly(copy);
 }
 @Override
 public Multiset<E> create(Object... elements) {
   return (Multiset<E>) SerializableTester.reserialize(gen.create(elements));
 }
 public void testSerialization() {
   table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
   SerializableTester.reserializeAndAssert(table);
 }
 @GwtIncompatible("serialize")
 public void testSerializable() {
   SerializableTester.reserializeAndAssert(create());
 }
Esempio n. 22
0
 public void testSerialization() {
   AtomicLongMap<String> map = AtomicLongMap.create();
   map.put("key", 1L);
   AtomicLongMap<String> reserialized = SerializableTester.reserialize(map);
   assertEquals(map.asMap(), reserialized.asMap());
 }
 @Override
 public M create(Object... elements) {
   return SerializableTester.reserialize(
       ((TestMultimapGenerator<K, V, M>) multimapGenerator.getInnerGenerator())
           .create(elements));
 }
Esempio n. 24
0
 public void testStringConverter_serialization() {
   SerializableTester.reserializeAndAssert(Enums.stringConverter(TestEnum.class));
 }
Esempio n. 25
0
 @GwtIncompatible("SerializableTester")
 public void testLexicographicalComparatorSerializable() {
   Comparator<float[]> comparator = Floats.lexicographicalComparator();
   assertSame(comparator, SerializableTester.reserialize(comparator));
 }
 @Override
 protected SortedMap<String, Integer> makeEmptyMap() throws UnsupportedOperationException {
   NavigableMap<String, Integer> map = new SafeTreeMap<String, Integer>();
   return SerializableTester.reserialize(map);
 }
Esempio n. 27
0
 @GwtIncompatible("SerializableTester")
 public void testContainsPattern_serialization() {
   Predicate<CharSequence> pre = Predicates.containsPattern("foo");
   Predicate<CharSequence> post = SerializableTester.reserializeAndAssert(pre);
   assertEquals(pre.apply("foo"), post.apply("foo"));
 }
Esempio n. 28
0
 @GwtIncompatible("SerializableTester")
 public void testValueOfFunction_serialization() {
   Function<String, TestEnum> function = Enums.valueOfFunction(TestEnum.class);
   SerializableTester.reserializeAndAssert(function);
 }
 @Test
 public void serialization() {
   SerializableTester.reserializeAndAssert(UTypeVarIdent.create("E"));
 }
Esempio n. 30
0
 @GwtIncompatible("SerializableTester")
 private static void checkSerialization(Predicate<? super Integer> predicate) {
   Predicate<? super Integer> reserialized = SerializableTester.reserializeAndAssert(predicate);
   assertEvalsLike(predicate, reserialized);
 }