Search in sources :

Example 16 with Serializer

use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.

the class ImmutableMapSerializerExtensionTest method fromProxy.

@Test
public void fromProxy() {
    TypeMirror typeMirror = declaredTypeOf(ImmutableMap.class, Integer.class, String.class);
    Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
    CodeBlock actualCodeBlock = serializer.fromProxy(CodeBlock.of("x"));
    assertThat(actualCodeBlock.toString()).isEqualTo(String.format("x.entrySet().stream().collect(%s.toImmutableMap(value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getKey()), value$ -> %s.<%s," + " %s>wrapper(element$ -> element$).apply(value$.getValue())))", IMMUTABLE_MAP, FUNCTION_WITH_EXCEPTIONS, INTEGER, INTEGER, FUNCTION_WITH_EXCEPTIONS, STRING, STRING));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) CodeBlock(com.squareup.javapoet.CodeBlock) Serializer(com.google.auto.value.extension.serializable.serializer.interfaces.Serializer) Test(org.junit.Test) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest)

Example 17 with Serializer

use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.

the class ImmutableMapSerializerExtensionTest method getSerializer_immutableMap_serializerReturned.

@Test
public void getSerializer_immutableMap_serializerReturned() {
    TypeMirror typeMirror = typeMirrorOf(ImmutableMap.class);
    Serializer actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
    assertThat(actualSerializer.getClass().getName()).contains("ImmutableMapSerializerExtension$ImmutableMapSerializer");
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Serializer(com.google.auto.value.extension.serializable.serializer.interfaces.Serializer) Test(org.junit.Test) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest)

Example 18 with Serializer

use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.

the class SerializerFactoryLoaderTest method getFactory_extensionsLoaded.

@Test
public void getFactory_extensionsLoaded() throws Exception {
    SerializerFactory factory = SerializerFactoryLoader.getFactory(mockProcessingEnvironment);
    Serializer actualSerializer = factory.getSerializer(typeMirrorOf(String.class));
    assertThat(actualSerializer.getClass().getName()).contains("TestStringSerializerFactory$TestStringSerializer");
}
Also used : SerializerFactory(com.google.auto.value.extension.serializable.serializer.interfaces.SerializerFactory) Serializer(com.google.auto.value.extension.serializable.serializer.interfaces.Serializer) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest) Test(org.junit.Test)

Example 19 with Serializer

use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.

the class ImmutableListSerializerExtensionTest method getSerializer_immutableListWithSerializableContainedType_emptyReturned.

@Test
public void getSerializer_immutableListWithSerializableContainedType_emptyReturned() {
    fakeSerializerFactory.setReturnIdentitySerializer(true);
    TypeMirror typeMirror = typeMirrorOf(ImmutableList.class);
    Optional<Serializer> actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment);
    assertThat(actualSerializer).isEmpty();
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Serializer(com.google.auto.value.extension.serializable.serializer.interfaces.Serializer) Test(org.junit.Test) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest)

Example 20 with Serializer

use of com.google.auto.value.extension.serializable.serializer.interfaces.Serializer in project auto by google.

the class OptionalSerializerExtensionTest method getSerializer_optional_serializerReturned.

@Test
public void getSerializer_optional_serializerReturned() {
    TypeMirror typeMirror = typeMirrorOf(Optional.class);
    Serializer actualSerializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
    assertThat(actualSerializer.getClass().getName()).contains("OptionalSerializerExtension$OptionalSerializer");
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Serializer(com.google.auto.value.extension.serializable.serializer.interfaces.Serializer) CompilationAbstractTest(com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest) Test(org.junit.Test)

Aggregations

Serializer (com.google.auto.value.extension.serializable.serializer.interfaces.Serializer)23 CompilationAbstractTest (com.google.auto.value.extension.serializable.serializer.utils.CompilationAbstractTest)20 TypeMirror (javax.lang.model.type.TypeMirror)20 Test (org.junit.Test)20 CodeBlock (com.squareup.javapoet.CodeBlock)6 SerializerFactory (com.google.auto.value.extension.serializable.serializer.interfaces.SerializerFactory)1 TestStringSerializerFactory (com.google.auto.value.extension.serializable.serializer.utils.TestStringSerializerFactory)1