Add tests for frequency-based trips#1551
Conversation
aaronbrethorst
left a comment
There was a problem hiding this comment.
Hi Igor & Sviatoslav,
Thanks for picking up issue #430 — frequency-based trips have been a coverage gap for a long time and the USF Bull Runner data is a great fit for it. The new Frequency Jackson deserialization tests in ObaArrivalInfoTest.java are nicely scoped, the URI map wiring is correct, and reusing the existing HART_3105 fixture for the negative case (rather than adding another one) is the right instinct.
That said, I'd like a few changes before merging. The headline issue is that the PR closes #430 in letter but not in spirit: none of the new tests exercise the production code that actually renders frequency-based arrivals to the user. There's also one test I'd ask you to delete outright.
Request Changes
Critical Issues (1 found)
testFrequencyHeadwayAsMinutesis tautological — please delete it. [ArrivalInfoRequestTest.java:763-780] The test re-fetches the same fixture astestFrequencyBasedTrips, then re-implements(int) (freq.getHeadway() / 60)inline in the test body and asserts the result equals10. The fixture setsheadwayto600, so this is reallyassertEquals(10, 600 / 60)— Java math, not a behavior test. IfArrivalInfo.java:155were changed tomorrow toheadway / 30, this test would still pass. It also doesn't add coverage thattestFrequencyBasedTripsdoesn't already give us viaassertEquals(600, arrival0.getFrequency().getHeadway())at line 742. Either remove it, or replace it with a test that calls the actual production code path (see next item).
Important Issues (2 found)
-
No test covers the production rendering of frequency arrivals. The whole reason #430 was filed is that the user-visible "Every N mins from HH:MM" / "Every N mins until HH:MM" output at
ArrivalInfo.java:152-171is unverified. As written, this PR proves we parse frequency JSON, but a regression that swapped the from/until labels, lost the seconds-to-minutes conversion, or short-circuited the whole branch would pass every test in this PR.UIUtilTest.javais the natural home — it already exercisesgetStatusText()for delay, on-time, and canceled cases. Please add at least one test there that asserts the rendered label for a frequency arrival using the USF fixture. -
Both branches of the
now < frequency.getStartTime()check should be covered. Once you're testinggetStatusText(), please cover bothstop_info_frequency_fromandstop_info_frequency_until— they're independent strings and either one could regress silently. The USF fixture'scurrentTimeof1456780082393falls betweenstartTimeandendTime, so it'll exercise the "until" branch naturally; a second case with anowbeforestartTimecovers "from".
Fit and Finish (3 found)
-
Redundant
setCustomApiUrl("api.pugetsound.onebusaway.org")calls. [ArrivalInfoRequestTest.java:717,:766]ObaTestCase.before()already sets this exact URL before every test (seeObaTestCase.java:58). The other tests in the file only callsetCustomApiUrlwhen they're overriding the default with a different region. Drop these two lines. The Tampa URL override at line 785 intestScheduleBasedTripHasNullFrequencyis legitimate — keep that one. -
Weak nearby-stops assertion. [
ArrivalInfoRequestTest.java:760]assertTrue(nearbyStops.size() > 0)doesn't pin much down when the fixture is deterministic. The USF fixture contains exactly one nearby stop (USF Bull Runner_204, "Research & Development"). Please tighten toassertEquals(1, nearbyStops.size())and check the ID, matching the precision of the other assertions in the same test. -
Add a length guard before indexing in
testScheduleBasedTripHasNullFrequency. [ArrivalInfoRequestTest.java:793-794] You assertarrivals != nulland then immediately indexarrivals[0]. If the array were empty, you'd getAIOOBEinstead of a clean failure message. EitherassertTrue(arrivals.length > 0)orassertEquals(1, arrivals.length)before indexing — consistent with the style intestFrequencyBasedTrips.
Strengths
- The three
testFrequency_*Jackson tests inObaArrivalInfoTest.java(present / null / missing) are clean, focused unit tests at the right level — they're the part of the PR I'd land as-is. testFrequencyBasedTripsproves the full request → response →Frequencychain end-to-end and asserts every field ofFrequency, which is the genuine new coverage.- The fixture is realistic two-route data lifted straight from the issue, and the
urimap.jsonentry follows the established pattern.
Recommended Action
- Delete
testFrequencyHeadwayAsMinutes. - Add at least one test of
ArrivalInfo.getStatusText()(inUIUtilTest.java) that exercises the frequency-based rendering path — ideally one each for the "from" and "until" branches. - Drop the two redundant
setCustomApiUrl(...)calls in the USF tests. - Tighten the
nearbyStopsassertion and add the array-length guard.
Happy to take another look once these are in — the bones of this PR are good, it just needs to reach the code path that actually matters to riders.
d944c2a to
b3f11cc
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a new JSON fixture and URI mapping plus unit/instrumentation/UI tests that validate frequency field deserialization, API responses for frequency vs schedule-based trips, and localized frequency status label rendering. ChangesFrequency-Based Trip Test Coverage
🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Add mock JSON response with USF Bull Runner frequency data and tests for parsing frequency fields (startTime, endTime, headway), for rendering the user-facing "Every N mins from/until" status label via ArrivalInfo.getStatusText() (both the "from" and "until" branches), and for verifying that schedule-based trips have null frequency. Fixes OneBusAway#430
b3f11cc to
eafb167
Compare
akimovpro
left a comment
There was a problem hiding this comment.
Thanks for the thorough review — really helpful framing on "letter vs. spirit" of #430. I've pushed an update addressing everything:
Critical
Deleted testFrequencyHeadwayAsMinutes — agreed it was tautological (assertEquals(10, 600 / 60)) and added no coverage over the field assertions already in testFrequencyBasedTrips.
Important
Added testFrequencyStatusLabels in UIUtilTest, which now exercises the actual rendering path via ArrivalInfo.getStatusText() on the USF fixture, not just JSON parsing.
Covered both branches of the now < frequency.getStartTime() check:
stop_info_frequency_until — using the fixture's currentTime (which falls inside the frequency window);
stop_info_frequency_from — using a now set before startTime.
The expected label is built with the same DateFormat.getTimeInstance(SHORT) + getString(...) that production uses, so the assertion stays locale/timezone-independent rather than hardcoding a clock string.
Fit and Finish
Dropped the two redundant setCustomApiUrl("api.pugetsound.onebusaway.org") calls in the USF tests (kept the Tampa override in the schedule-based test).
Tightened the nearby-stops assertion to assertEquals(1, nearbyStops.size()) plus an ID check on USF Bull Runner_204.
Added an assertTrue(arrivals.length > 0) guard before indexing in testScheduleBasedTripHasNullFrequency.
Summary
Add tests for frequency-based trips using USF Bull Runner data.
Fixes #430
Test plan
gradlew connectedObaGoogleDebugAndroidTest– all new and existing tests passAndroidStyle.xmlstyle template to your code in Android Studio.gradlew connectedObaGoogleDebugAndroidTestto make sure you didn't break anythingSummary by CodeRabbit