Package org.dbunit.annotation.runtime
Class InjectedTestCaseTesterBinding
java.lang.Object
org.dbunit.annotation.runtime.InjectedTestCaseTesterBinding
Resolves the
IDatabaseTester for an already-injected @DbUnitTestCase instance:
PrepAndExpectedTestCase.getDatabaseTester() if it already has one, otherwise a
caller-supplied fallback, wired back onto the test case and round-trip-verified.
Public so a binding outside org.dbunit.annotation.runtime - such as
DbUnitExtension or a Spring TestExecutionListener - can reach it too, sharing
the one round-trip-verification rule rather than each re-implementing it: a test case whose
type overrides setDatabaseTester() but does not round-trip
getDatabaseTester() back to the same instance is a bug (an operation applied to the
resolved tester would silently never reach the tester the test case actually uses) and fails
fast, while one that never overrides setDatabaseTester() at all is the documented
self-managed-connection pattern and only logged.
- Since:
- 3.6.0
- Author:
- Jeff Jensen
-
Method Summary
Modifier and TypeMethodDescriptionstatic IDatabaseTesterresolveTester(PrepAndExpectedTestCase testCase, String fieldDescription, Callable<IDatabaseTester> fallbackTester) Resolves and wires the tester fortestCase.
-
Method Details
-
resolveTester
public static IDatabaseTester resolveTester(PrepAndExpectedTestCase testCase, String fieldDescription, Callable<IDatabaseTester> fallbackTester) throws Exception Resolves and wires the tester fortestCase.- Parameters:
testCase- The already-injected test case, resolved and type-checked by the caller.fieldDescription- WheretestCasecame from, for an exception or log message - e.g."field 'testCase' in com.example.MyTest".fallbackTester- Supplies a tester whentestCase.getDatabaseTester()isnull; not called otherwise.- Returns:
- The resolved tester:
testCase.getDatabaseTester()if already set, otherwisefallbackTester's value. - Throws:
Exception- IffallbackTesterfails.IllegalStateException- IftestCase's type overridessetDatabaseTester()but does not round-tripgetDatabaseTester()back to the same instance.
-