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 File: FunnelsTest.java From exonum-java-binding with Apache License 2.0 | 6 votes |
@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 File: FunctionsTest.java From durian with Apache License 2.0 | 6 votes |
@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 File: IsCacheReserializable.java From caffeine with Apache License 2.0 | 6 votes |
@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 File: UBinaryTest.java From Refaster with Apache License 2.0 | 6 votes |
@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 File: SerializableAutoValueExtensionTest.java From auto with Apache License 2.0 | 5 votes |
@Test public void immutableMap_allFieldsSetAndSerialized() { ImmutableMapSerializableAutoValue autoValue = ImmutableMapSerializableAutoValue.builder() .setA(ImmutableMap.of(Optional.of("key"), "value")) .setB(ImmutableMap.of("key", Optional.of("value"))) .build(); ImmutableMapSerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue); assertThat(actualAutoValue).isEqualTo(autoValue); }
Example #6
Source File: SerializableAutoValueExtensionTest.java From auto with Apache License 2.0 | 5 votes |
@Test public void allFieldsAreSerialized_withMixedEmpty() { DummySerializableAutoValue autoValue = DummySerializableAutoValue.builder().setA(A).setB(B).setOptionalC(C).build(); DummySerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue); assertThat(actualAutoValue).isEqualTo(autoValue); }
Example #7
Source File: SerializableAutoValueExtensionTest.java From auto with Apache License 2.0 | 5 votes |
@Test public void allPrefixFieldsAreSerialized_noEmpty() { PrefixSerializableAutoValue autoValue = PrefixSerializableAutoValue.builder().a("A").b(true).c("C").d(false).build(); PrefixSerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue); assertThat(actualAutoValue).isEqualTo(autoValue); }
Example #8
Source File: UMethodInvocationTest.java From Refaster with Apache License 2.0 | 5 votes |
@Test public void serialization() { SerializableTester.reserializeAndAssert(UMethodInvocation.create( UMemberSelect.create(ULiteral.stringLit("foo"), "indexOf", UMethodType.create(UPrimitiveType.INT, UPrimitiveType.INT)), ULiteral.charLit('a'))); }
Example #9
Source File: SerializableAutoValueExtensionTest.java From auto with Apache License 2.0 | 5 votes |
@Test public void allPrefixFieldsAreSerialized_WithEmpty() { PrefixSerializableAutoValue autoValue = PrefixSerializableAutoValue.builder().a("A").b(true).build(); PrefixSerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue); assertThat(actualAutoValue).isEqualTo(autoValue); }
Example #10
Source File: ULiteralTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 #11
Source File: FunnelsTest.java From exonum-java-binding with Apache License 2.0 | 5 votes |
@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 #12
Source File: CuckooFilterTest.java From guava-probably with Apache License 2.0 | 5 votes |
@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 File: SerializableAutoValueExtensionTest.java From auto with Apache License 2.0 | 5 votes |
@Test public void immutableMap_emptyMapSerialized() { ImmutableMapSerializableAutoValue autoValue = ImmutableMapSerializableAutoValue.builder() .setA(ImmutableMap.of()) .setB(ImmutableMap.of()) .build(); ImmutableMapSerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue); assertThat(actualAutoValue).isEqualTo(autoValue); }
Example #14
Source File: TestCuckooFilter.java From CuckooFilter4J with Apache License 2.0 | 5 votes |
@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 #15
Source File: TestCuckooFilter.java From CuckooFilter4J with Apache License 2.0 | 5 votes |
@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 #16
Source File: ExceptionWrappingBenchmark.java From mug with Apache License 2.0 | 5 votes |
@Benchmark void reserializeException(int n) { IOException exception = new IOException(); for (int i = 0; i < n; i++) { SerializableTester.reserialize(exception); } }
Example #17
Source File: ExceptionWrappingBenchmark.java From mug with Apache License 2.0 | 5 votes |
@Benchmark void reserializeString(int n) { String string = new String("abc"); for (int i = 0; i < n; i++) { SerializableTester.reserialize(string); } }
Example #18
Source File: SerializableAutoValueExtensionTest.java From auto with Apache License 2.0 | 5 votes |
@Test public void allFieldsAreSerialized_withEmpty() { DummySerializableAutoValue autoValue = DummySerializableAutoValue.builder().setA(A).setB(B).build(); DummySerializableAutoValue actualAutoValue = SerializableTester.reserialize(autoValue); assertThat(actualAutoValue).isEqualTo(autoValue); }
Example #19
Source File: SerializableAutoValueExtensionTest.java From auto with Apache License 2.0 | 5 votes |
@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 #20
Source File: AutoValueTest.java From auto with Apache License 2.0 | 5 votes |
@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 #21
Source File: UBlockTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 #22
Source File: UForAllTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 #23
Source File: UStaticIdentTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 #24
Source File: UDoWhileLoopTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 File: UArrayTypeTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 #26
Source File: UWhileLoopTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 #27
Source File: UClassTypeTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 #28
Source File: UIfTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 #29
Source File: UForLoopTest.java From Refaster with Apache License 2.0 | 5 votes |
@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 #30
Source File: UEnhancedForLoopTest.java From Refaster with Apache License 2.0 | 5 votes |
@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)); }