Class TesterStateSnapshot

java.lang.Object
org.dbunit.annotation.runtime.TesterStateSnapshot

public class TesterStateSnapshot extends Object
An immutable snapshot of the three pieces of an IDatabaseTester the annotation runtime mutates for a test - its dataset, setup operation, and teardown operation - so they can be put back after the test.

Both lifecycle paths take one at the start of a test and restore it at the end, so a tester shared across methods - a static @DbUnitTester field, or any tester field under @TestInstance(Lifecycle.PER_CLASS) - carries no per-method @DbUnitPrep/@DbUnitSetup/@DbUnitTearDown onto the next method. A value a @BeforeEach method set is the captured snapshot and is restored unchanged, so configuring the tester in @BeforeEach still works.

Since:
3.6.0
Author:
Jeff Jensen
  • Method Details

    • capture

      public static TesterStateSnapshot capture(IDatabaseTester tester)
      Captures tester's current dataset and setup/teardown operations.
      Parameters:
      tester - The tester to snapshot.
      Returns:
      The snapshot.
    • restoreTo

      public void restoreTo(IDatabaseTester tester)
      Restores this snapshot's dataset and setup/teardown operations onto tester.
      Parameters:
      tester - The tester to restore.
    • restore

      public static void restore(IDatabaseTester tester, TesterStateSnapshot snapshot)
      Restores snapshot onto tester, or does nothing when snapshot is null - the case when a lifecycle threw before capturing one, or never reached the capture at all.
      Parameters:
      tester - The tester to restore; untouched when snapshot is null.
      snapshot - The snapshot to restore, or null to do nothing.
    • restoreSuppressing

      public static void restoreSuppressing(IDatabaseTester tester, TesterStateSnapshot snapshot, Throwable primary)
      Restores snapshot onto tester while primary is already being thrown, attaching any failure from the restore itself to it via Throwable.addSuppressed(Throwable) rather than letting that failure replace the one already in flight. A null snapshot is a no-op.
      Parameters:
      tester - The tester to restore.
      snapshot - The snapshot to restore, or null to do nothing.
      primary - The failure already being thrown, to attach a restore failure to.