1
1
package org .soujava .demos .mongodb .document ;
2
2
3
3
import jakarta .inject .Inject ;
4
+ import net .datafaker .Faker ;
4
5
import org .assertj .core .api .SoftAssertions ;
5
6
import org .eclipse .jnosql .databases .mongodb .mapping .MongoDBTemplate ;
6
7
import org .eclipse .jnosql .mapping .Database ;
22
23
import org .junit .jupiter .params .provider .MethodSource ;
23
24
24
25
import java .util .List ;
26
+ import java .util .concurrent .ThreadLocalRandom ;
25
27
import java .util .stream .Stream ;
26
28
27
29
@@ -38,6 +40,8 @@ class RoomServiceTest {
38
40
@ Inject
39
41
private RoomRepository repository ;
40
42
43
+ private static final Faker FAKER = new Faker ();
44
+
41
45
@ BeforeEach
42
46
void setUP () {
43
47
@@ -178,13 +182,19 @@ void shouldFindRoomsNeedingCleaning() {
178
182
179
183
static Stream <Arguments > room () {
180
184
Room room = new RoomBuilder ()
181
- .roomNumber (101 )
182
- .type (RoomType .VIP_SUITE )
183
- .status (RoomStatus .AVAILABLE )
184
- .cleanStatus (CleanStatus .CLEAN )
185
- .smokingAllowed (false )
185
+ .roomNumber (FAKER . number (). numberBetween ( 100 , 999 ) )
186
+ .type (randomEnum ( RoomType .class ) )
187
+ .status (randomEnum ( RoomStatus .class ) )
188
+ .cleanStatus (randomEnum ( CleanStatus .class ) )
189
+ .smokingAllowed (FAKER . bool (). bool () )
186
190
.build ();
187
191
188
192
return Stream .of (Arguments .of (room ));
189
193
}
194
+
195
+ private static <T extends Enum <?>> T randomEnum (Class <T > enumClass ) {
196
+ T [] constants = enumClass .getEnumConstants ();
197
+ int index = ThreadLocalRandom .current ().nextInt (constants .length );
198
+ return constants [index ];
199
+ }
190
200
}
0 commit comments