- Type Parameters:
T- the generic type of the objects to compare
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
FieldsModifier and TypeFieldDescriptionprotected Comparator<T>The comparator.protected TThe first comparison object.protected TThe other object to compare.Fields inherited from class io.github.astrapi69.AbstractTestCase
actual, expected -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidassertEquals(T expected, T actual) Abstract method that have to be implemented from derived classes with the specific unit frameworkprotected abstract voidassertTrue(Boolean expected) Abstract method that have to be implemented from derived classes with the specific unit frameworkAbstract factory callback method that have to be overwritten for create theListwith objects to sort in the sort scenario.protected abstract Comparator<T>Abstract factory callback method that have to be overwritten for create the specific comparator objectAbstract factory callback method that have to be overwritten for create the expectedListwith objects to test the sort algorithm in the sort scenario.Abstract factory callback method that have to be overwritten for create theListwith objects to sort in the sort scenario.protected abstract TAbstract 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 TAbstract factory callback method that have to be overwritten for create the first comparison object in the scenario greater than.protected abstract TAbstract factory callback method that have to be overwritten for create the first comparison object in the scenario less than.protected TFactory callback method that can be overwritten for create the other object to compare in the scenario that the objects are equal.protected abstract TAbstract factory callback method that have to be overwritten for create the other object to compare in the scenario greater than.protected abstract TAbstract factory callback method that have to be overwritten for create the other object to compare in the scenario less than.voidsetUp()Sets up method will be invoked before every unit test methodvoidtearDown()Tear down method will be invoked after every unit test method
Note: callsuper.tearDown()if you overwrite it for set actual and expected to nullvoidTest method forComparator.compare(Object, Object)voidTest scenario when comparison objects are equal.voidTest scenario when a comparison object is greater than the other object to compare.voidTest scenario when a comparison object is less than the other object to compare.
-
Field Details
-
comparator
The comparator. -
o1
The first comparison object. -
o2
The other object to compare.
-
-
Constructor Details
-
BaseComparatorTestCase
public BaseComparatorTestCase()
-
-
Method Details
-
newActualList
Abstract factory callback method that have to be overwritten for create theListwith objects to sort in the sort scenario.- Returns:
- the
Listwith objects to test the sort algorithm
-
newComparator
Abstract factory callback method that have to be overwritten for create the specific comparator object- Returns:
- the specific comparator
-
newExpectedSortedList
Abstract factory callback method that have to be overwritten for create the expectedListwith objects to test the sort algorithm in the sort scenario.- Returns:
- the
Listwith objects to test the sort algorithm
-
newExpectedUnsortedList
Abstract factory callback method that have to be overwritten for create theListwith objects to sort in the sort scenario.
Note:This list have to be equal withnewActualList()- Returns:
- the
Listwith objects to test the sort algorithm
-
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
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
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
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
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
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:
setUpin classAbstractTestCase<Integer,Boolean>
-
tearDown
public void tearDown()Tear down method will be invoked after every unit test method
Note: callsuper.tearDown()if you overwrite it for set actual and expected to null- Overrides:
tearDownin classAbstractTestCase<Integer,Boolean>
-
testCompare
public void testCompare()Test method forComparator.compare(Object, Object) -
testEqual
public void testEqual()Test scenario when comparison objects are equal. -
assertTrue
Abstract method that have to be implemented from derived classes with the specific unit framework- Parameters:
expected- the expected boolean value
-
assertEquals
Abstract method that have to be implemented from derived classes with the specific unit framework- Parameters:
expected- the expected valueactual- 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.
-