public void testSerialization() { SerializableTester.reserializeAndAssert(HostAndPort.fromParts("host", 80)); SerializableTester.reserializeAndAssert(HostAndPort.fromString("host")); SerializableTester.reserializeAndAssert(HostAndPort.fromString("host:80")); SerializableTester.reserializeAndAssert(HostAndPort.fromString("[::1]:104")); SerializableTester.reserializeAndAssert(HostAndPort.fromParts("1::2", 103)); } }
@GwtIncompatible // SerializableTester public void testForMapSerialization() { Map<String, Integer> map = Maps.newHashMap(); map.put("foo", 1); map.put("bar", 2); Multimap<String, Integer> multimapView = Multimaps.forMap(map); SerializableTester.reserializeAndAssert(multimapView); }
@GwtIncompatible // SerializableTester public void testSeveral_serialization() { SortedSet<String> set = new SafeTreeSet<>(); set.add("a"); set.add("b"); set.add("c"); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertEquals(set.comparator(), copy.comparator()); } }
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 testSerialization() { Multimap<String, Integer> multimap = createMultimap(); SerializableTester.reserializeAndAssert(multimap); assertEquals(multimap.size(), SerializableTester.reserialize(multimap).size()); SerializableTester.reserializeAndAssert(multimap.get("foo")); LenientSerializableTester.reserializeAndAssertLenient(multimap.keySet()); LenientSerializableTester.reserializeAndAssertLenient(multimap.keys()); SerializableTester.reserializeAndAssert(multimap.asMap()); Collection<Integer> valuesCopy = SerializableTester.reserialize(multimap.values()); assertEquals(HashMultiset.create(multimap.values()), HashMultiset.create(valuesCopy)); }
@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 testEmpty_serialization() { SortedSet<String> set = new SafeTreeSet<>(); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertEquals(set.comparator(), copy.comparator()); }
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); }
@GwtIncompatible // SerializableTester public void testSingle_serialization() { SortedSet<String> set = of("e"); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertEquals(set.comparator(), copy.comparator()); }
@GwtIncompatible // SerializableTester private static void checkSerialization(Predicate<? super Integer> predicate) { Predicate<? super Integer> reserialized = SerializableTester.reserializeAndAssert(predicate); assertEvalsLike(predicate, reserialized); } }
@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)); }
public void testConverter_serialization() { for (CaseFormat outer : CaseFormat.values()) { for (CaseFormat inner : CaseFormat.values()) { SerializableTester.reserializeAndAssert(outer.converterTo(inner)); } } } }
public void testSerializationWithMapMaker1() { ConcurrentMap<String, AtomicInteger> map = new MapMaker().makeMap(); multiset = ConcurrentHashMultiset.create(map); reserializeAndAssert(multiset); }
public void testSerialization_elementSet() { Multiset<String> c = ImmutableSortedMultiset.of("a", "b", "a"); Collection<String> copy = SerializableTester.reserializeAndAssert(c.elementSet()); assertThat(copy).containsExactly("a", "b").inOrder(); }
public void testSerialization_from() { Converter<String, String> dumb = Converter.from(toStringFunction(), toStringFunction()); SerializableTester.reserializeAndAssert(dumb); } }
@GwtIncompatible // SerializableTester public void testExplicit_serialization() { SortedSet<String> set = ImmutableSortedSet.orderedBy(STRING_LENGTH) .add("in", "the", "quick", "jumped", "over", "a") .build(); SortedSet<String> copy = SerializableTester.reserializeAndAssert(set); assertTrue(Iterables.elementsEqual(set, copy)); assertSame(set.comparator(), copy.comparator()); }
@GwtIncompatible // SerializableTester public void testNewSortedSetMultimapSerialization() { CountingSupplier<TreeSet<Integer>> factory = new SortedSetSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); SortedSetMultimap<Color, Integer> multimap = Multimaps.newSortedSetMultimap(map, factory); multimap.putAll(Color.BLUE, asList(3, 1, 4)); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); SerializableTester.reserializeAndAssert(multimap); assertEquals(INT_COMPARATOR, multimap.valueComparator()); }
private static <R, C, V> void validateReserialization(Table<R, C, V> original) { Table<R, C, V> copy = SerializableTester.reserializeAndAssert(original); assertThat(copy.cellSet()).containsExactlyElementsIn(original.cellSet()).inOrder(); assertThat(copy.rowKeySet()).containsExactlyElementsIn(original.rowKeySet()).inOrder(); assertThat(copy.columnKeySet()).containsExactlyElementsIn(original.columnKeySet()).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 // SerializableTester public void testExplicitComparatorSerialization() { TreeMultimap<String, Integer> multimap = createPopulate(); TreeMultimap<String, Integer> copy = SerializableTester.reserializeAndAssert(multimap); assertThat(copy.values()).containsExactly(7, 3, 1, null, 0, 6, 2).inOrder(); assertThat(copy.keySet()).containsExactly(null, "tree", "google").inOrder(); assertEquals(multimap.keyComparator(), copy.keyComparator()); assertEquals(multimap.valueComparator(), copy.valueComparator()); } }