Package org.dbunit.annotation.runtime
Class TesterStateSnapshot
java.lang.Object
org.dbunit.annotation.runtime.TesterStateSnapshot
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 Summary
Modifier and TypeMethodDescriptionstatic TesterStateSnapshotcapture(IDatabaseTester tester) Capturestester's current dataset and setup/teardown operations.static voidrestore(IDatabaseTester tester, TesterStateSnapshot snapshot) Restoressnapshotontotester, or does nothing whensnapshotisnull- the case when a lifecycle threw before capturing one, or never reached the capture at all.static voidrestoreSuppressing(IDatabaseTester tester, TesterStateSnapshot snapshot, Throwable primary) Restoressnapshotontotesterwhileprimaryis already being thrown, attaching any failure from the restore itself to it viaThrowable.addSuppressed(Throwable)rather than letting that failure replace the one already in flight.voidrestoreTo(IDatabaseTester tester) Restores this snapshot's dataset and setup/teardown operations ontotester.
-
Method Details
-
capture
Capturestester's current dataset and setup/teardown operations.- Parameters:
tester- The tester to snapshot.- Returns:
- The snapshot.
-
restoreTo
Restores this snapshot's dataset and setup/teardown operations ontotester.- Parameters:
tester- The tester to restore.
-
restore
Restoressnapshotontotester, or does nothing whensnapshotisnull- the case when a lifecycle threw before capturing one, or never reached the capture at all.- Parameters:
tester- The tester to restore; untouched whensnapshotisnull.snapshot- The snapshot to restore, ornullto do nothing.
-
restoreSuppressing
public static void restoreSuppressing(IDatabaseTester tester, TesterStateSnapshot snapshot, Throwable primary) Restoressnapshotontotesterwhileprimaryis already being thrown, attaching any failure from the restore itself to it viaThrowable.addSuppressed(Throwable)rather than letting that failure replace the one already in flight. Anullsnapshot is a no-op.- Parameters:
tester- The tester to restore.snapshot- The snapshot to restore, ornullto do nothing.primary- The failure already being thrown, to attach a restore failure to.
-