Skip to content

Commit b25c7ab

Browse files
committed
refactor: Add requireSameFeedId method to FeedScopedId
1 parent d349c1a commit b25c7ab

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

application/src/main/java/org/opentripplanner/transit/model/framework/FeedScopedId.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ public static boolean isValidString(@Nullable String value) throws IllegalArgume
9090
return value != null && value.indexOf(ID_SEPARATOR) > -1;
9191
}
9292

93+
public void requireSameFeedId(FeedScopedId other) {
94+
if (!feedId.equals(other.feedId)) {
95+
throw new IllegalArgumentException(
96+
"FeedIds does not match: '" + feedId + "' != '" + other.feedId + "'"
97+
);
98+
}
99+
}
100+
93101
/**
94102
* Concatenate feedId and id into a string.
95103
*/

application/src/test/java/org/opentripplanner/transit/model/framework/FeedScopedIdTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ void parseList() {
5454
);
5555
}
5656

57+
@Test
58+
void requireSameFeedId() {
59+
var ex = assertThrows(IllegalArgumentException.class, () ->
60+
new FeedScopedId("F", "1").requireSameFeedId(new FeedScopedId("E", "1"))
61+
);
62+
assertEquals("FeedIds does not match: 'F' != 'E'", ex.getMessage());
63+
}
64+
5765
@Test
5866
void throwWhenParsingNull() {
5967
var input = new ArrayList<String>();

0 commit comments

Comments
 (0)