com.google.common.testing.SerializableTester Java Examples

The following examples show how to use com.google.common.testing.SerializableTester. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: exonum-java-binding   Author: exonum   File: FunnelsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void testSerialization() {
  assertSame(
      Funnels.byteArrayFunnel(), SerializableTester.reserialize(Funnels.byteArrayFunnel()));
  assertSame(Funnels.integerFunnel(), SerializableTester.reserialize(Funnels.integerFunnel()));
  assertSame(Funnels.longFunnel(), SerializableTester.reserialize(Funnels.longFunnel()));
  assertSame(
      Funnels.unencodedCharsFunnel(),
      SerializableTester.reserialize(Funnels.unencodedCharsFunnel()));
  assertEquals(
      Funnels.sequentialFunnel(Funnels.integerFunnel()),
      SerializableTester.reserialize(Funnels.sequentialFunnel(Funnels.integerFunnel())));
  assertEquals(
      Funnels.stringFunnel(Charsets.US_ASCII),
      SerializableTester.reserialize(Funnels.stringFunnel(Charsets.US_ASCII)));
}
 
Example #2
Source Project: durian   Author: diffplug   File: FunctionsTest.java    License: Apache License 2.0 6 votes vote down vote up
@GwtIncompatible("SerializableTester")
private static <Y> void checkCanReserialize(Function<? super Integer, Y> f) {
	Function<? super Integer, Y> g = SerializableTester.reserializeAndAssert(f);
	for (int i = 1; i < 5; i++) {
		// convoluted way to check that the same result happens from each
		Y expected = null;
		try {
			expected = f.apply(i);
		} catch (IllegalArgumentException e) {
			try {
				g.apply(i);
				fail();
			} catch (IllegalArgumentException ok) {
				continue;
			}
		}
		assertEquals(expected, g.apply(i));
	}
}
 
Example #3
Source Project: caffeine   Author: ben-manes   File: IsCacheReserializable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean matchesSafely(T original, Description description) {
  desc = new DescriptionBuilder(description);

  T copy = SerializableTester.reserialize(original);

  if (original instanceof AsyncLoadingCache<?, ?>) {
    @SuppressWarnings("unchecked")
    AsyncLoadingCache<Object, Object> asyncCache = (AsyncLoadingCache<Object, Object>) original;
    @SuppressWarnings("unchecked")
    AsyncLoadingCache<Object, Object> asyncCopy = (AsyncLoadingCache<Object, Object>) copy;
    checkAsynchronousCache(asyncCache, asyncCopy, desc);
  } else if (original instanceof Cache<?, ?>) {
    @SuppressWarnings("unchecked")
    Cache<Object, Object> syncCache = (Cache<Object, Object>) original;
    @SuppressWarnings("unchecked")
    Cache<Object, Object> syncCopy = (Cache<Object, Object>) copy;
    checkSynchronousCache(syncCache, syncCopy, desc);
  } else {
    throw new UnsupportedOperationException();
  }

  return desc.matches();
}
 
Example #4
Source Project: Refaster   Author: google   File: UBinaryTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void serialization() {
  ULiteral oneLit = ULiteral.intLit(1);
  ULiteral twoLit = ULiteral.intLit(2);
  ULiteral piLit = ULiteral.doubleLit(Math.PI);
  ULiteral trueLit = ULiteral.booleanLit(true);
  ULiteral falseLit = ULiteral.booleanLit(false);

  SerializableTester.reserializeAndAssert(UBinary.create(Kind.PLUS, oneLit, twoLit));
  SerializableTester.reserializeAndAssert(UBinary.create(Kind.PLUS, oneLit, piLit));
  SerializableTester.reserializeAndAssert(UBinary.create(Kind.PLUS, piLit, twoLit));
  SerializableTester.reserializeAndAssert(UBinary.create(Kind.MINUS, oneLit, twoLit));
  SerializableTester.reserializeAndAssert(UBinary.create(Kind.XOR, oneLit, twoLit));
  SerializableTester.reserializeAndAssert(UBinary.create(Kind.CONDITIONAL_OR, trueLit, falseLit));
  SerializableTester.reserializeAndAssert(UBinary.create(Kind.OR, trueLit, falseLit));
}
 
Example #5
Source Project: mug   Author: google   File: ExceptionWrappingBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
void reserializeException(int n) {
  IOException exception = new IOException();
  for (int i = 0; i < n; i++) {
    SerializableTester.reserialize(exception);
  }
}
 
