PojoTester

Exercises the getters and setters of the provided pojo, ensuring that there are no side-effects.

As getters and setters are so simple, the intention of automating their testing is not to discover defects (though if there are unintentional side-effects, then these will be found). Instead, the rationale of testing getters and setters is to increase code coverage. Any substantial gap away from 100% would therefore due to significant functionality not having tests (as opposed to merely getters and setters not being tested).

API

PojoTester.java
class PojoTester {
  PojoTester create()     (1)
  PojoTester usingData(DatumFactory<T> factory)     (2)
  PojoTester usingData(Class<?> type, DatumFactory<T> factory)
  PojoTester usingData(Class<T> c, T... data)     (3)
  PojoTester usingData(Class<T> c, List<T> data)
  PojoTester usingData(Class<T> compileTimeType, Class<? extends T> runtimeType)     (4)
  PojoTester usingData(Class<T> compileTimeType)     (5)
  void exercise(Object bean)     (6)
  void exercise(Object bean, FilterSet filterSet)     (7)
}
1 create()

Factory method for the tester itself.

2 usingData(DatumFactory)

Provides a DatumFactory to the PojoTester in order to exercise any getter/setters of this type.

3 usingData(Class, T)

Convenience overload to provide a DatumFactory to the PojoTester , specifying both the type and a number of instances of that type.

4 usingData(Class, Class)

Convenience overload to provide a DatumFactory to the PojoTester for the specified compile time type, with the runtime type providing a no-arg constructor so that instances can be generated as required.

5 usingData(Class)

Convenience overload to provide a DatumFactory to the PojoTester for the specified compile time type, also instantiatable as the runtime type (with a no-arg constructor).

6 exercise(Object)

Exercises all of the getters and setters of the provided bean, using the built-in DatumFactory and any additional configured through previous calls to #usingData(Class, Object[]) (or its overloads).

7 exercise(Object, FilterSet)

As for #exercise(Object) , however only exercising the properties as defined by the provided FilterSet , and omitting any others.

Members

create()

Factory method for the tester itself.

This method is usually followed by several calls to #usingData(DatumFactory) or #usingData(Class, Object[]) (for all data types that are not built-in), and finally by #exercise(Object) (or one of its overloads) which actually exercises the provided pojo.

usingData(DatumFactory)

Provides a DatumFactory to the PojoTester in order to exercise any getter/setters of this type.

The PojoTester already knows how to exercise primitives, strings, enums and a number of other built-ins, so this is typically only necessary for custom value types.

usingData(Class, T)

Convenience overload to provide a DatumFactory to the PojoTester , specifying both the type and a number of instances of that type.

There should be at least two and ideally three different data instances.

usingData(Class, Class)

Convenience overload to provide a DatumFactory to the PojoTester for the specified compile time type, with the runtime type providing a no-arg constructor so that instances can be generated as required.

usingData(Class)

Convenience overload to provide a DatumFactory to the PojoTester for the specified compile time type, also instantiatable as the runtime type (with a no-arg constructor).

exercise(Object)

Exercises all of the getters and setters of the provided bean, using the built-in DatumFactory and any additional configured through previous calls to #usingData(Class, Object[]) (or its overloads).

exercise(Object, FilterSet)

As for #exercise(Object) , however only exercising the properties as defined by the provided FilterSet , and omitting any others.