Skip to content

Commit

Permalink
test(TripMonitorNotification): Add test file for sort order.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Nov 29, 2023
1 parent d3e9b9f commit 7264908
Showing 1 changed file with 34 additions and 0 deletions.
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));
}
}
}

0 comments on commit 7264908

Please sign in to comment.