Class InjectedTestCaseTesterBinding

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

public class InjectedTestCaseTesterBinding extends Object
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 Details

    • resolveTester

      public static IDatabaseTester resolveTester(PrepAndExpectedTestCase testCase, String fieldDescription, Callable<IDatabaseTester> fallbackTester) throws Exception
      Resolves and wires the tester for testCase.
      Parameters:
      testCase - The already-injected test case, resolved and type-checked by the caller.
      fieldDescription - Where testCase came from, for an exception or log message - e.g. "field 'testCase' in com.example.MyTest".
      fallbackTester - Supplies a tester when testCase.getDatabaseTester() is null; not called otherwise.
      Returns:
      The resolved tester: testCase.getDatabaseTester() if already set, otherwise fallbackTester's value.
      Throws:
      Exception - If fallbackTester fails.
      IllegalStateException - If testCase's type overrides setDatabaseTester() but does not round-trip getDatabaseTester() back to the same instance.