Class JavaBeanTesterBuilder<T,E>

java.lang.Object
com.codebox.bean.JavaBeanTesterBuilder<T,E>
Type Parameters:
T - the type under test
E - the extension type used for equality-related checks

public class JavaBeanTesterBuilder<T,E> extends Object
Fluent configuration object returned by JavaBeanTester.builder(Class).

Configure optional checks by chaining methods such as checkEquals(), checkSerializable(), loadData(), or skip(String...), then finish with a terminal method such as test(), testInstance(Object), testEquals(Object, Object), testObjectMethods(), or testPrivateConstructor().

  • Method Details

    • checkClear

      public JavaBeanTesterBuilder<T,E> checkClear()
      Enables clear() verification.
      Returns:
      this builder
    • checkClear

      public JavaBeanTesterBuilder<T,E> checkClear(boolean value)
      Toggles clear() verification.
      Parameters:
      value - true to enable the check, false to disable it
      Returns:
      this builder
    • checkConstructor

      public JavaBeanTesterBuilder<T,E> checkConstructor()
      Enables public-constructor verification.
      Returns:
      this builder
    • checkConstructor

      public JavaBeanTesterBuilder<T,E> checkConstructor(boolean value)
      Toggles public-constructor verification.
      Parameters:
      value - true to enable the check, false to disable it
      Returns:
      this builder
    • checkEquals

      public JavaBeanTesterBuilder<T,E> checkEquals()
      Enables equals, hashCode, toString, and canEqual verification.
      Returns:
      this builder
    • checkEquals

      public JavaBeanTesterBuilder<T,E> checkEquals(boolean value)
      Toggles equals, hashCode, toString, and canEqual verification.
      Parameters:
      value - true to enable the check, false to disable it
      Returns:
      this builder
    • checkSerializable

      public JavaBeanTesterBuilder<T,E> checkSerializable()
      Requires the type under test to be serializable and validates a serialization round-trip.
      Returns:
      this builder
    • checkSerializable

      public JavaBeanTesterBuilder<T,E> checkSerializable(boolean value)
      Toggles strict serializable validation.
      Parameters:
      value - true to require serialization support, false to skip the strict requirement
      Returns:
      this builder
    • loadData

      public JavaBeanTesterBuilder<T,E> loadData()
      Enables recursive sample-data generation for supported property types.
      Returns:
      this builder
    • loadData

      public JavaBeanTesterBuilder<T,E> loadData(boolean value)
      Toggles recursive sample-data generation for supported property types.
      Parameters:
      value - true to enable generated data, false to disable it
      Returns:
      this builder
    • skipStrictSerializable

      public JavaBeanTesterBuilder<T,E> skipStrictSerializable()
      Skip Strict Serializable is intended to relax strict check on serializable objects. For complex objects, strict checking will result in issues with equals check. Testing has shown this to be generally not a normal use case of javabean tester as it is normally used with POJOs only. In such a case, caller will get an error and if there is not actually a code problem they should turn this skip on.
      Returns:
      the java bean tester builder
    • skip

      public JavaBeanTesterBuilder<T,E> skip(String... propertyNames)
      Skips the supplied bean properties during getter/setter validation.
      Parameters:
      propertyNames - the bean property names to exclude
      Returns:
      this builder
    • test

      public void test()
      Runs the configured bean validation flow.
    • testPrivateConstructor

      public void testPrivateConstructor()
      Verifies that a private constructor can be exercised.
    • testObjectMethods

      public void testObjectMethods()
      Runs only the object-method checks for the configured class.
    • testInstance

      public void testInstance(T instance)
      Runs getter/setter checks against the supplied instance.
      Parameters:
      instance - the instance to populate and verify
    • testEquals

      public void testEquals(T instance, T expected)
      Compares two prepared instances using the configured equality options.
      Parameters:
      instance - the instance under test
      expected - the expected comparison instance