@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()))); }
@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); }
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); }
@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(); }
@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()); }
@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); }
@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); }
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); }
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")); }
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()); }
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); }
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()); }
@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 }
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); }
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); }
@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); }
@GwtIncompatible // SeriazableTester public void testSerializationOrdering() { Multimap<String, Integer> multimap = initializeMultimap5(); Multimap<String, Integer> copy = SerializableTester.reserializeAndAssert(multimap); assertOrderingReadOnly(copy); }
@GwtIncompatible("SerializableTester") private static void checkSerialization(Predicate<? super Integer> predicate) { Predicate<? super Integer> reserialized = SerializableTester.reserializeAndAssert(predicate); assertEvalsLike(predicate, reserialized); }
@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")); }
@GwtIncompatible("SerializableTester") public void testSerialization_entrySet() { Multiset<String> c = ImmutableMultiset.of("a", "b", "c"); SerializableTester.reserializeAndAssert(c.entrySet()); }
@GwtIncompatible("SerializableTester") public void testSerialization_asList() { ImmutableMultiset<String> multiset = ImmutableMultiset.of("a", "a", "b", "b", "b"); SerializableTester.reserializeAndAssert(multiset.asList()); }
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()); }
@Override public void testSerialization() { SerializableTester.reserializeAndAssert(create()); }
@GwtIncompatible // SerializableTester public void testEmptySerialization() { ImmutableBiMap<String, Integer> bimap = ImmutableBiMap.of(); assertSame(bimap, SerializableTester.reserializeAndAssert(bimap)); }
public void testStringConverter_serialization() { SerializableTester.reserializeAndAssert(Enums.stringConverter(TestEnum.class)); }
@Test public void serialization() { SerializableTester.reserializeAndAssert(UTypeVarIdent.create("E")); }
@GwtIncompatible("SerializableTester") public void testValueOfFunction_serialization() { Function<String, TestEnum> function = Enums.valueOfFunction(TestEnum.class); SerializableTester.reserializeAndAssert(function); }