Skip to content

Commit

Permalink
Add tests for effectiveEnd/StartDate
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jan 10, 2024
1 parent bfd802b commit 09e5090
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.google.transit.realtime.GtfsRealtime.TranslatedString.Translation;
import com.google.transit.realtime.GtfsRealtime.TripDescriptor;
import java.time.Instant;
import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map.Entry;
Expand All @@ -33,6 +34,8 @@ public class AlertsUpdateHandlerTest {

private final TransitAlertService service = new TransitAlertServiceImpl(new TransitModel());

Instant INSTANT = OffsetDateTime.parse("2024-01-10T17:31:00+01:00").toInstant();

@BeforeEach
void setUp() {
handler = new AlertsUpdateHandler();
Expand Down Expand Up @@ -525,6 +528,21 @@ void testRouteTypeAndAgencySelector() {
assertEquals(1l, RouteTypeAndAgencySelectorCount);
}

@Test
void testNoEndDate() {
var alert = Alert
.newBuilder()
.addInformedEntity(
GtfsRealtime.EntitySelector.newBuilder().setRouteType(1).setAgencyId("1").build()
)
.addActivePeriod(GtfsRealtime.TimeRange.newBuilder().setStart(INSTANT.getEpochSecond()).build())
.build();
var transitAlert = processOneAlert(alert);
assertNull(transitAlert.getEffectiveEndDate());
// not sure what deducts 5 seconds
assertEquals(INSTANT.minusSeconds(5), transitAlert.getEffectiveStartDate());
}

private TransitAlert processOneAlert(Alert alert) {
GtfsRealtime.FeedMessage message = GtfsRealtime.FeedMessage
.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"alertDescriptionText" : "",
"alertUrl" : null,
"alertDescriptionTextTranslations" : [ ],
"alertHeaderTextTranslations" : [ ]
"alertHeaderTextTranslations" : [ ],
"effectiveStartDate" : null,
"effectiveEndDate" : null
},
{
"id" : "QWxlcnQ6Rjpuby1oZWFkZXI",
Expand All @@ -28,15 +30,19 @@
"text" : "Etkö ole varma, mitä tämä tarkoittaa"
}
],
"alertHeaderTextTranslations" : [ ]
"alertHeaderTextTranslations" : [ ],
"effectiveStartDate" : null,
"effectiveEndDate" : null
},
{
"id" : "QWxlcnQ6Rjphbi1hbGVydA",
"alertHeaderText" : "A header",
"alertDescriptionText" : "A description",
"alertUrl" : "https://example.com",
"alertDescriptionTextTranslations" : [ ],
"alertHeaderTextTranslations" : [ ]
"alertHeaderTextTranslations" : [ ],
"effectiveStartDate" : 1676459008,
"effectiveEndDate" : 1676545408
},
{
"id" : "QWxlcnQ6Rjpuby1kZXNjcmlwdGlvbg",
Expand All @@ -57,7 +63,9 @@
"text" : "Minulla ei ole aavistustakaan kuinka puhua suomea",
"language" : "fi"
}
]
],
"effectiveStartDate" : null,
"effectiveEndDate" : null
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
text
language
}
effectiveStartDate
effectiveEndDate
}
}

0 comments on commit 09e5090

Please sign in to comment.