-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
3 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
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
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
81 changes: 81 additions & 0 deletions
81
...tity/src/test/java/net/savantly/nexus/audited/api/AuditedEntitySortedByDateDesc_test.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,81 @@ | ||
package net.savantly.nexus.audited.api; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class AuditedEntitySortedByDateDesc_test { | ||
|
||
@Test | ||
public void testCompare() { | ||
// given | ||
AuditedEntitySortedByDateDesc comparator = new AuditedEntitySortedByDateDesc(); | ||
AuditedEntity o1 = new MockAuditedEntity(); | ||
AuditedEntity o2 = new MockAuditedEntity(); | ||
o1.setCreatedDate(ZonedDateTime.now().minusDays(1)); | ||
o2.setCreatedDate(ZonedDateTime.now()); | ||
|
||
// when | ||
int result = comparator.compare(o1, o2); | ||
|
||
// then | ||
assertThat(result).isPositive(); | ||
|
||
} | ||
|
||
@Test | ||
public void testCompareWithNulls() { | ||
// given | ||
AuditedEntitySortedByDateDesc comparator = new AuditedEntitySortedByDateDesc(); | ||
AuditedEntity o1 = new MockAuditedEntity(); | ||
AuditedEntity o2 = new MockAuditedEntity(); | ||
o1.setCreatedDate(ZonedDateTime.now().minusDays(1)); | ||
o2.setCreatedDate(null); | ||
|
||
// when | ||
int result = comparator.compare(o1, o2); | ||
|
||
// then | ||
assertThat(result).isNegative(); | ||
|
||
} | ||
|
||
@Test | ||
public void testCompareWithNullsBoth() { | ||
// given | ||
AuditedEntitySortedByDateDesc comparator = new AuditedEntitySortedByDateDesc(); | ||
AuditedEntity o1 = new MockAuditedEntity(); | ||
AuditedEntity o2 = new MockAuditedEntity(); | ||
o1.setCreatedDate(null); | ||
o2.setCreatedDate(null); | ||
|
||
// when | ||
int result = comparator.compare(o1, o2); | ||
|
||
// then | ||
assertThat(result).isZero(); | ||
|
||
} | ||
|
||
@Test | ||
public void testCompareWithNullsFirst() { | ||
// given | ||
AuditedEntitySortedByDateDesc comparator = new AuditedEntitySortedByDateDesc(); | ||
AuditedEntity o1 = new MockAuditedEntity(); | ||
AuditedEntity o2 = new MockAuditedEntity(); | ||
o1.setCreatedDate(null); | ||
o2.setCreatedDate(ZonedDateTime.now().minusDays(1)); | ||
|
||
// when | ||
int result = comparator.compare(o1, o2); | ||
|
||
// then | ||
assertThat(result).isPositive(); | ||
|
||
} | ||
|
||
static class MockAuditedEntity extends AuditedEntity { | ||
} | ||
} |