Class ImmutableClassChecker


  • public class ImmutableClassChecker
    extends Object
    Hamcrest style class for verifying that a class follows the accepted rules for immutable classes. The rules that are enforced for immutable classes: - the class must be declared final - all data members of the class must be declared private and final - the class must not define any setter methods
    • Constructor Detail

      • ImmutableClassChecker

        public ImmutableClassChecker()
    • Method Detail

      • describeMismatch

        public void describeMismatch​(org.hamcrest.Description description)
        Describe why an error was reported. Uses Hamcrest style Description interfaces.
        Parameters:
        description - the Description object to use for reporting the mismatch
      • describeTo

        public void describeTo​(org.hamcrest.Description description)
        Describe the source object that caused an error, using a Hamcrest Matcher style interface. In this case, it always returns that we are looking for a properly defined utility class.
        Parameters:
        description - the Description object to use to report the "to" object
      • assertThatClassIsImmutable

        public static void assertThatClassIsImmutable​(Class<?> clazz)
        Assert that the given class adheres to the immutable class rules.
        Parameters:
        clazz - the class to check
        Throws:
        AssertionError - if the class is not an immutable class
      • assertThatClassIsImmutableBaseClass

        public static void assertThatClassIsImmutableBaseClass​(Class<?> clazz)
        Assert that the given class adheres to the immutable class rules, but is not declared final. Classes that need to be inherited from cannot be declared final.
        Parameters:
        clazz - the class to check
        Throws:
        AssertionError - if the class is not an immutable class