Skip to content

Commit a404aaa

Browse files
Brian OlsenBrian Olsen
authored andcommitted
Fix test fixtures
1 parent a9296f7 commit a404aaa

File tree

2 files changed

+121
-104
lines changed

2 files changed

+121
-104
lines changed

src/test/java/us/brianolsen/instructions/BaseTest.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Map;
1111

1212
import com.google.gson.Gson;
13+
import com.google.gson.JsonObject;
1314
import com.google.gson.JsonParser;
1415
import com.mapbox.services.api.directions.v5.models.LegStep;
1516

@@ -28,6 +29,8 @@ public class BaseTest {
2829
public class FixtureModel {
2930
private LegStep step;
3031
private Map<String, String> instructions;
32+
private JsonObject options;
33+
private Map<String, String> phrases;
3134

3235
public LegStep getStep() {
3336
return step;
@@ -36,6 +39,14 @@ public LegStep getStep() {
3639
public Map<String, String> getInstructions() {
3740
return instructions;
3841
}
42+
43+
public JsonObject getOptions() {
44+
return options;
45+
}
46+
47+
public Map<String, String> getPhrases() {
48+
return phrases;
49+
}
3950
}
4051

4152
public static String loadJsonFixture(String filename) {
@@ -53,24 +64,23 @@ public static String loadJsonFixture(String filename) {
5364
return body;
5465
}
5566

56-
protected void testFixture(String fixture) {
67+
protected void testFixture(String fixture, OSRMTextInstructions textInstructions) {
5768
String fixtureDirectory = Paths.get(FIXTURES_DIRECTORY, fixture).toString();
5869
File fixtureDirectoryFile = new File(fixtureDirectory);
5970
for (File fixtureFile : fixtureDirectoryFile.listFiles()) {
6071

6172
String body = loadJsonFixture(fixtureFile.getAbsolutePath());
6273
FixtureModel model = new Gson().fromJson(body, FixtureModel.class);
63-
System.out.println(fixture + ":" + fixtureFile.getName());
64-
for (Object entry : model.getInstructions().entrySet()) {
65-
try (OSRMTextInstructions textInstructions = new OSRMTextInstructions(VERSION)) {
74+
if (model.getInstructions() != null) {
75+
for (Object entry : model.getInstructions().entrySet()) {
6676
Map.Entry<String, String> pair = (Map.Entry<String, String>) entry;
6777
String language = pair.getKey();
6878
String compiled = pair.getValue();
6979
assertEquals(compiled, textInstructions.compile(language, model.getStep(), null));
70-
} catch (RuntimeException e) {
71-
System.err.println(e);
7280
}
81+
7382
}
83+
System.out.println("Fixture test for " + fixture + " passed in file " + fixtureFile.getName());
7484
}
7585
}
7686
}
Lines changed: 105 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,125 @@
11
package us.brianolsen.instructions;
22

3+
import org.junit.AfterClass;
4+
import org.junit.BeforeClass;
35
import org.junit.Test;
46

5-
//Only test specific fixtures in interest of avoiding too many files open bug until a solution is found.
67
public class OSRMTextInstructionsFixturesTest extends BaseTest {
8+
private static OSRMTextInstructions osrmTextInstructions;
9+
10+
@BeforeClass
11+
public static void setupClass() {
12+
osrmTextInstructions = new OSRMTextInstructions(VERSION);
13+
}
14+
15+
@AfterClass
16+
public static void teardownClass() {
17+
osrmTextInstructions.close();
18+
}
719

820
@Test
921
public void testFixturesMatchGeneratedArriveInstructions() {
10-
testFixture("arrive");
22+
testFixture("arrive", osrmTextInstructions);
23+
}
24+
25+
// @Test fails due to mismatching expected (from parent project)
26+
public void testFixturesMatchGeneratedArriveWaypointInstructions() {
27+
testFixture("arrive_waypoint", osrmTextInstructions);
28+
}
29+
30+
@Test
31+
public void testFixturesMatchGeneratedArriveWaypointLastInstructions() {
32+
testFixture("arrive_waypoint_last", osrmTextInstructions);
1133
}
1234

13-
// // @Test fails
14-
// public void testFixturesMatchGeneratedArriveWaypointInstructions() {
15-
// testFixture("arrive_waypoint");
16-
// }
17-
//
18-
// @Test
19-
// public void testFixturesMatchGeneratedArriveWaypointLastInstructions() {
20-
// testFixture("arrive_waypoint_last");
21-
// }
22-
//
23-
// // @Test fails
24-
// public void testFixturesMatchGeneratedContinueInstructions() {
25-
// testFixture("continue");
26-
// }
35+
// @Test fails due to mismatching expected (from parent project)
36+
public void testFixturesMatchGeneratedContinueInstructions() {
37+
testFixture("continue", osrmTextInstructions);
38+
}
2739

2840
@Test
2941
public void testFixturesMatchGeneratedDepartInstructions() {
30-
testFixture("depart");
31-
}
32-
33-
// @Test
34-
// public void testFixturesMatchGeneratedEndOfRoadInstructions() {
35-
// testFixture("end_of_road");
36-
// }
37-
//
38-
// @Test
39-
// public void testFixturesMatchGeneratedExitRotaryInstructions() {
40-
// testFixture("exit_rotary");
41-
// }
42-
//
43-
// @Test
44-
// public void testFixturesMatchGeneratedExitRoundaboutInstructions() {
45-
// testFixture("exit_roundabout");
46-
// }
47-
//
48-
// @Test
49-
// public void testFixturesMatchGeneratedForkInstructions() {
50-
// testFixture("fork");
51-
// }
52-
//
53-
// @Test
54-
// public void testFixturesMatchGeneratedMergeInstructions() {
55-
// testFixture("merge");
56-
// }
57-
//
58-
// @Test
59-
// public void testFixturesMatchGeneratedModesInstructions() {
60-
// testFixture("modes");
61-
// }
62-
//
63-
// @Test
64-
// public void testFixturesMatchGeneratedNewNameInstructions() {
65-
// testFixture("new_name");
66-
// }
67-
//
68-
// @Test
69-
// public void testFixturesMatchGeneratedNotificationInstructions() {
70-
// testFixture("notification");
71-
// }
72-
//
73-
// // @Test fail
74-
// public void testFixturesMatchGeneratedOffRampInstructions() {
75-
// testFixture("off_ramp");
76-
// }
77-
//
78-
// @Test
79-
// public void testFixturesMatchGeneratedOnRampInstructions() {
80-
// testFixture("on_ramp");
81-
// }
82-
//
83-
// // @Test fail
84-
// public void testFixturesMatchGeneratedOtherInstructions() {
85-
// testFixture("other");
86-
// }
87-
//
88-
// @Test
89-
// public void testFixturesMatchGeneratedPhraseInstructions() {
90-
// testFixture("phrase");
91-
// }
92-
//
93-
// @Test
94-
// public void testFixturesMatchGeneratedRotaryInstructions() {
95-
// testFixture("rotary");
96-
// }
97-
//
98-
// @Test
99-
// public void testFixturesMatchGeneratedRoundaboutInstructions() {
100-
// testFixture("roundabout");
101-
// }
102-
//
103-
// @Test
104-
// public void testFixturesMatchGeneratedRoundaboutTurnInstructions() {
105-
// testFixture("roundabout_turn");
106-
// }
42+
testFixture("depart", osrmTextInstructions);
43+
}
44+
45+
@Test
46+
public void testFixturesMatchGeneratedEndOfRoadInstructions() {
47+
testFixture("end_of_road", osrmTextInstructions);
48+
}
49+
50+
@Test
51+
public void testFixturesMatchGeneratedExitRotaryInstructions() {
52+
testFixture("exit_rotary", osrmTextInstructions);
53+
}
54+
55+
@Test
56+
public void testFixturesMatchGeneratedExitRoundaboutInstructions() {
57+
testFixture("exit_roundabout", osrmTextInstructions);
58+
}
59+
60+
@Test
61+
public void testFixturesMatchGeneratedForkInstructions() {
62+
testFixture("fork", osrmTextInstructions);
63+
}
64+
65+
@Test
66+
public void testFixturesMatchGeneratedMergeInstructions() {
67+
testFixture("merge", osrmTextInstructions);
68+
}
69+
70+
@Test
71+
public void testFixturesMatchGeneratedModesInstructions() {
72+
testFixture("modes", osrmTextInstructions);
73+
}
74+
75+
@Test
76+
public void testFixturesMatchGeneratedNewNameInstructions() {
77+
testFixture("new_name", osrmTextInstructions);
78+
}
79+
80+
@Test
81+
public void testFixturesMatchGeneratedNotificationInstructions() {
82+
testFixture("notification", osrmTextInstructions);
83+
}
84+
85+
// @Test fails due to mismatching expected (from parent project)
86+
public void testFixturesMatchGeneratedOffRampInstructions() {
87+
testFixture("off_ramp", osrmTextInstructions);
88+
}
89+
90+
@Test
91+
public void testFixturesMatchGeneratedOnRampInstructions() {
92+
testFixture("on_ramp", osrmTextInstructions);
93+
}
94+
95+
// @Test fails due to mismatching expected (from parent project)
96+
public void testFixturesMatchGeneratedOtherInstructions() {
97+
testFixture("other", osrmTextInstructions);
98+
}
99+
100+
@Test
101+
public void testFixturesMatchGeneratedRotaryInstructions() {
102+
testFixture("rotary", osrmTextInstructions);
103+
}
104+
105+
@Test
106+
public void testFixturesMatchGeneratedRoundaboutInstructions() {
107+
testFixture("roundabout", osrmTextInstructions);
108+
}
109+
110+
@Test
111+
public void testFixturesMatchGeneratedRoundaboutTurnInstructions() {
112+
testFixture("roundabout_turn", osrmTextInstructions);
113+
}
107114

108115
@Test
109116
public void testFixturesMatchGeneratedTurnInstructions() {
110-
testFixture("turn");
117+
testFixture("turn", osrmTextInstructions);
111118
}
112119

113-
// @Test
114-
// public void testFixturesMatchGeneratedUseLaneInstructions() {
115-
// testFixture("use_lane");
116-
// }
120+
@Test
121+
public void testFixturesMatchGeneratedUseLaneInstructions() {
122+
testFixture("use_lane", osrmTextInstructions);
123+
}
117124

118125
}

0 commit comments

Comments
 (0)