Class BaseComparatorTestCase<T>

  • Type Parameters:
    T - the generic type of the objects to compare

    public abstract class BaseComparatorTestCase<T>
    extends AbstractTestCase<java.lang.Integer,​java.lang.Boolean>
    The abstract class BaseComparatorTestCase is for unit tests with Comparator. An example is in the unit test class DateComparatorTest in project silly-collections
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Comparator<T> comparator
      The comparator.
      protected T o1
      The first comparison object.
      protected T o2
      The other object to compare.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void assertEquals​(T expected, T actual)
      Abstract method that have to be implemented from derived classes with the specific unit framework
      protected abstract void assertTrue​(java.lang.Boolean expected)
      Abstract method that have to be implemented from derived classes with the specific unit framework
      protected abstract java.util.List<T> newActualList()
      Abstract factory callback method that have to be overwritten for create the List with objects to sort in the sort scenario.
      protected abstract java.util.Comparator<T> newComparator()
      Abstract factory callback method that have to be overwritten for create the specific comparator object
      protected abstract java.util.List<T> newExpectedSortedList()
      Abstract factory callback method that have to be overwritten for create the expected List with objects to test the sort algorithm in the sort scenario.
      protected abstract java.util.List<T> newExpectedUnsortedList()
      Abstract factory callback method that have to be overwritten for create the List with objects to sort in the sort scenario.
      protected abstract T newO1Equal()
      Abstract factory callback method that have to be overwritten for create the other object to compare in the scenario that the objects are equal.
      protected abstract T newO1GreaterThan()
      Abstract factory callback method that have to be overwritten for create the first comparison object in the scenario greater than.
      protected abstract T newO1LessThan()
      Abstract factory callback method that have to be overwritten for create the first comparison object in the scenario less than.
      protected T newO2Equal()
      Factory callback method that can be overwritten for create the other object to compare in the scenario that the objects are equal.
      protected abstract T newO2GreaterThan()
      Abstract factory callback method that have to be overwritten for create the other object to compare in the scenario greater than.
      protected abstract T newO2LessThan()
      Abstract factory callback method that have to be overwritten for create the other object to compare in the scenario less than.
      void setUp()
      Sets up method will be invoked before every unit test method
      void tearDown()
      Tear down method will be invoked after every unit test method

      Note: call super.tearDown() if you overwrite it for set actual and expected to null
      void testCompare()
      Test method for Comparator.compare(Object, Object)
      void testEqual()
      Test scenario when comparison objects are equal.
      void testGreaterThan()
      Test scenario when a comparison object is greater than the other object to compare.
      void testLessThan()
      Test scenario when a comparison object is less than the other object to compare.
      • Methods inherited from class java.lang.Object

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

      • comparator

        protected java.util.Comparator<T> comparator
        The comparator.
      • o1

        protected T o1
        The first comparison object.
      • o2

        protected T o2
        The other object to compare.
    • Constructor Detail

      • BaseComparatorTestCase

        public BaseComparatorTestCase()
    • Method Detail

      • newActualList

        protected abstract java.util.List<T> newActualList()
        Abstract factory callback method that have to be overwritten for create the List with objects to sort in the sort scenario.
        Returns:
        the List with objects to test the sort algorithm
      • newComparator

        protected abstract java.util.Comparator<T> newComparator()
        Abstract factory callback method that have to be overwritten for create the specific comparator object
        Returns:
        the specific comparator
      • newExpectedSortedList

        protected abstract java.util.List<T> newExpectedSortedList()
        Abstract factory callback method that have to be overwritten for create the expected List with objects to test the sort algorithm in the sort scenario.
        Returns:
        the List with objects to test the sort algorithm
      • newExpectedUnsortedList

        protected abstract java.util.List<T> newExpectedUnsortedList()
        Abstract factory callback method that have to be overwritten for create the List with objects to sort in the sort scenario.

        Note:This list have to be equal with newActualList()
        Returns:
        the List with objects to test the sort algorithm
      • newO1Equal

        protected abstract T newO1Equal()
        Abstract factory callback method that have to be overwritten for create the other object to compare in the scenario that the objects are equal.
        Returns:
        the new created object to compare
      • newO1GreaterThan

        protected abstract T newO1GreaterThan()
        Abstract factory callback method that have to be overwritten for create the first comparison object in the scenario greater than.
        Returns:
        the new created first comparison object
      • newO1LessThan

        protected abstract T newO1LessThan()
        Abstract factory callback method that have to be overwritten for create the first comparison object in the scenario less than.
        Returns:
        the new created first comparison object
      • newO2Equal

        protected T newO2Equal()
        Factory callback method that can be overwritten for create the other object to compare in the scenario that the objects are equal.
        Returns:
        the new created object to compare
      • newO2GreaterThan

        protected abstract T newO2GreaterThan()
        Abstract factory callback method that have to be overwritten for create the other object to compare in the scenario greater than.
        Returns:
        the new created object to compare
      • newO2LessThan

        protected abstract T newO2LessThan()
        Abstract factory callback method that have to be overwritten for create the other object to compare in the scenario less than.
        Returns:
        the new created object to compare
      • setUp

        public void setUp()
        Sets up method will be invoked before every unit test method
        Overrides:
        setUp in class AbstractTestCase<java.lang.Integer,​java.lang.Boolean>
      • tearDown

        public void tearDown()
        Tear down method will be invoked after every unit test method

        Note: call super.tearDown() if you overwrite it for set actual and expected to null
        Overrides:
        tearDown in class AbstractTestCase<java.lang.Integer,​java.lang.Boolean>
      • testCompare

        public void testCompare()
        Test method for Comparator.compare(Object, Object)
      • testEqual

        public void testEqual()
        Test scenario when comparison objects are equal.
      • assertTrue

        protected abstract void assertTrue​(java.lang.Boolean expected)
        Abstract method that have to be implemented from derived classes with the specific unit framework
        Parameters:
        expected - the expected boolean value
      • assertEquals

        protected abstract void assertEquals​(T expected,
                                             T actual)
        Abstract method that have to be implemented from derived classes with the specific unit framework
        Parameters:
        expected - the expected value
        actual - the actual value
      • testGreaterThan

        public void testGreaterThan()
        Test scenario when a comparison object is greater than the other object to compare.
      • testLessThan

        public void testLessThan()
        Test scenario when a comparison object is less than the other object to compare.