use of com.squareup.javapoet.CodeBlock in project auto by google.
the class ImmutableMapSerializerExtensionTest method toProxy.
@Test
public void toProxy() {
TypeMirror typeMirror = declaredTypeOf(ImmutableMap.class, Integer.class, String.class);
Serializer serializer = extension.getSerializer(typeMirror, fakeSerializerFactory, mockProcessingEnvironment).get();
CodeBlock actualCodeBlock = serializer.toProxy(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));
}
use of com.squareup.javapoet.CodeBlock in project auto by google.
the class IdentitySerializerFactoryTest method fromProxy_isUnchanged.
@Test
public void fromProxy_isUnchanged() throws Exception {
TypeMirror typeMirror = typeMirrorOf(String.class);
CodeBlock inputExpression = CodeBlock.of("x");
CodeBlock outputExpression = IdentitySerializerFactory.getSerializer(typeMirror).fromProxy(inputExpression);
assertThat(outputExpression).isSameInstanceAs(inputExpression);
}
use of com.squareup.javapoet.CodeBlock in project auto by google.
the class IdentitySerializerFactoryTest method toProxy_isUnchanged.
@Test
public void toProxy_isUnchanged() throws Exception {
TypeMirror typeMirror = typeMirrorOf(String.class);
CodeBlock inputExpression = CodeBlock.of("x");
CodeBlock outputExpression = IdentitySerializerFactory.getSerializer(typeMirror).toProxy(inputExpression);
assertThat(outputExpression).isSameInstanceAs(inputExpression);
}
use of com.squareup.javapoet.CodeBlock 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));
}
use of com.squareup.javapoet.CodeBlock 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)");
}
Aggregations