Skip to content

Commit c03d7c1

Browse files
authored
feat: add Emergency provider (nature, location, instruction) (#1794)
* feat: add Emergency provider (nature, location, instruction) Adds a new base provider that generates emergency-related fake data: faker.emergency().nature() // "Fire", "Flood", "Tornado", ... faker.emergency().location() // "Highway", "Shopping mall", ... faker.emergency().instruction() // "Evacuate the building", ... Includes the provider class, YAML dataset with 35 natures, 35 locations, and 30 instructions, BaseProviders wiring, EnFile resource registration, and the standard provider-list test. Closes #1793 * feat: add dryRun flag and emergencyCase sub-provider Extends Emergency with: - dryRun(): boolean flag distinguishing training alerts from real emergencies (per @L-Evg's suggestion in #1794) - emergencyCase(): bundles nature, location, instruction, and dryRun into an EmergencyCase record for a single-call full emergency Also fixes the @SInCE tag from 2.7.0 to 2.6.0 (per @kingthorin's review). --------- Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
1 parent 46c5170 commit c03d7c1

5 files changed

Lines changed: 202 additions & 0 deletions

File tree

src/main/java/net/datafaker/providers/base/BaseProviders.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ default ElectricalComponents electricalComponents() {
209209
return getProvider(ElectricalComponents.class, ElectricalComponents::new);
210210
}
211211

212+
default Emergency emergency() {
213+
return getProvider(Emergency.class, Emergency::new);
214+
}
215+
212216
default Emoji emoji() {
213217
return getProvider(Emoji.class, Emoji::new);
214218
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package net.datafaker.providers.base;
2+
3+
/**
4+
* Generates emergency-related fake data: the nature of an emergency
5+
* (fire, flood, tornado, ...), a plausible emergency location, an
6+
* instruction someone might be asked to follow in response, and a
7+
* dry-run flag distinguishing training alerts from real emergencies.
8+
*
9+
* @since 2.6.0
10+
*/
11+
public class Emergency extends AbstractProvider<BaseProviders> {
12+
13+
protected Emergency(BaseProviders faker) {
14+
super(faker);
15+
}
16+
17+
/**
18+
* @return a type of emergency, e.g. "Fire", "Flood", "Tornado".
19+
*/
20+
public String nature() {
21+
return resolve("emergency.nature");
22+
}
23+
24+
/**
25+
* @return a plausible location where an emergency might occur,
26+
* e.g. "Highway", "Downtown office building".
27+
*/
28+
public String location() {
29+
return resolve("emergency.location");
30+
}
31+
32+
/**
33+
* @return an instruction to follow during an emergency, e.g.
34+
* "Evacuate the building", "Shelter in place".
35+
*/
36+
public String instruction() {
37+
return resolve("emergency.instruction");
38+
}
39+
40+
/**
41+
* @return {@code true} for a dry-run (training) alert, {@code false}
42+
* for a real emergency.
43+
*/
44+
public boolean dryRun() {
45+
return faker.random().nextBoolean();
46+
}
47+
48+
/**
49+
* @return a complete emergency case bundling {@link #nature()},
50+
* {@link #location()}, {@link #instruction()}, and {@link #dryRun()}.
51+
*/
52+
public EmergencyCase emergencyCase() {
53+
return new EmergencyCase(nature(), location(), instruction(), dryRun());
54+
}
55+
56+
public record EmergencyCase(String nature, String location, String instruction, boolean dryRun) { }
57+
}

src/main/java/net/datafaker/service/files/EnFile.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ public String getPath() {
103103
"elden_ring.yml",
104104
"elder_scrolls.yml",
105105
"electrical_components.yml",
106+
"emergency.yml",
106107
"emoji.yml",
107108
"esport.yml",
108109
"englandfootball.yml",
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
en:
2+
faker:
3+
emergency:
4+
nature:
5+
- "Fire"
6+
- "Flood"
7+
- "Earthquake"
8+
- "Tornado"
9+
- "Hurricane"
10+
- "Tsunami"
11+
- "Wildfire"
12+
- "Landslide"
13+
- "Volcanic eruption"
14+
- "Blizzard"
15+
- "Severe thunderstorm"
16+
- "Hailstorm"
17+
- "Heatwave"
18+
- "Cold wave"
19+
- "Drought"
20+
- "Power outage"
21+
- "Gas leak"
22+
- "Chemical spill"
23+
- "Nuclear incident"
24+
- "Building collapse"
25+
- "Bridge collapse"
26+
- "Vehicle accident"
27+
- "Train derailment"
28+
- "Aircraft incident"
29+
- "Maritime incident"
30+
- "Medical emergency"
31+
- "Pandemic outbreak"
32+
- "Hazardous materials"
33+
- "Structural fire"
34+
- "Forest fire"
35+
- "Explosion"
36+
- "Bomb threat"
37+
- "Active shooter"
38+
- "Civil unrest"
39+
- "Missing person"
40+
location:
41+
- "Residential building"
42+
- "Downtown office tower"
43+
- "Shopping mall"
44+
- "School"
45+
- "Hospital"
46+
- "University campus"
47+
- "Factory"
48+
- "Warehouse"
49+
- "Highway"
50+
- "Subway station"
51+
- "Train station"
52+
- "Bus terminal"
53+
- "Airport terminal"
54+
- "Seaport"
55+
- "Sports stadium"
56+
- "Concert venue"
57+
- "Convention center"
58+
- "Hotel"
59+
- "Restaurant"
60+
- "Gas station"
61+
- "Chemical plant"
62+
- "Power plant"
63+
- "Data center"
64+
- "Apartment complex"
65+
- "Government building"
66+
- "Park"
67+
- "Parking garage"
68+
- "Construction site"
69+
- "Farm"
70+
- "Forest"
71+
- "Riverbank"
72+
- "Coastline"
73+
- "Mountain trail"
74+
- "Rural road"
75+
- "City square"
76+
instruction:
77+
- "Evacuate the building immediately"
78+
- "Shelter in place"
79+
- "Move to higher ground"
80+
- "Take cover under a sturdy desk"
81+
- "Use the stairs, not the elevator"
82+
- "Proceed to the nearest exit"
83+
- "Assemble at the designated meeting point"
84+
- "Do not re-enter the building"
85+
- "Cover your mouth and nose"
86+
- "Stay away from windows"
87+
- "Turn off gas and electricity"
88+
- "Call emergency services"
89+
- "Remain calm and await instructions"
90+
- "Follow the marked evacuation route"
91+
- "Do not use open flames"
92+
- "Check on neighbors if safe to do so"
93+
- "Stay tuned to official broadcasts"
94+
- "Wear protective clothing"
95+
- "Avoid downed power lines"
96+
- "Drop, cover, and hold on"
97+
- "Secure loose objects"
98+
- "Do not drive through flooded roads"
99+
- "Keep your distance from the affected area"
100+
- "Administer first aid if trained"
101+
- "Evacuate by vehicle using authorized routes"
102+
- "Return only when authorities give the all clear"
103+
- "Conserve drinking water"
104+
- "Boil water before consumption"
105+
- "Move vehicles away from buildings"
106+
- "Silence your phone and listen for alerts"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package net.datafaker.providers.base;
2+
3+
import java.util.Collection;
4+
import java.util.List;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
final class EmergencyTest extends BaseFakerTest {
11+
12+
@Override
13+
protected Collection<TestSpec> providerListTest() {
14+
Emergency emergency = faker.emergency();
15+
return List.of(
16+
TestSpec.of(emergency::nature, "emergency.nature"),
17+
TestSpec.of(emergency::location, "emergency.location"),
18+
TestSpec.of(emergency::instruction, "emergency.instruction"));
19+
}
20+
21+
@Test
22+
void shouldReturnDryRunFlag() {
23+
assertThat(faker.emergency().dryRun()).isIn(false, true);
24+
}
25+
26+
@Test
27+
void shouldReturnEmergencyCase() {
28+
Emergency.EmergencyCase emergencyCase = faker.emergency().emergencyCase();
29+
assertThat(emergencyCase.nature()).isNotEmpty();
30+
assertThat(emergencyCase.location()).isNotEmpty();
31+
assertThat(emergencyCase.instruction()).isNotEmpty();
32+
assertThat(emergencyCase.dryRun()).isIn(false, true);
33+
}
34+
}

0 commit comments

Comments
 (0)