Skip to content

Commit d8dca70

Browse files
Fix mapping of GroupOfRoutes
1 parent 7fd00b2 commit d8dca70

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

application/src/main/java/org/opentripplanner/gtfs/mapping/RouteMapper.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ private Route doMap(org.onebusaway.gtfs.model.Route rhs) {
8383
lhs.withTextColor(rhs.getTextColor());
8484
lhs.withBikesAllowed(BikeAccessMapper.mapForRoute(rhs));
8585
if (rhs.getNetworkId() != null) {
86-
var networkId = GroupOfRoutes.of(
87-
new FeedScopedId(rhs.getId().getAgencyId(), rhs.getNetworkId())
88-
).build();
86+
var networkId = GroupOfRoutes.of(idFactory.createId(rhs.getNetworkId())).build();
8987
lhs.getGroupsOfRoutes().add(networkId);
9088
}
9189

application/src/test/java/org/opentripplanner/gtfs/mapping/RouteMapperTest.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
1717
import org.opentripplanner.transit.model._data.TimetableRepositoryForTest;
1818
import org.opentripplanner.transit.model.basic.TransitMode;
19+
import org.opentripplanner.transit.model.framework.AbstractTransitEntity;
20+
import org.opentripplanner.transit.model.framework.FeedScopedId;
1921
import org.opentripplanner.transit.model.network.BikeAccess;
2022
import org.opentripplanner.transit.model.organization.Branding;
2123

22-
public class RouteMapperTest {
24+
class RouteMapperTest {
25+
26+
private static final String FEED_ID = "A";
2327

2428
private static final Agency AGENCY = new GtfsTestData().agency;
2529

26-
private static final AgencyAndId ROUTE_ID = new AgencyAndId("A", "1");
30+
private static final AgencyAndId ROUTE_ID = new AgencyAndId(FEED_ID, "1");
2731

2832
private static final String SHORT_NAME = "Short Name";
2933

@@ -48,7 +52,7 @@ public class RouteMapperTest {
4852
private static final Integer SORT_ORDER = 1;
4953

5054
private static final Route ROUTE = new Route();
51-
private static final IdFactory ID_FACTORY = new IdFactory("A");
55+
private static final IdFactory ID_FACTORY = new IdFactory(FEED_ID);
5256
private final RouteMapper subject = new RouteMapper(
5357
ID_FACTORY,
5458
new AgencyMapper(ID_FACTORY),
@@ -71,14 +75,14 @@ public class RouteMapperTest {
7175
}
7276

7377
@Test
74-
public void testMapCollection() throws Exception {
78+
void testMapCollection() throws Exception {
7579
assertNull(subject.map((Collection<Route>) null));
7680
assertTrue(subject.map(Collections.emptyList()).isEmpty());
7781
assertEquals(1, subject.map(Collections.singleton(ROUTE)).size());
7882
}
7983

8084
@Test
81-
public void testMap() throws Exception {
85+
void testMap() throws Exception {
8286
org.opentripplanner.transit.model.network.Route result = subject.map(ROUTE);
8387

8488
assertEquals("A:1", result.getId().toString());
@@ -100,7 +104,7 @@ public void testMap() throws Exception {
100104
}
101105

102106
@Test
103-
public void testMapWithNulls() throws Exception {
107+
void testMapWithNulls() throws Exception {
104108
Route input = new Route();
105109

106110
// id, agency, mode and name (short or long) is required.
@@ -129,7 +133,7 @@ public void testMapWithNulls() throws Exception {
129133
}
130134

131135
@Test
132-
public void mapNetworkId() {
136+
void mapNetworkId() {
133137
Route input = new Route();
134138

135139
input.setId(ROUTE_ID);
@@ -141,8 +145,8 @@ public void mapNetworkId() {
141145
org.opentripplanner.transit.model.network.Route result = subject.map(input);
142146

143147
assertEquals(
144-
List.of(NETWORK_ID),
145-
result.getGroupsOfRoutes().stream().map(g -> g.getId().getId()).toList()
148+
List.of(new FeedScopedId(FEED_ID, NETWORK_ID)),
149+
result.getGroupsOfRoutes().stream().map(AbstractTransitEntity::getId).toList()
146150
);
147151
}
148152

@@ -164,7 +168,7 @@ void carpool() {
164168
* Mapping the same object twice, should return the same instance.
165169
*/
166170
@Test
167-
public void testMapCache() throws Exception {
171+
void testMapCache() throws Exception {
168172
org.opentripplanner.transit.model.network.Route result1 = subject.map(ROUTE);
169173
org.opentripplanner.transit.model.network.Route result2 = subject.map(ROUTE);
170174

0 commit comments

Comments
 (0)