patterntesting.runtime.junit
Class ComparableTester

Package class diagram package ComparableTester
java.lang.Object
  extended by patterntesting.runtime.junit.ComparableTester

public final class ComparableTester
extends Object

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
static void assertCompareTo(Class<? extends Comparable> clazz)
          This method will create two objects of the given class using the default constructor and compares them.
static void assertCompareTo(Collection<Class<Comparable>> classes)
          Check for each class in the given collection if the compareTo method works as expected
static void assertCompareTo(Comparable c1, Comparable c2)
          The Comparable.compareTo(Object) method should return 0 if the given objects are eqals.
static void assertCompareTo(Package pkg)
          Check for each Comparable class in the given package if the compareTo(..) method works as expected.
static void assertCompareToOfPackage(String packageName)
          Check for each Comparable class in the given package if the compareTo(..) method works as expected.
static void assertCompareToOfPackage(String packageName, Class<? extends Comparable<?>>... excluded)
          Check for each Comparable class in the given package if the compareTo(..) method works as expected.
static void assertCompareToOfPackage(String packageName, List<Class<? extends Comparable<?>>> 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(Comparable c1,
                                   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
Throws:
AssertionError - if the check fails

assertCompareTo

public static void assertCompareTo(Class<? extends Comparable> clazz)
                            throws 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:
AssertionError - if the check fails

assertCompareTo

public static void assertCompareTo(Collection<Class<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(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)

assertCompareToOfPackage

public static void assertCompareToOfPackage(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

public static void assertCompareToOfPackage(String packageName,
                                            Class<? extends 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(String packageName,
                                            List<Class<? extends 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)


Copyright © 2002–2014 PatternTesting Team. All rights reserved.