Package org.dbunit

Class PrepAndExpectedTestData

java.lang.Object
org.dbunit.PrepAndExpectedTestData

public class PrepAndExpectedTestData extends Object
The table verification definitions, prep data files, and expected data files for one PrepAndExpectedTestCase run, bundled as a single immutable value.

PrepAndExpectedTestCase.configureTest(PrepAndExpectedTestData), PrepAndExpectedTestCase.preTest(PrepAndExpectedTestData), and PrepAndExpectedTestCase.runTest(PrepAndExpectedTestData, PrepAndExpectedTestCaseSteps) each accept one of these in place of the three separate array arguments their older overloads take. The three values describe one test scenario and are meaningless apart, so passing them as one argument keeps a data-driven test's @MethodSource rows, parameter lists, and any row-factory methods from carrying the same triple through every layer, and collapses the three per-scenario "empty" constants a suite would otherwise declare into the shared NONE.

An instance carries no mutable state of its own: the constructor copies each array in, every getter copies its array out, and a null array is normalized to an empty one. The VerifyTableDefinition elements are referenced as given rather than deep-copied, so a caller must not mutate a VerifyTableDefinition through its setters once it has been passed to this constructor; doing so retroactively changes the scenario an already-built instance describes. This matches how a suite is expected to supply them - as shared static final constants.

Since:
3.6.0
Author:
Jeff Jensen
  • Field Details

    • NONE

      public static final PrepAndExpectedTestData NONE
      Verifies no tables, loads no prep data, and expects no data. The shared constant for a scenario that needs none of the three, replacing a separate empty constant per type.
  • Constructor Details

    • PrepAndExpectedTestData

      public PrepAndExpectedTestData(VerifyTableDefinition[] verifyTableDefinitions, String[] prepDataFiles, String[] expectedDataFiles)
      Creates an instance carrying the given verification definitions and prep and expected data file paths.
      Parameters:
      verifyTableDefinitions - The table definitions to verify after the test runs; null or empty verifies no tables.
      prepDataFiles - The prep data files (as classpath resources) to load and insert as seed data; null or empty loads none.
      expectedDataFiles - The expected data files (as classpath resources) to verify actual data against after the test runs; null or empty expects none.
  • Method Details

    • prepOnly

      public static PrepAndExpectedTestData prepOnly(String... prepDataFiles)
      Creates an instance that loads the given prep data files and does nothing else - verifies no tables and expects no data.
      Parameters:
      prepDataFiles - The prep data files (as classpath resources) to load and insert as seed data.
      Returns:
      The instance.
    • getVerifyTableDefinitions

      public VerifyTableDefinition[] getVerifyTableDefinitions()
      Returns the table definitions to verify after the test runs.
      Returns:
      A copy of the verify table definitions; empty if none.
    • getPrepDataFiles

      public String[] getPrepDataFiles()
      Returns the prep data file paths.
      Returns:
      A copy of the prep data file paths; empty if none.
    • getExpectedDataFiles

      public String[] getExpectedDataFiles()
      Returns the expected data file paths.
      Returns:
      A copy of the expected data file paths; empty if none.
    • equals

      public boolean equals(Object o)

      Two instances are equal when their prep and expected file paths match by content and their verify table definitions match by array position. VerifyTableDefinition does not define value equality, so that part of the comparison is by instance identity - which is what the intended usage produces: sharing static final VerifyTableDefinition constants across scenarios.

      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object