Skip to content

Commit d368ef3

Browse files
Address PR #2 review feedback
ArrivalDepartureGeneratorDefaultImplTest: replace vacuous stub re-assertions with verify()/verify(never()) interaction checks so the tests fail if the short-circuit guards are removed. FrequencyKalmanPredictionGeneratorImplTest: call getMaxPredictionsTimeSecs() through KalmanPredictionGeneratorImpl rather than PredictionGeneratorDefaultImpl so a future static override on any intermediate layer will break the test. SpatialMatchTest.atStop_layoverStopAlwaysCountsAsAtStop: move the match to the segment midpoint, outside both beforeStopDistance and afterStopDistance windows, so isAtStop can only be true via the layover flag.
1 parent 6af332a commit d368ef3

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

transitclock/src/test/java/org/transitclock/core/ArrivalDepartureGeneratorDefaultImplTest.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.mockito.Mockito.mock;
5+
import static org.mockito.Mockito.never;
6+
import static org.mockito.Mockito.verify;
57
import static org.mockito.Mockito.verifyNoInteractions;
68
import static org.mockito.Mockito.when;
79

@@ -22,11 +24,8 @@ public void generate_unpredictableVehicleIsANoOp() {
2224

2325
new ArrivalDepartureGeneratorDefaultImpl().generate(vs);
2426

25-
// The method returns early; nothing else on the mock should have been
26-
// touched. isPredictable() will show in interactions, so we just
27-
// re-assert the guard held by checking getMatch() was never consulted.
28-
// Using a looser check here since Mockito's strict mode isn't enabled.
29-
assertThat(vs.isPredictable()).isFalse();
27+
verify(vs).isPredictable();
28+
verify(vs, never()).getMatch();
3029
}
3130

3231
@Test
@@ -35,20 +34,25 @@ public void generate_nullMatchIsANoOp() {
3534
when(vs.isPredictable()).thenReturn(true);
3635
when(vs.getMatch()).thenReturn(null);
3736

38-
// Should not throw, should not reach any downstream processing.
3937
new ArrivalDepartureGeneratorDefaultImpl().generate(vs);
38+
39+
verify(vs).isPredictable();
40+
verify(vs).getMatch();
41+
verify(vs, never()).getPreviousMatch();
4042
}
4143

4244
@Test
4345
public void generate_doesNotTouchTrivialCollaboratorsWhenUnpredictable() {
4446
VehicleState vs = mock(VehicleState.class);
4547
when(vs.isPredictable()).thenReturn(false);
46-
SpatialMatch match = mock(SpatialMatch.class);
48+
TemporalMatch match = mock(TemporalMatch.class);
49+
when(vs.getMatch()).thenReturn(match);
4750

4851
new ArrivalDepartureGeneratorDefaultImpl().generate(vs);
4952

50-
// Since the method short-circuits, it should never have asked for a
51-
// match or a previous match.
53+
verify(vs).isPredictable();
54+
// Guard short-circuited before ever reading match off the state.
55+
verify(vs, never()).getMatch();
5256
verifyNoInteractions(match);
5357
}
5458
}

transitclock/src/test/java/org/transitclock/core/SpatialMatchTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,13 @@ public void atStop_inMiddleOfPathIsNotAtStop() {
152152
@Test
153153
public void atStop_layoverStopAlwaysCountsAsAtStop() {
154154
// Layover flag forces atStop regardless of how far from the stop we are.
155+
// Position the match at the midpoint of the segment — outside both
156+
// beforeStopDistance (50m from end) and afterStopDistance (50m from
157+
// start) — so the only thing that can drive isAtStop to true is the
158+
// layover flag itself.
155159
Block block = buildSimpleBlock(2, new boolean[] {true, false});
156-
SpatialMatch match = matchAt(block, 0, 5.0); // almost at the start
160+
VectorWithHeading seg = block.getStopPath(0, 0).getSegmentVector(0);
161+
SpatialMatch match = matchAt(block, 0, seg.length() / 2.0);
157162

158163
assertThat(match.isAtStop()).isTrue();
159164
assertThat(match.atEndOfPathStop()).isTrue();

transitclock/src/test/java/org/transitclock/core/predictiongenerator/frequency/traveltime/kalman/FrequencyKalmanPredictionGeneratorImplTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ public void classHierarchy_flowsThroughHistoricalAverageAndLastVehicleToDefault(
2626
@Test
2727
public void maxPredictionsTimeSecs_usesInheritedDefault() {
2828
// Not overridden in any of the intermediate layers, so the 45-min
29-
// default from PredictionGeneratorDefaultImpl still applies.
30-
assertThat(PredictionGeneratorDefaultImpl.getMaxPredictionsTimeSecs())
29+
// default from PredictionGeneratorDefaultImpl still applies. Assert
30+
// through the Kalman class so that if a future change adds a static
31+
// override on Kalman (or any intermediate layer), this test breaks
32+
// instead of silently continuing to read the base-class value.
33+
assertThat(KalmanPredictionGeneratorImpl.getMaxPredictionsTimeSecs())
3134
.isEqualTo(45 * 60);
3235
}
3336
}

0 commit comments

Comments
 (0)