Skip to content

Commit 1cc3c88

Browse files
committed
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).
1 parent 4020686 commit 1cc3c88

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
/**
44
* Generates emergency-related fake data: the nature of an emergency
5-
* (fire, flood, tornado, ...), a plausible emergency location, and an
6-
* instruction someone might be asked to follow in response.
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.
78
*
8-
* @since 2.7.0
9+
* @since 2.6.0
910
*/
1011
public class Emergency extends AbstractProvider<BaseProviders> {
1112

@@ -35,4 +36,22 @@ public String location() {
3536
public String instruction() {
3637
return resolve("emergency.instruction");
3738
}
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) { }
3857
}

src/test/java/net/datafaker/providers/base/EmergencyTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import java.util.Collection;
44
import java.util.List;
55

6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
610
final class EmergencyTest extends BaseFakerTest {
711

812
@Override
@@ -13,4 +17,18 @@ protected Collection<TestSpec> providerListTest() {
1317
TestSpec.of(emergency::location, "emergency.location"),
1418
TestSpec.of(emergency::instruction, "emergency.instruction"));
1519
}
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+
}
1634
}

0 commit comments

Comments
 (0)