Polish contribution

See gh-31808
This commit is contained in:
Sam Brannen 2023-12-11 13:42:03 +01:00
parent a01384068a
commit 7432a96b48
2 changed files with 34 additions and 14 deletions

View File

@ -21,31 +21,44 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link Comparators}
* Tests for {@link Comparators}.
*
* @since 6.1.2
* @author Mathieu Amblard
* @author Sam Brannen
*/
class ComparatorsTest {
class ComparatorsTests {
@Test
void shouldCompareWithNullsLow() {
assertThat(Comparators.nullsLow().compare(null, "boo")).isNegative();
void nullsLow() {
assertThat(Comparators.nullsLow().compare("boo", "boo")).isZero();
assertThat(Comparators.nullsLow().compare(null, null)).isZero();
assertThat(Comparators.nullsLow().compare(null, "boo")).isNegative();
assertThat(Comparators.nullsLow().compare("boo", null)).isPositive();
}
@Test
void shouldCompareWithNullsLowAndComparator() {
assertThat(Comparators.nullsLow(String::compareTo).compare(null, "boo")).isNegative();
void nullsLowWithExplicitComparator() {
assertThat(Comparators.nullsLow(String::compareTo).compare("boo", "boo")).isZero();
assertThat(Comparators.nullsLow(String::compareTo).compare(null, null)).isZero();
assertThat(Comparators.nullsLow(String::compareTo).compare(null, "boo")).isNegative();
assertThat(Comparators.nullsLow(String::compareTo).compare("boo", null)).isPositive();
}
@Test
void shouldCompareWithNullsHigh() {
assertThat(Comparators.nullsHigh().compare(null, "boo")).isPositive();
void nullsHigh() {
assertThat(Comparators.nullsHigh().compare("boo", "boo")).isZero();
assertThat(Comparators.nullsHigh().compare(null, null)).isZero();
assertThat(Comparators.nullsHigh().compare(null, "boo")).isPositive();
assertThat(Comparators.nullsHigh().compare("boo", null)).isNegative();
}
@Test
void shouldCompareWithNullsHighAndComparator() {
assertThat(Comparators.nullsHigh(String::compareTo).compare(null, "boo")).isPositive();
void nullsHighWithExplicitComparator() {
assertThat(Comparators.nullsHigh(String::compareTo).compare("boo", "boo")).isZero();
assertThat(Comparators.nullsHigh(String::compareTo).compare(null, null)).isZero();
assertThat(Comparators.nullsHigh(String::compareTo).compare(null, "boo")).isPositive();
assertThat(Comparators.nullsHigh(String::compareTo).compare("boo", null)).isNegative();
}
}
}

View File

@ -36,7 +36,11 @@ class NullSafeComparatorTests {
void shouldCompareWithNullsLow() {
@SuppressWarnings("deprecation")
Comparator<String> c = NullSafeComparator.NULLS_LOW;
assertThat(c.compare(null, "boo")).isLessThan(0);
assertThat(c.compare("boo", "boo")).isZero();
assertThat(c.compare(null, null)).isZero();
assertThat(c.compare(null, "boo")).isNegative();
assertThat(c.compare("boo", null)).isPositive();
}
@Test
@ -44,8 +48,11 @@ class NullSafeComparatorTests {
void shouldCompareWithNullsHigh() {
@SuppressWarnings("deprecation")
Comparator<String> c = NullSafeComparator.NULLS_HIGH;
assertThat(c.compare(null, "boo")).isGreaterThan(0);
assertThat(c.compare(null, null)).isEqualTo(0);
assertThat(c.compare("boo", "boo")).isZero();
assertThat(c.compare(null, null)).isZero();
assertThat(c.compare(null, "boo")).isPositive();
assertThat(c.compare("boo", null)).isNegative();
}
}