Class UtilityClassChecker


  • public class UtilityClassChecker
    extends java.lang.Object
    Hamcrest style class for verifying that a class follows the accepted rules for utility classes. The rules that are enforced for utility classes: - the class must be declared final - the class must have only one constructor - the constructor must be private and inaccessible to callers - the class must have only static methods
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertThatClassIsUtility​(java.lang.Class<?> clazz)
      Assert that the given class adheres to the utility class rules.
      void describeMismatch​(org.hamcrest.Description description)
      Describe why an error was reported.
      void describeTo​(org.hamcrest.Description description)
      Describe the source object that caused an error, using a Hamcrest Matcher style interface.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UtilityClassChecker

        public UtilityClassChecker()
    • 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
      • assertThatClassIsUtility

        public static void assertThatClassIsUtility​(java.lang.Class<?> clazz)
        Assert that the given class adheres to the utility class rules.
        Parameters:
        clazz - the class to check
        Throws:
        java.lang.AssertionError - if the class is not a valid utility class