Example #6
Source Project: mug   Author: google   File: ExceptionWrappingBenchmark.java    License: Apache License 2.0 5 votes vote down vote up
@Benchmark
void reserializeString(int n) {
  String string = new String("abc");
  for (int i = 0; i < n; i++) {
    SerializableTester.reserialize(string);
  }
}
 
Example #7
Source Project: exonum-java-binding   Author: exonum   File: FunnelsTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testEquals() {
  new EqualsTester()
      .addEqualityGroup(Funnels.byteArrayFunnel())
      .addEqualityGroup(Funnels.integerFunnel())
      .addEqualityGroup(Funnels.longFunnel())
      .addEqualityGroup(Funnels.unencodedCharsFunnel())
      .addEqualityGroup(Funnels.stringFunnel(Charsets.UTF_8))
      .addEqualityGroup(Funnels.stringFunnel(Charsets.US_ASCII))
      .addEqualityGroup(
          Funnels.sequentialFunnel(Funnels.integerFunnel()),
          SerializableTester.reserialize(Funnels.sequentialFunnel(Funnels.integerFunnel())))
      .addEqualityGroup(Funnels.sequentialFunnel(Funnels.longFunnel()))
      .testEquals();
}
 
Example #8
Source Project: CuckooFilter4J   Author: MGunlogson   File: TestCuckooFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializePartFull() {
	CuckooFilter<Integer> filter = new CuckooFilter.Builder<>(Funnels.integerFunnel(), 2000000)
			.withFalsePositiveRate(0.01).withHashAlgorithm(Algorithm.Murmur3_32).build();
	for (int i = 0; i < 1000000; i++) {
		assertTrue(filter.put(i));
	}
	SerializableTester.reserializeAndAssert(filter);
}
 
Example #9
Source Project: CuckooFilter4J   Author: MGunlogson   File: TestCuckooFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializeFull() {
	CuckooFilter<Integer> filter = new CuckooFilter.Builder<>(Funnels.integerFunnel(), 2000000)
			.withFalsePositiveRate(0.01).withHashAlgorithm(Algorithm.Murmur3_32).build();
	for (int i = 0;; i++) {
		if (!filter.put(i))
			break;
	}
	SerializableTester.reserializeAndAssert(filter);
}
 
Example #10
Source Project: guava-probably   Author: bdupras   File: CuckooFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void javaSerialization() {
  CuckooFilter<byte[]> cf = CuckooFilter.create(Funnels.byteArrayFunnel(), 100);
  for (int i = 0; i < 10; i++) {
    cf.add(Ints.toByteArray(i));
  }

  CuckooFilter<byte[]> copy = SerializableTester.reserialize(cf);
  for (int i = 0; i < 10; i++) {
    assertTrue(copy.contains(Ints.toByteArray(i)));
  }
  assertEquals(cf.currentFpp(), copy.currentFpp());

  SerializableTester.reserializeAndAssert(cf);
}
 
Example #11
Source Project: nomulus   Author: google   File: CidrAddressBlockTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testSerializability() {
  SerializableTester.reserializeAndAssert(new CidrAddressBlock("22.24.66.0/24"));
  SerializableTester.reserializeAndAssert(new CidrAddressBlock("64.132.1.2"));
  SerializableTester.reserializeAndAssert(
      new CidrAddressBlock(InetAddresses.forString("1.2.3.4")));

  SerializableTester.reserializeAndAssert(new CidrAddressBlock("2001:db8::/32"));
  SerializableTester.reserializeAndAssert(new CidrAddressBlock("2001:db8::1"));
  SerializableTester.reserializeAndAssert(
      new CidrAddressBlock(InetAddresses.forString("5ffe::1")));
}
 
Example #12
Source Project: guava-probably   Author: bdupras   File: CuckooFilterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void javaSerialization() {
  CuckooFilter<byte[]> cf = CuckooFilter.create(Funnels.byteArrayFunnel(), 100);
  for (int i = 0; i < 10; i++) {
    cf.add(Ints.toByteArray(i));
  }

  CuckooFilter<byte[]> copy = SerializableTester.reserialize(cf);
  for (int i = 0; i < 10; i++) {
    assertTrue(copy.contains(Ints.toByteArray(i)));
  }
  assertEquals(cf.currentFpp(), copy.currentFpp());

  SerializableTester.reserializeAndAssert(cf);
}
 
