Skip to content

Commit 4566f57

Browse files
Refactor NetexEntitiesTestFactory and unit tests. (#600)
1 parent fbd1eb8 commit 4566f57

19 files changed

+2272
-2308
lines changed

src/test/java/no/entur/antu/netextestdata/NetexEntitiesTestFactory.java

+1,120-693
Large diffs are not rendered by default.

src/test/java/no/entur/antu/validation/flex/validator/flexiblearea/InvalidFlexibleAreaValidatorTest.java

+22-29
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import org.entur.netex.index.api.NetexEntitiesIndex;
1111
import org.entur.netex.validation.validator.ValidationReport;
1212
import org.junit.jupiter.api.Test;
13-
import org.rutebanken.netex.model.FlexibleArea;
14-
import org.rutebanken.netex.model.FlexibleStopPlace;
1513

1614
class InvalidFlexibleAreaValidatorTest extends ValidationTest {
1715

@@ -26,10 +24,11 @@ private ValidationReport runValidation(
2624

2725
@Test
2826
void testDataSetWithoutFlexibleStopPlacesShouldBeIgnoredGracefully() {
29-
NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory();
27+
NetexEntitiesTestFactory netexEntitiesTestFactory =
28+
new NetexEntitiesTestFactory();
3029

3130
ValidationReport validationReport = runValidation(
32-
testData.netexEntitiesIndex().create()
31+
netexEntitiesTestFactory.create()
3332
);
3433

3534
assertTrue(validationReport.getValidationReportEntries().isEmpty());
@@ -177,30 +176,30 @@ void testMissingCoordinatesShouldFail() {
177176

178177
@Test
179178
void testMissingFlexibleStopAreaShouldIgnoreValidationGracefully() {
180-
NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory();
179+
NetexEntitiesTestFactory netexEntitiesTestFactory =
180+
new NetexEntitiesTestFactory();
181181

182-
FlexibleStopPlace flexibleStopPlace =
183-
new NetexEntitiesTestFactory.CreateFlexibleStopPlace().create();
182+
netexEntitiesTestFactory.createFlexibleStopPlace();
184183

185184
ValidationReport validationReport = runValidation(
186-
testData.netexEntitiesIndex(flexibleStopPlace).create()
185+
netexEntitiesTestFactory.create()
187186
);
188187

189188
assertThat(validationReport.getValidationReportEntries().size(), is(0));
190189
}
191190

192191
@Test
193192
void testMissingPolygonShouldIgnoreValidationGracefully2() {
194-
NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory();
193+
NetexEntitiesTestFactory netexEntitiesTestFactory =
194+
new NetexEntitiesTestFactory();
195195

196-
FlexibleArea flexibleArea = testData.flexibleArea().create();
197-
198-
FlexibleStopPlace flexibleStopPlace = testData
199-
.flexibleStopPlace(flexibleArea.withPolygon(null))
200-
.create();
196+
netexEntitiesTestFactory
197+
.createFlexibleStopPlace()
198+
.flexibleArea(1)
199+
.withNullPolygon(true);
201200

202201
ValidationReport validationReport = runValidation(
203-
testData.netexEntitiesIndex(flexibleStopPlace).create()
202+
netexEntitiesTestFactory.create()
204203
);
205204

206205
assertThat(validationReport.getValidationReportEntries().size(), is(0));
@@ -209,19 +208,13 @@ void testMissingPolygonShouldIgnoreValidationGracefully2() {
209208
private ValidationReport runTestWithGivenCoordinates(
210209
List<Double> coordinates
211210
) {
212-
NetexEntitiesTestFactory testData = new NetexEntitiesTestFactory();
213-
214-
FlexibleArea flexibleArea = testData
215-
.flexibleArea()
216-
.withCoordinates(coordinates)
217-
.create();
218-
219-
FlexibleStopPlace flexibleStopPlace = testData
220-
.flexibleStopPlace(flexibleArea)
221-
.create();
222-
223-
return runValidation(
224-
testData.netexEntitiesIndex(flexibleStopPlace).create()
225-
);
211+
NetexEntitiesTestFactory netexEntitiesTestFactory =
212+
new NetexEntitiesTestFactory();
213+
netexEntitiesTestFactory
214+
.createFlexibleStopPlace()
215+
.flexibleArea(1)
216+
.withCoordinates(coordinates);
217+
218+
return runValidation(netexEntitiesTestFactory.create());
226219
}
227220
}

src/test/java/no/entur/antu/validation/validator/interchange/distance/UnexpectedInterchangeDistanceValidatorTest.java

+20-32
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66

77
import java.util.Collection;
8-
import java.util.List;
98
import java.util.stream.IntStream;
109
import no.entur.antu.netextestdata.NetexEntitiesTestFactory;
1110
import no.entur.antu.validation.ValidationTest;
@@ -15,9 +14,8 @@
1514
import org.entur.netex.validation.validator.model.QuayCoordinates;
1615
import org.entur.netex.validation.validator.model.QuayId;
1716
import org.entur.netex.validation.validator.model.ScheduledStopPointId;
18-
import org.entur.netex.validation.validator.model.ServiceJourneyId;
1917
import org.junit.jupiter.api.Test;
20-
import org.rutebanken.netex.model.ServiceJourneyInterchange;
18+
import org.rutebanken.netex.model.ScheduledStopPointRefStructure;
2119

2220
class UnexpectedInterchangeDistanceValidatorTest extends ValidationTest {
2321

@@ -165,57 +163,47 @@ private ValidationReport runTestWithCoordinates(
165163
) {
166164
assert coordinates.length % 2 == 0;
167165

168-
NetexEntitiesTestFactory fragment = new NetexEntitiesTestFactory();
166+
NetexEntitiesTestFactory netexEntitiesTestFactory =
167+
new NetexEntitiesTestFactory();
169168

170-
List<ServiceJourneyInterchange> serviceJourneyInterchanges = IntStream
169+
IntStream
171170
.rangeClosed(1, coordinates.length / 2)
172-
.mapToObj(i -> {
171+
.forEach(i -> {
173172
int idx1 = (i - 1) * 2;
174173
int idx2 = (i - 1) * 2 + 1;
175174

176175
QuayCoordinates fromCoordinates = coordinates[idx1];
177176
QuayCoordinates toCoordinates = coordinates[idx2];
178177

179-
ScheduledStopPointId fromPointRef = new ScheduledStopPointId(
180-
"TST:ScheduledStopPoint:" + idx1
181-
);
182-
ScheduledStopPointId toPointRef = new ScheduledStopPointId(
183-
"TST:ScheduledStopPoint:" + idx2
184-
);
178+
ScheduledStopPointRefStructure fromPointRef =
179+
NetexEntitiesTestFactory.createScheduledStopPointRef(idx1);
180+
ScheduledStopPointRefStructure toPointRef =
181+
NetexEntitiesTestFactory.createScheduledStopPointRef(idx2);
185182

186183
mockGetCoordinates(
187-
fromPointRef,
184+
ScheduledStopPointId.of(fromPointRef),
188185
new QuayId("TST:Quay:" + idx1),
189186
fromCoordinates
190187
);
188+
191189
mockGetCoordinates(
192-
toPointRef,
190+
ScheduledStopPointId.of(toPointRef),
193191
new QuayId("TST:Quay:" + idx2),
194192
toCoordinates
195193
);
196194

197-
return fragment
198-
.serviceJourneyInterchange()
199-
.withId(i)
195+
netexEntitiesTestFactory
196+
.createServiceJourneyInterchange(i)
200197
.withFromPointRef(fromPointRef)
201198
.withToPointRef(toPointRef)
202199
.withFromJourneyRef(
203-
ServiceJourneyId.ofValidId("TST:ServiceJourney:" + idx1)
200+
NetexEntitiesTestFactory.createServiceJourneyRef(idx1)
204201
)
205202
.withToJourneyRef(
206-
ServiceJourneyId.ofValidId("TST:ServiceJourney:" + idx2)
207-
)
208-
.create();
209-
})
210-
.toList();
211-
212-
return runValidation(
213-
fragment
214-
.netexEntitiesIndex()
215-
.addInterchanges(
216-
serviceJourneyInterchanges.toArray(ServiceJourneyInterchange[]::new)
217-
)
218-
.create()
219-
);
203+
NetexEntitiesTestFactory.createServiceJourneyRef(idx2)
204+
);
205+
});
206+
207+
return runValidation(netexEntitiesTestFactory.create());
220208
}
221209
}

0 commit comments

Comments
 (0)