Class ComparableTester


  • public final class ComparableTester
    extends AbstractTester
    This utility class checks classes which implements the Comparable interface. E.g. for two objects which are equals it is expected that the Comparable.compareTo(Object) method returns 0.
    Since:
    1.2 (21.09.2011)
    Author:
    oliver (ob@aosd.de)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertCompareTo​(java.lang.Class<? extends java.lang.Comparable> clazz)
      This method will create two objects of the given class using the default constructor and compares them.
      static void assertCompareTo​(java.lang.Comparable c1, java.lang.Comparable c2)
      The Comparable.compareTo(Object) method should return 0 if the given objects are eqals.
      static void assertCompareTo​(java.lang.Package pkg)
      Check for each Comparable class in the given package if the compareTo(..) method works as expected.
      static void assertCompareTo​(java.lang.Package pkg, java.util.regex.Pattern... excluded)
      Check for each Comparable class in the given package if the compareTo(..) method works as expected.
      static void assertCompareTo​(java.util.Collection<java.lang.Class<? extends java.lang.Comparable>> classes)
      Check for each class in the given collection if the compareTo method works as expected.
      static void assertCompareToOfPackage​(java.lang.String packageName)
      Check for each Comparable class in the given package if the compareTo(..) method works as expected.
      static void assertCompareToOfPackage​(java.lang.String packageName, java.lang.Class<? extends java.lang.Comparable<?>>... excluded)
      Check for each Comparable class in the given package if the compareTo(..) method works as expected.
      static void assertCompareToOfPackage​(java.lang.String packageName, java.util.regex.Pattern... excluded)
      Check for each Comparable class in the given package if the compareTo(..) method works as expected.
      • Methods inherited from class java.lang.Object

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

      • assertCompareTo

        public static void assertCompareTo​(java.lang.Comparable c1,
                                           java.lang.Comparable c2)
        The Comparable.compareTo(Object) method should return 0 if the given objects are eqals. If they are not equals the shouldn't return 0. This is checked here.
        Parameters:
        c1 - the first Comparable
        c2 - the second Comparable
      • assertCompareTo

        public static void assertCompareTo​(java.lang.Class<? extends java.lang.Comparable> clazz)
                                    throws java.lang.AssertionError
        This method will create two objects of the given class using the default constructor and compares them. So two preconditions must be true:
        1. the class must not be abstract
        2. there must be a (public) default constructor
        Parameters:
        clazz - the clazz
        Throws:
        java.lang.AssertionError - if the check fails
      • assertCompareTo

        public static void assertCompareTo​(java.util.Collection<java.lang.Class<? extends java.lang.Comparable>> classes)
        Check for each class in the given collection if the compareTo method works as expected.
        Parameters:
        classes - a collection of classes to be checked
      • assertCompareTo

        public static void assertCompareTo​(java.lang.Package pkg)
        Check for each Comparable class in the given package if the compareTo(..) method works as expected.

        To get a name of a package call Package.getPackage(String). But be sure that you can't get null as result. In this case use assertCompareToOfPackage(String).

        Parameters:
        pkg - the package e.g. "patterntesting.runtime"
        See Also:
        assertCompareToOfPackage(String)
      • assertCompareTo

        public static void assertCompareTo​(java.lang.Package pkg,
                                           java.util.regex.Pattern... excluded)
        Check for each Comparable class in the given package if the compareTo(..) method works as expected.

        To get a name of a package call Package.getPackage(String). But be sure that you can't get null as result. In this case use assertCompareToOfPackage(String).

        Parameters:
        pkg - the package e.g. "patterntesting.runtime"
        excluded - class pattern which should be excluded from the check
        Since:
        1.6
        See Also:
        assertCompareToOfPackage(String, Pattern...)
      • assertCompareToOfPackage

        public static void assertCompareToOfPackage​(java.lang.String packageName)
        Check for each Comparable class in the given package if the compareTo(..) method works as expected.
        Parameters:
        packageName - the package name e.g. "patterntesting.runtime"
      • assertCompareToOfPackage

        @SafeVarargs
        public static void assertCompareToOfPackage​(java.lang.String packageName,
                                                    java.lang.Class<? extends java.lang.Comparable<?>>... excluded)
        Check for each Comparable class in the given package if the compareTo(..) method works as expected.
        Parameters:
        packageName - the package name e.g. "patterntesting.runtime"
        excluded - classes which should be excluded from the check
        See Also:
        assertCompareToOfPackage(String)
      • assertCompareToOfPackage

        public static void assertCompareToOfPackage​(java.lang.String packageName,
                                                    java.util.regex.Pattern... excluded)
        Check for each Comparable class in the given package if the compareTo(..) method works as expected.
        Parameters:
        packageName - the package name e.g. "patterntesting.runtime"
        excluded - classes which should be excluded from the check
        Since:
        1.6
        See Also:
        assertCompareToOfPackage(String)