11package org .soujava .demos .mongodb ;
22
33
4+ import io .cucumber .java .Before ;
45import io .cucumber .java .en .*;
56import org .assertj .core .api .Assertions ;
67import org .soujava .demos .mongodb .document .*;
1112
1213public class HotelRoomSteps {
1314
14-
1515 @ Inject
16- RoomService roomService ;
16+ private RoomService service ;
1717
1818 @ Inject
19- RoomRepository roomRepository ;
19+ private RoomRepository repository ;
20+
21+ @ Before
22+ public void cleanDatabase () {
23+ repository .deleteBy ();
24+ }
2025
2126 @ Given ("the hotel management system is operational" )
2227 public void the_hotel_management_system_is_operational () {
23- Assertions .assertThat (roomService ).as ("RoomService should be initialized" ).isNotNull ();
24- Assertions .assertThat (roomRepository ).as ("RoomRepository should be initialized" ).isNotNull ();
28+ Assertions .assertThat (service ).as ("RoomService should be initialized" ).isNotNull ();
29+ Assertions .assertThat (repository ).as ("RoomRepository should be initialized" ).isNotNull ();
2530 }
2631
2732 @ When ("I register a room with number {int}" )
@@ -32,25 +37,25 @@ public void i_register_a_room_with_number(Integer number) {
3237 .status (RoomStatus .AVAILABLE )
3338 .cleanStatus (CleanStatus .CLEAN )
3439 .build ();
35- roomService .save (room );
40+ service .save (room );
3641 }
3742
3843 @ Then ("the room with number {int} should appear in the room list" )
3944 public void the_room_with_number_should_appear_in_the_room_list (Integer number ) {
40- List <Room > rooms = roomRepository .findAll ();
45+ List <Room > rooms = repository .findAll ();
4146 Assertions .assertThat (rooms )
4247 .extracting (Room ::getNumber )
4348 .contains (number );
4449 }
4550
4651 @ When ("I register the following rooms:" )
4752 public void i_register_the_following_rooms (List <Room > rooms ) {
48- rooms .forEach (roomService ::save );
53+ rooms .forEach (service ::save );
4954 }
5055
5156 @ Then ("there should be {int} rooms available in the system" )
5257 public void there_should_be_rooms_available_in_the_system (int expectedCount ) {
53- List <Room > rooms = roomRepository .findAll ();
58+ List <Room > rooms = repository .findAll ();
5459 Assertions .assertThat (rooms ).hasSize (expectedCount );
5560 }
5661
@@ -63,13 +68,13 @@ public void a_room_with_number_is_registered_as(Integer number, String statusNam
6368 .status (status )
6469 .cleanStatus (CleanStatus .CLEAN )
6570 .build ();
66- roomService .save (room );
71+ service .save (room );
6772 }
6873
6974 @ When ("I mark the room {int} as {word}" )
7075 public void i_mark_the_room_as (Integer number , String newStatusName ) {
7176 RoomStatus newStatus = RoomStatus .valueOf (newStatusName );
72- Optional <Room > roomOpt = roomRepository .findAll ()
77+ Optional <Room > roomOpt = repository .findAll ()
7378 .stream ()
7479 .filter (r -> r .getNumber () == number )
7580 .findFirst ();
@@ -81,13 +86,13 @@ public void i_mark_the_room_as(Integer number, String newStatusName) {
8186 Room updatedRoom = roomOpt .orElseThrow ();
8287 updatedRoom .update (newStatus );
8388
84- roomService .save (updatedRoom );
89+ service .save (updatedRoom );
8590 }
8691
8792 @ Then ("the room {int} should be marked as {word}" )
8893 public void the_room_should_be_marked_as (Integer number , String expectedStatusName ) {
8994 RoomStatus expectedStatus = RoomStatus .valueOf (expectedStatusName );
90- Optional <Room > roomOpt = roomRepository .findAll ()
95+ Optional <Room > roomOpt = repository .findAll ()
9196 .stream ()
9297 .filter (r -> r .getNumber () == number )
9398 .findFirst ();
0 commit comments