Skip to content

Commit

Permalink
ORG: NAV-6 - Set code style for project
Browse files Browse the repository at this point in the history
- Add IntelliJ code style to project.
- Reformat complete project.
  • Loading branch information
munterfi committed May 4, 2024
1 parent 2b1cdc2 commit eac4f5c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
25 changes: 25 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ enum GtfsScheduleFile {
private final Presence presence;

public enum Presence {
REQUIRED, OPTIONAL, CONDITIONALLY_REQUIRED, CONDITIONALLY_FORBIDDEN, RECOMMENDED
REQUIRED,
OPTIONAL,
CONDITIONALLY_REQUIRED,
CONDITIONALLY_FORBIDDEN,
RECOMMENDED
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.BOMInputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -65,7 +61,8 @@ private static void readFromZip(File zipFile, GtfsScheduleParser parser) throws
readCsvRecords(reader, parser, fileType);
}
} else if (fileType.getPresence() == GtfsScheduleFile.Presence.REQUIRED) {
throw new FileNotFoundException("Required GTFS CSV file" + fileType.getFileName() + " not found in ZIP");
throw new FileNotFoundException(
"Required GTFS CSV file" + fileType.getFileName() + " not found in ZIP");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ class GtfsScheduleTest {

@BeforeEach
void setUp(GtfsScheduleTestBuilder builder) {
schedule = builder.withAddAgency().withAddCalendars().withAddCalendarDates().withAddInterCity()
.withAddUnderground().withAddBus().build();
schedule = builder.withAddAgency()
.withAddCalendars()
.withAddCalendarDates()
.withAddInterCity()
.withAddUnderground()
.withAddBus()
.build();
}

@Nested
Expand Down Expand Up @@ -63,13 +68,15 @@ void shouldFindStopWithin1Meter() {

@Test
void shouldFindStopsWithin10000Meters() {
assertThat(schedule.getNearestStops(47.5, 8.5, 10000)).hasSize(3).extracting("id")
assertThat(schedule.getNearestStops(47.5, 8.5, 10000)).hasSize(3)
.extracting("id")
.containsOnly("u6", "s2", "u3");
}

@Test
void shouldFindAllStops() {
assertThat(schedule.getNearestStops(47.5, 8.5, Integer.MAX_VALUE)).hasSize(9).extracting("id")
assertThat(schedule.getNearestStops(47.5, 8.5, Integer.MAX_VALUE)).hasSize(9)
.extracting("id")
.containsOnly("s1", "s2", "s3", "u1", "u2", "u3", "u4", "u5", "u6");
}

Expand All @@ -90,7 +97,8 @@ private static void assertWeekendAndHoliday(List<StopTime> departures) {
List<ServiceDayTime> expectedDepartures = List.of(ServiceDayTime.parse("08:15:00"),
ServiceDayTime.parse("08:15:00"), ServiceDayTime.parse("09:15:00"),
ServiceDayTime.parse("09:15:00"), ServiceDayTime.parse("10:15:00"));
assertThat(departures).hasSize(LIMIT).extracting(StopTime::departure)
assertThat(departures).hasSize(LIMIT)
.extracting(StopTime::departure)
.containsExactlyElementsOf(expectedDepartures);

// assert trips are correct
Expand All @@ -114,7 +122,8 @@ void shouldReturnNextDeparturesOnWeekday() {
List<ServiceDayTime> expectedDepartures = List.of(ServiceDayTime.parse("08:00:00"),
ServiceDayTime.parse("08:00:00"), ServiceDayTime.parse("08:09:00"),
ServiceDayTime.parse("08:09:00"), ServiceDayTime.parse("08:15:00"));
assertThat(departures).hasSize(LIMIT).extracting(StopTime::departure)
assertThat(departures).hasSize(LIMIT)
.extracting(StopTime::departure)
.containsExactlyElementsOf(expectedDepartures);

// assert trips are correct
Expand Down Expand Up @@ -154,7 +163,8 @@ void shouldReturnNextDeparturesAfterMidnight() {
List<ServiceDayTime> expectedDepartures = List.of(ServiceDayTime.parse("24:00:00"),
ServiceDayTime.parse("24:00:00"), ServiceDayTime.parse("24:09:00"),
ServiceDayTime.parse("24:09:00"), ServiceDayTime.parse("24:15:00"));
assertThat(departures).hasSize(LIMIT).extracting(StopTime::departure)
assertThat(departures).hasSize(LIMIT)
.extracting(StopTime::departure)
.containsExactlyElementsOf(expectedDepartures);

// assert trips are correct
Expand Down Expand Up @@ -186,7 +196,8 @@ void shouldReturnNoDeparturesFromUnknownStop() {
class ActiveTrips {

private static void assertWeekendAndHoliday(List<Trip> activeTrips) {
assertThat(activeTrips).hasSize(168).extracting(trip -> trip.getRoute().getId())
assertThat(activeTrips).hasSize(168)
.extracting(trip -> trip.getRoute().getId())
.containsAll(Set.of("route1", "route2"));
}

Expand All @@ -195,7 +206,8 @@ void shouldReturnActiveTripsOnWeekday() {
List<Trip> activeTrips = schedule.getActiveTrips(
GtfsScheduleTestBuilder.Moments.WEEKDAY_8_AM.toLocalDate());

assertThat(activeTrips).hasSize(503).extracting(trip -> trip.getRoute().getId())
assertThat(activeTrips).hasSize(503)
.extracting(trip -> trip.getRoute().getId())
.containsAll(Set.of("route1", "route2", "route3"));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
package ch.naviqore.gtfs.schedule.model;

import ch.naviqore.gtfs.schedule.type.DefaultRouteType;
import ch.naviqore.gtfs.schedule.type.ExceptionType;
import ch.naviqore.gtfs.schedule.type.HierarchicalVehicleType;
import ch.naviqore.gtfs.schedule.type.RouteType;
import ch.naviqore.gtfs.schedule.type.ServiceDayTime;
import ch.naviqore.gtfs.schedule.type.*;
import lombok.NoArgsConstructor;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

/**
* Test builder to set up a GTFS schedule for testing purposes.
Expand Down Expand Up @@ -105,7 +95,6 @@ public GtfsScheduleTestBuilder withAddInterCity() {
return this;
}


public GtfsScheduleTestBuilder withAddUnderground() {
addRoute(ROUTES.get(1), true, false);
return this;
Expand All @@ -120,7 +109,6 @@ public GtfsSchedule build() {
return builder.build();
}


private void addRoute(Route route, boolean everydayService, boolean bidirectional) {
builder.addRoute(route.id, route.agencyId, route.name, route.name + "long", route.routeType);
addStops(route);
Expand Down

0 comments on commit eac4f5c

Please sign in to comment.