Package 

Interface TypePrinter


  • 
    public interface TypePrinter<T extends Object>
    
                        

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

    Use typePrinter for simple, basic implementation.

    • Method Summary

      Modifier and Type Method Description
      abstract Boolean acceptsObject(Object obj) Return true if obj is a valid object to pass to generateCode.
      abstract String generateCode(T instance, Function1<Object, String> generateConstructor) 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.
      List<String> modifyImports(List<String> imports) Optionally modify the import statements that will be added to the generated mock file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • generateCode

         abstract String generateCode(T instance, Function1<Object, String> generateConstructor)

        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.

        Parameters:
        generateConstructor - This function can be used to access the default code generation for arbitrary object types.
      • modifyImports

         List<String> modifyImports(List<String> imports)

        Optionally modify the import statements that will be added to the generated mock file. By default, each processed type is added as an import.

        This function can be used if your generated code depends on anything beyond the instance types that are processed.

        This will be called once per registered TypePrinter, after all other code has been generated, but only if this instance is actually used to generated code (ie it returned true from acceptsObject at least once).