Class TestContext

java.lang.Object
net.kyori.mammoth.test.TestContext

@NullMarked public final class TestContext extends Object
Context information for individual tests.

Within this class, all input paths are for classpath resources relative to the current test class.

Since:
1.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    assertOutputEquals(String resourceName, String fileName)
    Expect that the contents of the output file fileName is equal to the contents of the resource at <testName>/out/<resourceName>.
    void
    Assert that the output at destination is equal to the literal text.
    org.gradle.testkit.runner.BuildResult
    build(String... extraArgs)
    Create and execute a new Gradle runner.
    void
    Copy a resource from the <testName>/in/ directory to the run directory with no changes.
    void
    copyInput(String fromName, String toName)
    copy a resource from the <testName>/in/ directory to the run directory with the provided new name.
    The output directory for the Gradle build.
    readOutput(String fileName)
    Expect that a file is present in the output directory with the provided path.
    org.gradle.testkit.runner.GradleRunner
    runner(String... extraArgs)
    Create a new Gradle runner.
    void
    writeText(String destination, String text)
    Write literal text to a file in the run director with the provided new name.

    Methods inherited from class java.lang.Object

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

    • outputDirectory

      public Path outputDirectory()
      The output directory for the Gradle build.
      Returns:
      the output directory
      Since:
      1.1.0
    • copyInput

      public void copyInput(String name) throws IOException
      Copy a resource from the <testName>/in/ directory to the run directory with no changes.
      Parameters:
      name - the input relative to the test's directory
      Throws:
      IOException - if an error occurs writing the input file to disk
      Since:
      1.1.0
    • copyInput

      public void copyInput(String fromName, String toName) throws IOException
      copy a resource from the <testName>/in/ directory to the run directory with the provided new name.
      Parameters:
      fromName - the name relative to the input
      toName - the name to use in the test's output directory
      Throws:
      IOException - if an error occurs writing the input file to disk
      Since:
      1.1.0
    • writeText

      public void writeText(String destination, String text) throws IOException
      Write literal text to a file in the run director with the provided new name.
      Parameters:
      destination - The path to the location to write to
      text - the text to write
      Throws:
      IOException - if an error occurs writing the text
      Since:
      1.2.0
    • readOutput

      public String readOutput(String fileName) throws IOException
      Expect that a file is present in the output directory with the provided path.
      Parameters:
      fileName - the file name
      Returns:
      the contents of the file as a string
      Throws:
      IOException - if thrown while attempting to read the output file
      Since:
      1.1.0
    • assertOutputEqualsLiteral

      public void assertOutputEqualsLiteral(String destination, String text) throws IOException
      Assert that the output at destination is equal to the literal text.
      Parameters:
      destination - the output file to check
      text - the expected text
      Throws:
      IOException - if an error occurs reading the text
      Since:
      1.2.0
    • assertOutputEquals

      public void assertOutputEquals(String resourceName, String fileName) throws IOException
      Expect that the contents of the output file fileName is equal to the contents of the resource at <testName>/out/<resourceName>.
      Parameters:
      resourceName - the name of the expected resource
      fileName - the name of the actual output file
      Throws:
      IOException - if failed to read one of the files
      Since:
      1.1.0
    • runner

      public org.gradle.testkit.runner.GradleRunner runner(String... extraArgs)
      Create a new Gradle runner.
      Parameters:
      extraArgs - extra arguments to provide
      Returns:
      the new runner
      Since:
      1.1.0
    • build

      public org.gradle.testkit.runner.BuildResult build(String... extraArgs)
      Create and execute a new Gradle runner.
      Parameters:
      extraArgs - the extra arguments to provide
      Returns:
      the result of an executed build
      Since:
      1.1.0