-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(TripMonitorNotification): Add test file for sort order.
- Loading branch information
1 parent
d3e9b9f
commit 7264908
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/test/java/org/opentripplanner/middleware/models/TripMonitorNotificationTest.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,34 @@ | ||
package org.opentripplanner.middleware.models; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner.middleware.tripmonitor.jobs.NotificationType; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
class TripMonitorNotificationTest { | ||
@Test | ||
void testSortOrderPutsInitialReminderFirst() { | ||
TripMonitorNotification reminder = new TripMonitorNotification(NotificationType.INITIAL_REMINDER, "reminder"); | ||
Set<TripMonitorNotification> notifications = Set.of( | ||
new TripMonitorNotification(NotificationType.ALERT_FOUND, "alert"), | ||
new TripMonitorNotification(NotificationType.DEPARTURE_DELAY, "departure delay"), | ||
reminder, | ||
new TripMonitorNotification(NotificationType.ARRIVAL_DELAY, "arrival delay") | ||
); | ||
|
||
List<TripMonitorNotification> sortedNotifications = notifications.stream() | ||
.sorted(Comparator.comparingInt(TripMonitorNotification::sortOrder)) | ||
.collect(Collectors.toList()); | ||
|
||
assertEquals(reminder, sortedNotifications.get(0)); | ||
for (int i = 1; i < sortedNotifications.size(); i++) { | ||
assertNotEquals(reminder, sortedNotifications.get(i)); | ||
} | ||
} | ||
} |