interface TypePrinter<T : Any>
This interface defines how to generate mock code for a custom object type.
Use typePrinter for simple, basic implementation.
abstract fun acceptsObject(obj: Any): Boolean
Return true if obj is a valid object to pass to generateCode. |
|
abstract fun generateCode(instance: T, generateConstructor: (Any?) -> String): String
A function that takes an instance of an object and returns a String representing the Kotlin code that can be used to recreate the instance with the same data. |
|
open fun modifyImports(imports: List<String>): List<String>
Optionally modify the import statements that will be added to the generated mock file. By default, each processed type is added as an import. |
class AutoValueTypePrinter : TypePrinter<Any>
This looks for classes generated via AutoValue, indicated by the class prefix GENERATED_PREFIX. When an autovalue class is found, code to reconstruct it is generated by reflectively accessing the Builder and its setter functions. |