-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
eleonov
authored and
eleonov
committed
Dec 4, 2023
1 parent
a4b8fcc
commit 8cfddfc
Showing
3 changed files
with
168 additions
and
27 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
src/test/java/software/leonov/common/util/function/NaturalOrderingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package software.leonov.common.util.function; | ||
|
||
import static com.google.common.collect.Lists.newArrayList; | ||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static software.leonov.common.util.function.CheckedComparator.evalUnchecked; | ||
import static software.leonov.common.util.function.CheckedComparator.naturalOrder; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class NaturalOrderingTest { | ||
|
||
@BeforeAll | ||
static void setUpBeforeClass() throws Exception { | ||
} | ||
|
||
@AfterAll | ||
static void tearDownAfterClass() throws Exception { | ||
} | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
} | ||
|
||
@AfterEach | ||
void tearDown() throws Exception { | ||
} | ||
|
||
@Test | ||
void test_naturalOrder_strings() throws Exception { | ||
final List<String> actual = newArrayList("b", "a", "d", "c"); | ||
|
||
actual.sort(evalUnchecked(naturalOrder())); | ||
|
||
assertThat(actual).isEqualTo(newArrayList("a", "b", "c", "d")); | ||
} | ||
|
||
@Test | ||
void test_naturalOrder_strings_reversed() throws Exception { | ||
final List<String> actual = newArrayList("b", "a", "d", "c"); | ||
|
||
actual.sort(evalUnchecked(CheckedComparator.<String>naturalOrder().reversed())); | ||
|
||
assertThat(actual).isEqualTo(newArrayList("d", "c", "b", "a")); | ||
} | ||
|
||
@Test | ||
void test_naturalOrder_ints() throws Exception { | ||
final List<Integer> actual = newArrayList(3, 7, 25, -6, 8, 5); | ||
|
||
actual.sort(evalUnchecked(naturalOrder())); | ||
|
||
assertThat(actual).isEqualTo(newArrayList(-6, 3, 5, 7, 8, 25)); | ||
} | ||
|
||
@Test | ||
void test_naturalOrder_ints_reversed() throws Exception { | ||
final List<Integer> actual = newArrayList(3, 7, 25, -6, 8, 5); | ||
|
||
actual.sort(evalUnchecked(CheckedComparator.<Integer>naturalOrder().reversed())); | ||
|
||
assertThat(actual).isEqualTo(newArrayList(25, 8, 7, 5, 3, -6)); | ||
} | ||
|
||
@Test | ||
void test_naturalOrder_ints_npe() throws Exception { | ||
final List<Integer> actual = newArrayList(3, 7, 25, null, -6, 8, 5); | ||
|
||
assertThrows(NullPointerException.class, () -> actual.sort(evalUnchecked(naturalOrder()))); | ||
} | ||
|
||
} |
90 changes: 90 additions & 0 deletions
90
src/test/java/software/leonov/common/util/function/NullsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package software.leonov.common.util.function; | ||
|
||
import static com.google.common.collect.Lists.newArrayList; | ||
import static com.google.common.truth.Truth.assertThat; | ||
import static software.leonov.common.util.function.CheckedComparator.evalUnchecked; | ||
import static software.leonov.common.util.function.CheckedComparator.naturalOrder; | ||
import static software.leonov.common.util.function.CheckedComparator.nullsFirst; | ||
import static software.leonov.common.util.function.CheckedComparator.nullsLast; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class NullsTest { | ||
|
||
@BeforeAll | ||
static void setUpBeforeClass() throws Exception { | ||
} | ||
|
||
@AfterAll | ||
static void tearDownAfterClass() throws Exception { | ||
} | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
} | ||
|
||
@AfterEach | ||
void tearDown() throws Exception { | ||
} | ||
|
||
@Test | ||
void test_nullsFirst_naturalOrder() throws Exception { | ||
final List<String> actual = newArrayList("b", "a", null, "d", "c", null); | ||
|
||
actual.sort(evalUnchecked(nullsFirst(naturalOrder()))); | ||
|
||
assertThat(actual).isEqualTo(newArrayList(null, null, "a", "b", "c", "d")); | ||
} | ||
|
||
@Test | ||
void test_nullsFirst_naturalOrder_reversed() throws Exception { | ||
final List<String> actual = newArrayList("b", "a", null, "d", "c", null); | ||
|
||
actual.sort(evalUnchecked(nullsFirst(CheckedComparator.<String>naturalOrder()).reversed())); | ||
|
||
assertThat(actual).isEqualTo(newArrayList("d", "c", "b", "a", null, null)); | ||
} | ||
|
||
@Test | ||
void test_nullsLast_naturalOrder() throws Exception { | ||
final List<String> actual = newArrayList("b", "a", null, "d", "c", null); | ||
|
||
actual.sort(evalUnchecked(nullsLast(naturalOrder()))); | ||
|
||
assertThat(actual).isEqualTo(newArrayList("a", "b", "c", "d", null, null)); | ||
} | ||
|
||
@Test | ||
void test_nullsLast_naturalOrder_reversed() throws Exception { | ||
final List<String> actual = newArrayList("b", "a", null, "d", "c", null); | ||
|
||
actual.sort(evalUnchecked(nullsLast(CheckedComparator.<String>naturalOrder()).reversed())); | ||
|
||
assertThat(actual).isEqualTo(newArrayList(null, null, "d", "c", "b", "a")); | ||
} | ||
|
||
@Test | ||
void test_nullsFirst_null() throws Exception { | ||
final List<String> actual = newArrayList("b", "a", null, "d", "c", null); | ||
|
||
actual.sort(evalUnchecked(nullsFirst(null))); | ||
|
||
assertThat(actual).isEqualTo(newArrayList(null, null, "b", "a", "d", "c")); | ||
} | ||
|
||
@Test | ||
void test_nullsFirst_last() throws Exception { | ||
final List<String> actual = newArrayList("b", "a", null, "d", "c", null); | ||
|
||
actual.sort(evalUnchecked(nullsLast(null))); | ||
|
||
assertThat(actual).isEqualTo(newArrayList("b", "a", "d", "c", null, null)); | ||
} | ||
|
||
} |
27 changes: 0 additions & 27 deletions
27
src/test/java/software/leonov/common/util/function/Test.java
This file was deleted.
Oops, something went wrong.