Search in sources :

Example 21 with Serializer

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

the class OptionalSerializerExtensionTest method fromProxy.

@Test
public void fromProxy() {
    TypeMirror typeMirror = declaredTypeOf(Optional.class, Integer.class);
    Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
    CodeBlock actualCodeBlock = serializer.fromProxy(CodeBlock.of("x"));
    assertThat(actualCodeBlock.toString()).isEqualTo("java.util.Optional.ofNullable(x == null ? null : x)");
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) CodeBlock(com.squareup.javapoet.CodeBlock) 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 22 with Serializer

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

the class OptionalSerializerExtensionTest method proxyFieldType.

@Test
public void proxyFieldType() {
    TypeMirror typeMirror = declaredTypeOf(Optional.class, Integer.class);
    Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
    TypeMirror actualTypeMirror = serializer.proxyFieldType();
    assertThat(actualTypeMirror).isEqualTo(typeMirrorOf(Integer.class));
}
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)

Example 23 with Serializer

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

the class OptionalSerializerExtensionTest method getSerializer_nonOptional_emptyReturned.

@Test
public void getSerializer_nonOptional_emptyReturned() {
    TypeMirror typeMirror = typeMirrorOf(String.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) 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