mvrx-mocking / com.airbnb.mvrx.mocking.printer / TypePrinter

TypePrinter

interface TypePrinter<T : Any>

This interface defines how to generate mock code for a custom object type.

Use typePrinter for simple, basic implementation.

Functions

acceptsObject

abstract fun acceptsObject(obj: Any): Boolean

Return true if obj is a valid object to pass to generateCode.

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.

modifyImports

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.

Inheritors

AutoValueTypePrinter

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.