コード例 #1
0
 @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())));
 }
コード例 #2
0
 @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));
 }
コード例 #3
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));
 }
コード例 #4
0
 @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);
 }
コード例 #5
0
 public void testExplicit_sortingExample() {
   Comparator<Integer> c = Ordering.explicit(2, 8, 6, 1, 7, 5, 3, 4, 0, 9);
   List<Integer> list = Arrays.asList(0, 3, 5, 6, 7, 8, 9);
   Collections.sort(list, c);
   assertThat(list).containsExactly(8, 6, 7, 5, 3, 0, 9).inOrder();
   reserializeAndAssert(c);
 }
コード例 #6
0
ファイル: SetsTest.java プロジェクト: cjosw/guava
 @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();
 }
コード例 #7
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 @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());
 }
コード例 #8
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);
  }
コード例 #9
0
ファイル: SetsTest.java プロジェクト: cjosw/guava
  @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);
  }
コード例 #10
0
 public void testExplicit_none() {
   Comparator<Integer> c = Ordering.explicit(Collections.<Integer>emptyList());
   try {
     c.compare(0, 0);
     fail();
   } catch (IncomparableValueException expected) {
     assertEquals(0, expected.value);
   }
   reserializeAndAssert(c);
 }
コード例 #11
0
 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"));
 }
コード例 #12
0
 public void testExplicit_one() {
   Comparator<Integer> c = Ordering.explicit(0);
   assertEquals(0, c.compare(0, 0));
   try {
     c.compare(0, 1);
     fail();
   } catch (IncomparableValueException expected) {
     assertEquals(1, expected.value);
   }
   reserializeAndAssert(c);
   assertEquals("Ordering.explicit([0])", c.toString());
 }
コード例 #13
0
ファイル: BloomFilterTest.java プロジェクト: Ricordo/guava
  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);
  }
コード例 #14
0
  public void testOnResultOf_natural() {
    Comparator<String> comparator =
        Ordering.natural().onResultOf(StringLengthFunction.StringLength);
    assertTrue(comparator.compare("to", "be") == 0);
    assertTrue(comparator.compare("or", "not") < 0);
    assertTrue(comparator.compare("that", "to") > 0);

    new EqualsTester()
        .addEqualityGroup(
            comparator, Ordering.natural().onResultOf(StringLengthFunction.StringLength))
        .addEqualityGroup(DECREASING_INTEGER)
        .testEquals();
    reserializeAndAssert(comparator);
    assertEquals("Ordering.natural().onResultOf(StringLength)", comparator.toString());
  }
コード例 #15
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
 }
コード例 #16
0
 public void testExplicit_two() {
   Comparator<Integer> c = Ordering.explicit(42, 5);
   assertEquals(0, c.compare(5, 5));
   assertTrue(c.compare(5, 42) > 0);
   assertTrue(c.compare(42, 5) < 0);
   try {
     c.compare(5, 666);
     fail();
   } catch (IncomparableValueException expected) {
     assertEquals(666, expected.value);
   }
   new EqualsTester()
       .addEqualityGroup(c, Ordering.explicit(42, 5))
       .addEqualityGroup(Ordering.explicit(5, 42))
       .addEqualityGroup(Ordering.explicit(42))
       .testEquals();
   reserializeAndAssert(c);
 }
コード例 #17
0
 public void testCompound_static() {
   Comparator<String> comparator =
       Ordering.compound(
           ImmutableList.of(
               byCharAt(0), byCharAt(1), byCharAt(2), byCharAt(3), byCharAt(4), byCharAt(5)));
   Helpers.testComparator(
       comparator,
       ImmutableList.of(
           "applesauce",
           "apricot",
           "artichoke",
           "banality",
           "banana",
           "banquet",
           "tangelo",
           "tangerine"));
   reserializeAndAssert(comparator);
 }
コード例 #18
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);
  }
コード例 #19
0
 @GwtIncompatible // SeriazableTester
 public void testSerializationOrdering() {
   Multimap<String, Integer> multimap = initializeMultimap5();
   Multimap<String, Integer> copy = SerializableTester.reserializeAndAssert(multimap);
   assertOrderingReadOnly(copy);
 }
コード例 #20
0
 @GwtIncompatible("SerializableTester")
 private static void checkSerialization(Predicate<? super Integer> predicate) {
   Predicate<? super Integer> reserialized = SerializableTester.reserializeAndAssert(predicate);
   assertEvalsLike(predicate, reserialized);
 }
コード例 #21
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"));
 }
コード例 #22
0
 @GwtIncompatible("SerializableTester")
 public void testSerialization_entrySet() {
   Multiset<String> c = ImmutableMultiset.of("a", "b", "c");
   SerializableTester.reserializeAndAssert(c.entrySet());
 }
コード例 #23
0
 @GwtIncompatible("SerializableTester")
 public void testSerialization_asList() {
   ImmutableMultiset<String> multiset = ImmutableMultiset.of("a", "a", "b", "b", "b");
   SerializableTester.reserializeAndAssert(multiset.asList());
 }
コード例 #24
0
 public void testSerialization() {
   table = create("foo", 1, 'a', "bar", 1, 'b', "foo", 3, 'c');
   SerializableTester.reserializeAndAssert(table);
 }
コード例 #25
0
 @GwtIncompatible("serialize")
 public void testSerializable() {
   SerializableTester.reserializeAndAssert(create());
 }
コード例 #26
0
 @Override
 public void testSerialization() {
   SerializableTester.reserializeAndAssert(create());
 }
コード例 #27
0
ファイル: ImmutableBiMapTest.java プロジェクト: cushon/guava
 @GwtIncompatible // SerializableTester
 public void testEmptySerialization() {
   ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.of();
   assertSame(bimap, SerializableTester.reserializeAndAssert(bimap));
 }
コード例 #28
0
 public void testStringConverter_serialization() {
   SerializableTester.reserializeAndAssert(Enums.stringConverter(TestEnum.class));
 }
コード例 #29
0
 @Test
 public void serialization() {
   SerializableTester.reserializeAndAssert(UTypeVarIdent.create("E"));
 }
コード例 #30
0
 @GwtIncompatible("SerializableTester")
 public void testValueOfFunction_serialization() {
   Function<String, TestEnum> function = Enums.valueOfFunction(TestEnum.class);
   SerializableTester.reserializeAndAssert(function);
 }