-
public class EqualsContractTests Reflexive, Symmetric, Transitive, Consistent, and non-nullity properties of the equals()contract. If you think this is confusing, realize that there is no way to implement aone-sided equals() correctly with inheritance - it's a broken concept, but it's still used sooften that you have to do your best with it.I got the idea of contract-based testing from watching Bill Venners:https://www.youtube.com/watch?v=bCTZQi2dpl8
-
-
Method Summary
Modifier and Type Method Description static <T> voidpermutations(List<T> items, BiFunction<Out Object, Out Object, Out Object> f)Apply the given function against all unique pairings of items in the list. static <S, T1 extends S, T2 extends S, T3 extends S, T4 extends S> voidequalsHashCode(T1 equiv1, T2 equiv2, T3 equiv3, T4 different, boolean requireDistinctHashes)Tests Reflexive, Symmetric, Transitive, Consistent, and non-nullity properties of the equals()contract. static <S, T1 extends S, T2 extends S, T3 extends S, T4 extends S> voidequalsSameHashCode(T1 equiv1, T2 equiv2, T3 equiv3, T4 different)Tests Reflexive, Symmetric, Transitive, Consistent, and non-nullity properties of the equals()contract. static <S, T1 extends S, T2 extends S, T3 extends S, T4 extends S> voidequalsDistinctHashCode(T1 equiv1, T2 equiv2, T3 equiv3, T4 different)Tests Reflexive, Symmetric, Transitive, Consistent, and non-nullity properties of the equals()contract. -
-
Method Detail
-
permutations
static <T> void permutations(List<T> items, BiFunction<Out Object, Out Object, Out Object> f)
Apply the given function against all unique pairings of items in the list.
-
equalsHashCode
static <S, T1 extends S, T2 extends S, T3 extends S, T4 extends S> void equalsHashCode(T1 equiv1, T2 equiv2, T3 equiv3, T4 different, boolean requireDistinctHashes)
Tests Reflexive, Symmetric, Transitive, Consistent, and non-nullity properties of the equals()contract.- Parameters:
equiv1- First equivalent (but unique) objectequiv2- Second equivalent (but unique) object (could be a different class)equiv3- Third equivalent (but unique) object (could be a different class)different- Non-equivalent object with a (maybe) different hashCode (should be an otherwise compatible class)requireDistinctHashes- if true, require that the fourth object have a different hashCode.
-
equalsSameHashCode
static <S, T1 extends S, T2 extends S, T3 extends S, T4 extends S> void equalsSameHashCode(T1 equiv1, T2 equiv2, T3 equiv3, T4 different)
Tests Reflexive, Symmetric, Transitive, Consistent, and non-nullity properties of the equals()contract.- Parameters:
equiv1- First equivalent (but unique) objectequiv2- Second equivalent (but unique) object (could be a different class)equiv3- Third equivalent (but unique) object (could be a different class)different- Non-equivalent object with the same hashCode as the previous three
-
equalsDistinctHashCode
static <S, T1 extends S, T2 extends S, T3 extends S, T4 extends S> void equalsDistinctHashCode(T1 equiv1, T2 equiv2, T3 equiv3, T4 different)
Tests Reflexive, Symmetric, Transitive, Consistent, and non-nullity properties of the equals()contract.- Parameters:
equiv1- First equivalent (but unique) objectequiv2- Second equivalent (but unique) object (could be a different class)equiv3- Third equivalent (but unique) object (could be a different class)different- Non-equivalent object with a different hashCode (should be an otherwise compatible class)
-
-
-
-