File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
src/test/java/org/soujava/demos/mongodb/document Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ package org .soujava .demos .mongodb .document ;
2
+
3
+ import net .datafaker .Faker ;
4
+
5
+ import java .util .UUID ;
6
+ import java .util .concurrent .ThreadLocalRandom ;
7
+
8
+ final class RoomFaker {
9
+
10
+ private static final Faker FAKER = new Faker ();
11
+
12
+ static Room getRoom () {
13
+ return Room .builder ()
14
+ .id (UUID .randomUUID ().toString ())
15
+ .roomNumber (FAKER .number ().numberBetween (100 , 999 ))
16
+ .type (randomEnum (RoomType .class ))
17
+ .status (randomEnum (RoomStatus .class ))
18
+ .cleanStatus (randomEnum (CleanStatus .class ))
19
+ .smokingAllowed (FAKER .bool ().bool ())
20
+ .build ();
21
+ }
22
+
23
+
24
+ static <T extends Enum <?>> T randomEnum (Class <T > enumClass ) {
25
+ T [] constants = enumClass .getEnumConstants ();
26
+ int index = ThreadLocalRandom .current ().nextInt (constants .length );
27
+ return constants [index ];
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments