Class ProvidedAttribute

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

public class ProvidedAttribute extends Object
The shared rules, and the one message shape, for an org.dbunit.annotation attribute that can be given inline or through a provider class. Three rules recur across @DbUnitPrep/@DbUnitExpected value()/provider(), @DbUnitConfig properties()/propertiesProvider(), @DbUnitExpected verify()/verifyDefinitions()/verifyTables(), and @DbUnitConfig databaseTesterFactory(): setting two mutually exclusive ways is an error, a provider returning null is an error, and a provider returning nothing - where nothing is a misconfiguration rather than a valid "none" - is an error. Routing every site's diagnostic through here keeps a user who trips two of them across different attributes from getting two differently shaped messages for the same class of mistake.

Public so a binding outside org.dbunit.annotation.runtime - such as DbUnitExtension, for databaseTesterFactory() - can reach it too.

Since:
3.6.0
Author:
Jeff Jensen
  • Method Details

    • rejectBothSet

      public static void rejectBothSet(boolean bothSet, String owner, String attributeA, String attributeB, String note)
      Throws an IllegalStateException when two mutually exclusive ways of setting the same attribute were both used.
      Parameters:
      bothSet - Whether both were given a non-default value.
      owner - The annotation carrying both attributes, with the test class where that adds clarity, e.g. "@DbUnitConfig" or "@DbUnitPrep on com.example.FooTest".
      attributeA - One attribute, e.g. "value()".
      attributeB - The other, e.g. "provider()".
      note - An extra sentence appended after "set only one.", or null for none.
    • requireProvided

      public static <T> T requireProvided(T provided, String providerInterface, Class<?> providerClass, String namedBy, String getter)
      Returns provided unless the provider returned null, in which case it throws an IllegalStateException naming the provider, its class, the attribute that named it, and the method called.
      Type Parameters:
      T - The provider's value type.
      Parameters:
      provided - The value the provider returned.
      providerInterface - The provider interface's simple name, e.g. "DataSetPathsProvider".
      providerClass - The provider implementation class.
      namedBy - The attribute that named the provider, e.g. "@DbUnitPrep.provider".
      getter - The provider method called, without parentheses, e.g. "getDataSetPaths".
      Returns:
      provided, when non-null.
    • rejectEmptyProvider

      public static void rejectEmptyProvider(boolean empty, String providerInterface, Class<?> providerClass, String namedBy, String getter, String note)
      Throws an IllegalStateException when a provider returned nothing.
      Parameters:
      empty - Whether the provider's output is empty.
      providerInterface - The provider interface's simple name.
      providerClass - The provider implementation class.
      namedBy - The attribute that named the provider.
      getter - The provider method called, without parentheses.
      note - Guidance appended to the message explaining why nothing is a misconfiguration.