Package org.codehaus.groovy.tools.groovydoc

# Class MockOutputTool

java.lang.Object
org.codehaus.groovy.tools.groovydoc.MockOutputTool

All Implemented Interfaces:
  `OutputTool`

public class MockOutputTool extends Object implements OutputTool
In-memory `OutputTool` used by tests. Nothing is written to disk by default, so test runs leave no filesystem artifacts.

Debugging: pass the `groovydoc.mockOutputTool.dumpDir` system property to also mirror every output call to that directory. Example (from the groovy-groovydoc module):

     ./gradlew :groovy-groovydoc:test -Dgroovydoc.mockOutputTool.dumpDir=build/mock-dump

When the property is unset, all calls are captured only in the in-memory `output` and `outputAreas` maps; inspect them via `getText(String)` or via a debugger breakpoint.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MockOutputTool()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `copyResource(String srcPath, String dstPath)`
  Copy a resource file (doc-files/, snippet-files/ content) from `srcPath` to `dstPath`.
  `String`
  `getText(String fileName)`
  Returns the content written to the given filename by `writeToOutput(java.lang.String, java.lang.String, java.lang.String)`, or `null` if no content has been written.
  `boolean`
  `isValidOutputArea(String fileName)`
  Returns `true` if `makeOutputArea(java.lang.String)` was previously called with the given filename.
  `void`
  `makeOutputArea(String filename)`
  Ensures that the supplied output location exists.
  `String`
  `toString()`
  `void`
  `writeToOutput(String fileName, String text, String charset)`
  Writes rendered text to the supplied output file.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### MockOutputTool

    public MockOutputTool()

- ## Method Details

  - ### makeOutputArea

    public void makeOutputArea(String filename)
    Ensures that the supplied output location exists.
    Specified by:
      `makeOutputArea` in interface `OutputTool`
    Parameters:
      `filename` - the output directory or root path to prepare

  - ### writeToOutput

    public void writeToOutput(String fileName, String text, String charset) throws Exception
    Writes rendered text to the supplied output file.
    Specified by:
      `writeToOutput` in interface `OutputTool`
    Parameters:
      `fileName` - the file to write
      `text` - the rendered content
      `charset` - the character set to use when writing
    Throws:
      `Exception` - if the output cannot be written

  - ### copyResource

    public void copyResource(String srcPath, String dstPath) throws IOException
    Copy a resource file (doc-files/, snippet-files/ content) from `srcPath` to `dstPath`. Routed through the tool rather than calling `Files.copy` directly so that alternative tools (notably `MockOutputTool`) can intercept the side-effect.
    Specified by:
      `copyResource` in interface `OutputTool`
    Throws:
      `IOException`

  - ### isValidOutputArea

    public boolean isValidOutputArea(String fileName)
    Returns `true` if `makeOutputArea(java.lang.String)` was previously called with the given filename.

  - ### getText

    public String getText(String fileName)
    Returns the content written to the given filename by `writeToOutput(java.lang.String, java.lang.String, java.lang.String)`, or `null` if no content has been written.

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`