Example #13
Source Project: durian   Author: diffplug   File: FunctionsTest.java    License: Apache License 2.0 5 votes vote down vote up
@GwtIncompatible("SerializableTester")
private static <Y> void checkCanReserializeSingleton(Function<? super String, Y> f) {
	Function<? super String, Y> g = SerializableTester.reserializeAndAssert(f);
	assertSame(f, g);
	for (Integer i = 1; i < 5; i++) {
		assertEquals(f.apply(i.toString()), g.apply(i.toString()));
	}
}
 
Example #14
Source Project: caffeine   Author: ben-manes   File: CaffeinatedGuavaTest.java    License: Apache License 2.0 5 votes vote down vote up
public void testSerializable() {
  SerializableTester.reserialize(CaffeinatedGuava.build(Caffeine.newBuilder()));
  SerializableTester.reserialize(CaffeinatedGuava.build(
      Caffeine.newBuilder(), IdentityLoader.INSTANCE));
  SerializableTester.reserialize(CaffeinatedGuava.build(
      Caffeine.newBuilder(), TestingCacheLoaders.identityLoader()));
}
 
Example #15
Source Project: caffeine   Author: ben-manes   File: AsMapTest.java    License: Apache License 2.0 5 votes vote down vote up
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
@CacheSpec(implementation = Implementation.Caffeine,
    population = { Population.SINGLETON, Population.PARTIAL, Population.FULL })
public void writeThroughEntry_serialize(Map<Integer, Integer> map, CacheContext context) {
  Map.Entry<Integer, Integer> entry = map.entrySet().iterator().next();
  Object copy = SerializableTester.reserialize(entry);
  assertThat(entry, is(equalTo(copy)));
}
 
Example #16
Source Project: Refaster   Author: google   File: ULiteralTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(ULiteral.intLit(1));
  SerializableTester.reserializeAndAssert(ULiteral.longLit(1L));
  SerializableTester.reserializeAndAssert(ULiteral.doubleLit(1.0));
  SerializableTester.reserializeAndAssert(ULiteral.floatLit(1.0f));
  SerializableTester.reserializeAndAssert(ULiteral.stringLit("foo"));
  SerializableTester.reserializeAndAssert(ULiteral.nullLit());
  SerializableTester.reserializeAndAssert(ULiteral.booleanLit(true));
  SerializableTester.reserializeAndAssert(ULiteral.charLit('0'));
}
 
Example #17
Source Project: Refaster   Author: google   File: UMethodInvocationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(UMethodInvocation.create(
      UMemberSelect.create(ULiteral.stringLit("foo"), 
          "indexOf", 
          UMethodType.create(UPrimitiveType.INT, UPrimitiveType.INT)), 
      ULiteral.charLit('a')));
}
 
Example #18
Source Project: Refaster   Author: google   File: UWhileLoopTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(UWhileLoop.create(
      UParens.create(UMethodInvocation.create(
          UMemberSelect.create(UFreeIdent.create("itr"), "hasNext", 
              UMethodType.create(UPrimitiveType.BOOLEAN)))),
      UBlock.create(UExpressionStatement.create(UMethodInvocation.create(
          UMemberSelect.create(UFreeIdent.create("itr"), "next", 
              UMethodType.create(UTypeVar.create("E"))))))));
}
 
Example #19
Source Project: Refaster   Author: google   File: UClassTypeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  UClassType stringType = UClassType.create("java.lang.String");
  UClassType integerType = UClassType.create("java.lang.Integer");
  SerializableTester.reserializeAndAssert(stringType);
  SerializableTester.reserializeAndAssert(integerType);
  SerializableTester.reserializeAndAssert(
      UClassType.create("java.util.List", stringType));
  SerializableTester.reserializeAndAssert(
      UClassType.create("java.util.List", integerType));
  SerializableTester.reserializeAndAssert(
      UClassType.create("java.util.Map", stringType, stringType));
}
 
Example #20
Source Project: Refaster   Author: google   File: UIfTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(UIf.create(
      UFreeIdent.create("cond"), 
      UBlock.create(UExpressionStatement.create(
          UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("y")))), 
      UBlock.create(UExpressionStatement.create(
          UAssign.create(UFreeIdent.create("x"), UFreeIdent.create("z"))))));
}
 
