DEFENSIVE PROGRAMMING WITH KLOJANG CHECK

Common Properties

The CommonProperties class provides property extraction functions for some commonly used properties of well-known classes and interfaces — for example the size property of a Collection. As with the CommonChecks class, these properties have been hooked up to a descriptive name of what they expose. Thus, very little input from you is required to generate a full-blown, informative error message:

import static org.klojang.check.CommonChecks.gte;
import static org.klojang.check.CommonProperties.size

// ...

    Check.notNull(emps, "employees").has(size(), gte(), 100);

This would cause the following error message to be generated if the size of the emps collection was, say, 42:

employees.size() must be >= 100 (was 42)

Here are some more examples:

    Check.that(-7).has(abs(), eq(), 7);
    Check.that("Hello, World!").has(strlen(), eq(), 13);
    Check.that("foo").has(toUpperCase(), EQ(), "FOO");
    Check.that(vehicle).has(type(), subtypeOf(), Car.class);