SerializableTester.reserializeAndAssert
Code IndexAdd Codota to your IDE (free)

Best code snippets using com.google.common.testing.SerializableTester.reserializeAndAssert(Showing top 15 results out of 315)

origin: google/guava

public void testCreate() {
 ConcurrentHashMultiset<Integer> multiset = ConcurrentHashMultiset.create();
 assertTrue(multiset.isEmpty());
 reserializeAndAssert(multiset);
}
origin: google/guava

public void testObjectWhichIsEqualButChangesClass() {
 ObjectWhichIsEqualButChangesClass orig = new ObjectWhichIsEqualButChangesClass();
 boolean errorNotThrown = false;
 try {
  SerializableTester.reserializeAndAssert(orig);
  errorNotThrown = true;
 } catch (AssertionFailedError error) {
  // expected
  assertContains("expected:<class ", error.getMessage());
 }
 assertFalse(errorNotThrown);
}
origin: google/guava

@GwtIncompatible // SerializableTester
public void testNewSetMultimapSerialization() {
 CountingSupplier<Set<Integer>> factory = new SetSupplier();
 Map<Color, Collection<Integer>> map = Maps.newHashMap();
 SetMultimap<Color, Integer> multimap = Multimaps.newSetMultimap(map, factory);
 multimap.putAll(Color.BLUE, asList(3, 1, 4));
 multimap.putAll(Color.RED, asList(2, 7, 1, 8));
 SerializableTester.reserializeAndAssert(multimap);
}
origin: google/guava

@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);
}
origin: google/guava

public void testSerialization_andThen() {
 Converter<String, Long> converterA = Longs.stringConverter();
 Converter<Long, String> reverseConverter = Longs.stringConverter().reverse();
 Converter<String, String> composedConverter = converterA.andThen(reverseConverter);
 SerializableTester.reserializeAndAssert(composedConverter);
}
origin: google/guava

@GwtIncompatible // SerializableTester
public void testDifferentComparator_serialization() {
 // don't use Collections.reverseOrder(); it didn't reserialize to the same instance in JDK5
 Comparator<Comparable<?>> comparator = Ordering.natural().reverse();
 SortedSet<String> set =
   new ImmutableSortedSet.Builder<String>(comparator).add("a", "b", "c").build();
 SortedSet<String> copy = SerializableTester.reserializeAndAssert(set);
 assertTrue(Iterables.elementsEqual(set, copy));
 assertEquals(set.comparator(), copy.comparator());
}
origin: google/guava

@GwtIncompatible // SerializableTester
public void testOf_serialization() {
 SortedSet<String> set = of("e", "f", "b", "d", "c");
 SortedSet<String> copy = SerializableTester.reserializeAndAssert(set);
 assertTrue(Iterables.elementsEqual(set, copy));
 assertEquals(set.comparator(), copy.comparator());
}
origin: google/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();
}
origin: google/guava

@GwtIncompatible // SerializableTester
public void testSingle_serialization() {
 SortedSet<String> set = new SafeTreeSet<>();
 set.add("e");
 SortedSet<String> copy = SerializableTester.reserializeAndAssert(set);
 assertEquals(set.comparator(), copy.comparator());
}
origin: google/guava

 @GwtIncompatible // SerializableTester
 private static void checkSerialization(Predicate<? super Integer> predicate) {
  Predicate<? super Integer> reserialized = SerializableTester.reserializeAndAssert(predicate);
  assertEvalsLike(predicate, reserialized);
 }
}
origin: google/guava

public void testAsConverter_serialization() {
 ImmutableBiMap<String, Integer> biMap =
   ImmutableBiMap.of(
     "one", 1,
     "two", 2);
 Converter<String, Integer> converter = Maps.asConverter(biMap);
 SerializableTester.reserializeAndAssert(converter);
}
origin: google/guava

public void testCreateFromIterable() {
 Iterable<Integer> iterable = asList(1, 2, 2, 3, 4);
 ConcurrentHashMultiset<Integer> multiset = ConcurrentHashMultiset.create(iterable);
 assertEquals(2, multiset.count(2));
 reserializeAndAssert(multiset);
}
origin: google/guava

@GwtIncompatible // SerializableTester, ImmutableSortedAsList
public void testSubsetAsListReturnTypeAndSerialization() {
 ImmutableSet<String> set = ImmutableSortedSet.of("a", "e", "i", "o", "u").subSet("c", "r");
 ImmutableList<String> list = set.asList();
 assertTrue(list instanceof ImmutableSortedAsList);
 ImmutableList<String> copy = SerializableTester.reserializeAndAssert(list);
 assertTrue(copy instanceof ImmutableSortedAsList);
}
origin: google/guava

 @Override
 public void testSerialization() {
  SerializableTester.reserializeAndAssert(create());
 }
}
origin: google/guava

 @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());
 }
}
com.google.common.testingSerializableTesterreserializeAndAssert

Javadoc

Serializes and deserializes the specified object and verifies that the re-serialized object is equal to the provided object, that the hashcodes are identical, and that the class of the re-serialized object is identical to that of the original.

GWT warning: Under GWT, this method simply returns its input, as proper GWT serialization tests require more setup. This no-op behavior allows test authors to intersperse SerializableTester calls with other, GWT-compatible tests.

Note that the specified object may not be known by the compiler to be a java.io.Serializable instance, and is thus declared an Object. For example, it might be declared as a List.

Note also that serialization is not in general required to return an object that is Object#equals to the original, nor is it required to return even an object of the same class. For example, if sublists of MyList instances were serializable, those sublists might implement a private MySubList type but serialize as a plain MyList to save space. So long as MyList has all the public supertypes of MySubList, this is safe. For these cases, for which reserializeAndAssert is too strict, use #reserialize.

Popular methods of SerializableTester

  • reserialize
    Serializes and deserializes the specified object.GWT warning: Under GWT, this method simply returns

Popular classes and methods

  • runOnUiThread (Activity)
  • onCreateOptionsMenu (Activity)
  • Component (java.awt)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • PrintStream (java.io)
    Wraps an existing OutputStream and provides convenience methods for writing common data types in a h
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • HashMap (java.util)
    HashMap is an implementation of Map. All optional operations are supported.All elements are permitte
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,

For IntelliJ IDEA,
Android Studio or Eclipse

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)