Example #21
Source Project: Refaster   Author: google   File: UEnhancedForLoopTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(UEnhancedForLoop.create(
      UVariableDecl.create("c", UPrimitiveTypeTree.CHAR, null), 
      UMethodInvocation.create(UMemberSelect.create(ULiteral.stringLit("foo"), "toCharArray", 
          UMethodType.create(UArrayType.create(UPrimitiveType.CHAR)))), USkip.INSTANCE));
}
 
Example #22
Source Project: Refaster   Author: google   File: UForLoopTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(UForLoop.create(ImmutableList.of(
      UVariableDecl.create("i", UPrimitiveTypeTree.INT, UFreeIdent.create("from"))), 
      UBinary.create(Kind.LESS_THAN, ULocalVarIdent.create("i"), UFreeIdent.create("to")), 
      ImmutableList.of(UExpressionStatement.create(
          UUnary.create(Kind.POSTFIX_INCREMENT, ULocalVarIdent.create("i")))), 
      UBlock.create()));
}
 
Example #23
Source Project: Refaster   Author: google   File: UArrayTypeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(
      UArrayType.create(UClassType.create("java.lang.String")));
  SerializableTester.reserializeAndAssert(UArrayType.create(UPrimitiveType.INT));
  SerializableTester.reserializeAndAssert(
      UArrayType.create(UArrayType.create(UPrimitiveType.INT)));
}
 
Example #24
Source Project: Refaster   Author: google   File: UDoWhileLoopTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(UDoWhileLoop.create(
      UBlock.create(
          UExpressionStatement.create(
              UAssign.create(ULocalVarIdent.create("old"), UMethodInvocation.create(
                  UMemberSelect.create(UFreeIdent.create("str"), "indexOf", 
                      UMethodType.create(
                          UPrimitiveType.INT, UPrimitiveType.INT, UPrimitiveType.INT)),
                  ULiteral.charLit(' '), 
                  UBinary.create(
                      Kind.PLUS, ULocalVarIdent.create("old"), ULiteral.intLit(1)))))),
      UParens.create(UBinary.create(
          Kind.NOT_EQUAL_TO, ULocalVarIdent.create("old"), ULiteral.intLit(-1)))));
}
 
Example #25
Source Project: Refaster   Author: google   File: UStaticIdentTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(UStaticIdent.create(
      "java.lang.Integer", "valueOf", 
      UMethodType.create(UClassType.create("java.lang.Integer"), 
          UClassType.create("java.lang.String"))));
}
 
Example #26
Source Project: Refaster   Author: google   File: UForAllTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  UType nullType = UPrimitiveType.create(TypeKind.NULL);
  UType objectType = UClassType.create("java.lang.Object", ImmutableList.<UType>of());
  UTypeVar eType = UTypeVar.create("E", nullType, objectType);
  UType listOfEType = UClassType.create("java.util.List", ImmutableList.<UType>of(eType));
  SerializableTester.reserializeAndAssert(UForAll.create(ImmutableList.of(eType), listOfEType));
}
 
Example #27
Source Project: Refaster   Author: google   File: UBlockTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void serialization() {
  SerializableTester.reserializeAndAssert(UBlock.create(
      UExpressionStatement.create(
          UMethodInvocation.create(
              UStaticIdent.create("java.lang.System", "exit", 
                  UMethodType.create(UPrimitiveType.VOID, UPrimitiveType.INT)), 
              ULiteral.intLit(0)))));
}
 
Example #28
Source Project: auto   Author: google   File: AutoValueTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializeWithVersionUID() throws Exception {
  SerializeWithVersionUID instance = SerializeWithVersionUID.create(23, "23");
  assertEquals(instance, SerializableTester.reserialize(instance));

  long serialVersionUID =
      ObjectStreamClass.lookup(AutoValue_AutoValueTest_SerializeWithVersionUID.class)
          .getSerialVersionUID();
  assertEquals(4294967297L, serialVersionUID);
}
 
Example #29
Source Project: auto   Author: google   File: SerializableAutoValueExtensionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void allFieldsAreSerialized_noEmpty() {
  DummySerializableAutoValue autoValue =
      DummySerializableAutoValue.builder()
          .setA(A)
          .setB(B)
          .setOptionalC(C)
          .setOptionalD(D)
          .build();

  DummySerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}
 
Example #30
Source Project: auto   Author: google   File: SerializableAutoValueExtensionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void allFieldsAreSerialized_withEmpty() {
  DummySerializableAutoValue autoValue =
      DummySerializableAutoValue.builder().setA(A).setB(B).build();

  DummySerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue);

  assertThat(actualAutoValue).isEqualTo(autoValue);
}