BAEL-7108: Comparing Arrays Using compare() Method in Java (#14975)
This commit is contained in:
parent
4b29870418
commit
de7dadabef
|
@ -58,4 +58,8 @@
|
|||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.release>11</maven.compiler.release>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,29 @@
|
|||
package com.baeldung.arraycompare;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ArraysCompareUnitTest {
|
||||
|
||||
@Test
|
||||
void givenSameContents_whenCompare_thenCorrect() {
|
||||
String[] array1 = new String[] { "A", "B", "C" };
|
||||
String[] array2 = new String[] { "A", "B", "C" };
|
||||
|
||||
assertThat(Arrays.compare(array1, array2)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenDifferentContents_whenCompare_thenDifferent() {
|
||||
String[] array1 = new String[] { "A", "B", "C" };
|
||||
String[] array2 = new String[] { "A", "C", "B", "D" };
|
||||
|
||||
assertThat(Arrays.compare(array1, array2)).isLessThan(0);
|
||||
assertThat(Arrays.compare(array2, array1)).isGreaterThan(0);
|
||||
assertThat(Arrays.compare(array1, null)).isGreaterThan(0);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue