@ -30,6 +30,7 @@ import java.nio.file.Path;
import java.sql.SQLException ;
import java.sql.SQLException ;
import java.time.LocalDate ;
import java.time.LocalDate ;
import java.time.ZoneId ;
import java.time.ZoneId ;
import java.util.Arrays ;
import java.util.Collections ;
import java.util.Collections ;
import java.util.Currency ;
import java.util.Currency ;
import java.util.Date ;
import java.util.Date ;
@ -38,6 +39,7 @@ import java.util.HashSet;
import java.util.List ;
import java.util.List ;
import java.util.Locale ;
import java.util.Locale ;
import java.util.Map ;
import java.util.Map ;
import java.util.Objects ;
import java.util.Optional ;
import java.util.Optional ;
import java.util.Set ;
import java.util.Set ;
import java.util.TimeZone ;
import java.util.TimeZone ;
@ -379,193 +381,221 @@ class ObjectUtilsTests {
}
}
@Test
@Test
void nullSafeHashCodeWithBooleanArray ( ) {
void nullSafeHashWithNull ( ) {
int expected = 31 * 7 + Boolean . TRUE . hashCode ( ) ;
assertThat ( ObjectUtils . nullSafeHash ( ( Object [ ] ) null ) ) . isEqualTo ( 0 ) ;
expected = 31 * expected + Boolean . FALSE . hashCode ( ) ;
}
@Test
void nullSafeHashWithIntermediateNullElements ( ) {
assertThat ( ObjectUtils . nullSafeHash ( 3 , null , 5 ) ) . isEqualTo ( Objects . hash ( 3 , null , 5 ) ) ;
}
@Test
@Deprecated
void nullSafeHashCodeWithNullBooleanArray ( ) {
boolean [ ] array = null ;
assertThat ( ObjectUtils . nullSafeHashCode ( array ) ) . isEqualTo ( 0 ) ;
}
@Test
@Deprecated
void nullSafeHashCodeWithBooleanArray ( ) {
boolean [ ] array = { true , false } ;
boolean [ ] array = { true , false } ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( Arrays . hashCode ( array ) ) ;
}
assertThat ( actual ) . isEqualTo ( expected ) ;
@Test
@Deprecated
void nullSafeHashCodeWithObjectBeingBooleanArray ( ) {
Object array = new boolean [ ] { true , false } ;
int expected = ObjectUtils . nullSafeHashCode ( ( boolean [ ] ) array ) ;
assertEqualHashCodes ( expected , array ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithBooleanArrayEqualToNull ( ) {
@Deprecated
assertThat ( ObjectUtils . nullSafeHashCode ( ( boolean [ ] ) null ) ) . isEqualTo ( 0 ) ;
void nullSafeHashCodeWithNullByteArray ( ) {
byte [ ] array = null ;
assertThat ( ObjectUtils . nullSafeHashCode ( array ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test
@Deprecated
void nullSafeHashCodeWithByteArray ( ) {
void nullSafeHashCodeWithByteArray ( ) {
int expected = 31 * 7 + 8 ;
expected = 31 * expected + 10 ;
byte [ ] array = { 8 , 10 } ;
byte [ ] array = { 8 , 10 } ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( Arrays . hashCode ( array ) ) ;
}
assertThat ( actual ) . isEqualTo ( expected ) ;
@Test
@Deprecated
void nullSafeHashCodeWithObjectBeingByteArray ( ) {
Object array = new byte [ ] { 6 , 39 } ;
int expected = ObjectUtils . nullSafeHashCode ( ( byte [ ] ) array ) ;
assertEqualHashCodes ( expected , array ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithByteArrayEqualToNull ( ) {
@Deprecated
assertThat ( ObjectUtils . nullSafeHashCode ( ( byte [ ] ) null ) ) . isEqualTo ( 0 ) ;
void nullSafeHashCodeWithNullCharArray ( ) {
char [ ] array = null ;
assertThat ( ObjectUtils . nullSafeHashCode ( array ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test
@Deprecated
void nullSafeHashCodeWithCharArray ( ) {
void nullSafeHashCodeWithCharArray ( ) {
int expected = 31 * 7 + 'a' ;
expected = 31 * expected + 'E' ;
char [ ] array = { 'a' , 'E' } ;
char [ ] array = { 'a' , 'E' } ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( Arrays . hashCode ( array ) ) ;
}
assertThat ( actual ) . isEqualTo ( expected ) ;
@Test
@Deprecated
void nullSafeHashCodeWithObjectBeingCharArray ( ) {
Object array = new char [ ] { 'l' , 'M' } ;
int expected = ObjectUtils . nullSafeHashCode ( ( char [ ] ) array ) ;
assertEqualHashCodes ( expected , array ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithCharArrayEqualToNull ( ) {
@Deprecated
assertThat ( ObjectUtils . nullSafeHashCode ( ( char [ ] ) null ) ) . isEqualTo ( 0 ) ;
void nullSafeHashCodeWithNullDoubleArray ( ) {
double [ ] array = null ;
assertThat ( ObjectUtils . nullSafeHashCode ( array ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test
@Deprecated
void nullSafeHashCodeWithDoubleArray ( ) {
void nullSafeHashCodeWithDoubleArray ( ) {
long bits = Double . doubleToLongBits ( 8449 . 65 ) ;
int expected = 31 * 7 + ( int ) ( bits ^ ( bits > > > 32 ) ) ;
bits = Double . doubleToLongBits ( 9944 . 923 ) ;
expected = 31 * expected + ( int ) ( bits ^ ( bits > > > 32 ) ) ;
double [ ] array = { 8449 . 65 , 9944 . 923 } ;
double [ ] array = { 8449 . 65 , 9944 . 923 } ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( Arrays . hashCode ( array ) ) ;
}
assertThat ( actual ) . isEqualTo ( expected ) ;
@Test
@Deprecated
void nullSafeHashCodeWithObjectBeingDoubleArray ( ) {
Object array = new double [ ] { 68930 . 993 , 9022 . 009 } ;
int expected = ObjectUtils . nullSafeHashCode ( ( double [ ] ) array ) ;
assertEqualHashCodes ( expected , array ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithDoubleArrayEqualToNull ( ) {
@Deprecated
assertThat ( ObjectUtils . nullSafeHashCode ( ( double [ ] ) null ) ) . isEqualTo ( 0 ) ;
void nullSafeHashCodeWithNullFloatArray ( ) {
float [ ] array = null ;
assertThat ( ObjectUtils . nullSafeHashCode ( array ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test
@Deprecated
void nullSafeHashCodeWithFloatArray ( ) {
void nullSafeHashCodeWithFloatArray ( ) {
int expected = 31 * 7 + Float . floatToIntBits ( 9 . 6f ) ;
expected = 31 * expected + Float . floatToIntBits ( 7 . 4f ) ;
float [ ] array = { 9 . 6f , 7 . 4f } ;
float [ ] array = { 9 . 6f , 7 . 4f } ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( Arrays . hashCode ( array ) ) ;
assertThat ( actual ) . isEqualTo ( expected ) ;
}
@Test
void nullSafeHashCodeWithFloatArrayEqualToNull ( ) {
assertThat ( ObjectUtils . nullSafeHashCode ( ( float [ ] ) null ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithIntArray ( ) {
@Deprecated
int expected = 31 * 7 + 884 ;
void nullSafeHashCodeWithObjectBeingFloatArray ( ) {
expected = 31 * expected + 340 ;
Object array = new float [ ] { 9 . 9f , 9 . 54f } ;
int expected = ObjectUtils . nullSafeHashCode ( ( float [ ] ) array ) ;
int [ ] array = { 884 , 340 } ;
assertEqualHashCodes ( expected , array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( expected ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithIntArrayEqualToNull ( ) {
@Deprecated
assertThat ( ObjectUtils . nullSafeHashCode ( ( int [ ] ) null ) ) . isEqualTo ( 0 ) ;
void nullSafeHashCodeWithNullIntArray ( ) {
int [ ] array = null ;
assertThat ( ObjectUtils . nullSafeHashCode ( array ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithLongArray ( ) {
@Deprecated
long lng = 7993L ;
void nullSafeHashCodeWithIntArray ( ) {
int expected = 31 * 7 + ( int ) ( lng ^ ( lng > > > 32 ) ) ;
int [ ] array = { 884 , 340 } ;
lng = 84320L ;
expected = 31 * expected + ( int ) ( lng ^ ( lng > > > 32 ) ) ;
long [ ] array = { 7993L , 84320L } ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( Arrays . hashCode ( array ) ) ;
assertThat ( actual ) . isEqualTo ( expected ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithLongArrayEqualToNull ( ) {
@Deprecated
assertThat ( ObjectUtils . nullSafeHashCode ( ( long [ ] ) null ) ) . isEqualTo ( 0 ) ;
void nullSafeHashCodeWithObjectBeingIntArray ( ) {
Object array = new int [ ] { 89 , 32 } ;
int expected = ObjectUtils . nullSafeHashCode ( ( int [ ] ) array ) ;
assertEqualHashCodes ( expected , array ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithObject ( ) {
@Deprecated
String str = "Luke" ;
void nullSafeHashCodeWithNullLongArray ( ) {
assertThat ( ObjectUtils . nullSafeHashCode ( str ) ) . isEqualTo ( str . hashCode ( ) ) ;
long [ ] array = null ;
assertThat ( ObjectUtils . nullSafeHashCode ( array ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithObjectArray ( ) {
@Deprecated
int expected = 31 * 7 + "Leia" . hashCode ( ) ;
void nullSafeHashCodeWithLongArray ( ) {
expected = 31 * expected + "Han" . hashCode ( ) ;
long [ ] array = { 7993L , 84320L } ;
Object [ ] array = { "Leia" , "Han" } ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( Arrays . hashCode ( array ) ) ;
assertThat ( actual ) . isEqualTo ( expected ) ;
}
@Test
void nullSafeHashCodeWithObjectArrayEqualToNull ( ) {
assertThat ( ObjectUtils . nullSafeHashCode ( ( Object [ ] ) null ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithObjectBeingBooleanArray ( ) {
@Deprecated
Object array = new boolean [ ] { true , false } ;
void nullSafeHashCodeWithObjectBeingLongArray ( ) {
int expected = ObjectUtils . nullSafeHashCode ( ( boolean [ ] ) array ) ;
Object array = new long [ ] { 4389 , 320 } ;
int expected = ObjectUtils . nullSafeHashCode ( ( long [ ] ) array ) ;
assertEqualHashCodes ( expected , array ) ;
assertEqualHashCodes ( expected , array ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithObjectBeingByteArray ( ) {
@Deprecated
Object array = new byte [ ] { 6 , 39 } ;
void nullSafeHashCodeWithNullShortArray ( ) {
int expected = ObjectUtils . nullSafeHashCode ( ( byte [ ] ) array ) ;
short [ ] array = null ;
assertEqualHashCodes ( expected , array ) ;
assertThat ( ObjectUtils . nullSafeHashCode ( array ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithObjectBeingCharArray ( ) {
@Deprecated
Object array = new char [ ] { 'l' , 'M' } ;
void nullSafeHashCodeWithShortArray ( ) {
int expected = ObjectUtils . nullSafeHashCode ( ( char [ ] ) array ) ;
short [ ] array = { 4 , 25 } ;
assertEqualHashCodes ( expected , array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( Arrays . hashCode ( array ) ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithObjectBeingDoubleArray ( ) {
@Deprecated
Object array = new double [ ] { 68930 . 993 , 9022 . 009 } ;
void nullSafeHashCodeWithObjectBeingShortArray ( ) {
int expected = ObjectUtils . nullSafeHashCode ( ( double [ ] ) array ) ;
Object array = new short [ ] { 5 , 3 } ;
int expected = ObjectUtils . nullSafeHashCode ( ( short [ ] ) array ) ;
assertEqualHashCodes ( expected , array ) ;
assertEqualHashCodes ( expected , array ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithObjectBeingFloatArray ( ) {
void nullSafeHashCodeWithObject ( ) {
Object array = new float [ ] { 9 . 9f , 9 . 54f } ;
String str = "Luke" ;
int expected = ObjectUtils . nullSafeHashCode ( ( float [ ] ) array ) ;
assertThat ( ObjectUtils . nullSafeHashCode ( str ) ) . isEqualTo ( str . hashCode ( ) ) ;
assertEqualHashCodes ( expected , array ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithObjectBeingIntArray ( ) {
@Deprecated
Object array = new int [ ] { 89 , 32 } ;
void nullSafeHashCodeWithObjectArray ( ) {
int expected = ObjectUtils . nullSafeHashCode ( ( int [ ] ) array ) ;
Object [ ] array = { "Leia" , "Han" } ;
assertEqualHashCodes ( expected , array ) ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( Arrays . hashCode ( array ) ) ;
}
}
@Test
@Test
void nullSafeHashCodeWithObjectBeingLongArray ( ) {
@Deprecated
Object array = new long [ ] { 4389 , 320 } ;
void nullSafeHashCodeWithObjectArrayEqualToNull ( ) {
int expected = ObjectUtils . nullSafeHashCode ( ( long [ ] ) array ) ;
assertThat ( ObjectUtils . nullSafeHashCode ( ( Object [ ] ) null ) ) . isEqualTo ( 0 ) ;
assertEqualHashCodes ( expected , array ) ;
}
}
@Test
@Test
@Deprecated
void nullSafeHashCodeWithObjectBeingObjectArray ( ) {
void nullSafeHashCodeWithObjectBeingObjectArray ( ) {
Object array = new Object [ ] { "Luke" , "Anakin" } ;
Object array = new Object [ ] { "Luke" , "Anakin" } ;
int expected = ObjectUtils . nullSafeHashCode ( ( Object [ ] ) array ) ;
int expected = ObjectUtils . nullSafeHashCode ( ( Object [ ] ) array ) ;
@ -573,31 +603,10 @@ class ObjectUtilsTests {
}
}
@Test
@Test
void nullSafeHashCodeWithObjectBeingShortArray ( ) {
@Deprecated
Object array = new short [ ] { 5 , 3 } ;
int expected = ObjectUtils . nullSafeHashCode ( ( short [ ] ) array ) ;
assertEqualHashCodes ( expected , array ) ;
}
@Test
void nullSafeHashCodeWithObjectEqualToNull ( ) {
void nullSafeHashCodeWithObjectEqualToNull ( ) {
assertThat ( ObjectUtils . nullSafeHashCode ( ( Object ) null ) ) . isEqualTo ( 0 ) ;
Object [ ] array = null ;
}
assertThat ( ObjectUtils . nullSafeHashCode ( array ) ) . isEqualTo ( 0 ) ;
@Test
void nullSafeHashCodeWithShortArray ( ) {
int expected = 31 * 7 + 70 ;
expected = 31 * expected + 8 ;
short [ ] array = { 70 , 8 } ;
int actual = ObjectUtils . nullSafeHashCode ( array ) ;
assertThat ( actual ) . isEqualTo ( expected ) ;
}
@Test
void nullSafeHashCodeWithShortArrayEqualToNull ( ) {
assertThat ( ObjectUtils . nullSafeHashCode ( ( short [ ] ) null ) ) . isEqualTo ( 0 ) ;
}
}
@Test
@Test