@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)); }
@Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer(
      TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv); }
ImmutableMapSerializerExtension implements SerializerExtension { @Override public Optional<Serializer> getSerializer( TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv) { if (!isImmutableMap(typeMirror)) { return Optional.empty(); } TypeMirror keyType = getKeyType(typeMirror); TypeMirror valueType = getValueType(typeMirror); Serializer keyTypeSerializer = factory.getSerializer(keyType); Serializer valueTypeSerializer = factory.getSerializer(valueType); if (keyTypeSerializer.isIdentity() && valueTypeSerializer.isIdentity()) { return Optional.empty(); } return Optional.of( new ImmutableMapSerializer( keyType, valueType, keyTypeSerializer, valueTypeSerializer, processingEnv)); } ImmutableMapSerializerExtension(); @Override Optional<Serializer> getSerializer(
      TypeMirror typeMirror, SerializerFactory factory, ProcessingEnvironment processingEnv);  }