17
17
import org .junit .jupiter .api .BeforeEach ;
18
18
import org .junit .jupiter .api .Test ;
19
19
import org .junit .jupiter .params .ParameterizedTest ;
20
+ import org .junit .jupiter .params .provider .Arguments ;
20
21
import org .junit .jupiter .params .provider .EnumSource ;
22
+ import org .junit .jupiter .params .provider .MethodSource ;
21
23
22
24
import java .util .List ;
25
+ import java .util .stream .Stream ;
23
26
24
27
25
28
@ EnableAutoWeld
@@ -36,7 +39,7 @@ class RoomServiceTest {
36
39
private RoomRepository repository ;
37
40
38
41
@ BeforeEach
39
- void setUP () {
42
+ void setUP () {
40
43
41
44
Room vipRoom1 = new RoomBuilder ()
42
45
.roomNumber (101 )
@@ -101,58 +104,86 @@ void setUP() {
101
104
smokingAllowedRoom
102
105
));
103
106
104
- }
105
-
106
- @ AfterEach
107
- void cleanUp () {
108
- repository .deleteBy ();
109
- }
110
-
111
- @ Test
112
- void shouldFindRoomReadyToGuest () {
113
- List <Room > rooms = this .repository .findAvailableStandardRooms ();
114
- SoftAssertions .assertSoftly (softly -> {
115
- softly .assertThat (rooms ).hasSize (3 );
116
- softly .assertThat (rooms ).allMatch (room -> room .getStatus ().equals (RoomStatus .AVAILABLE ));
117
- softly .assertThat (rooms ).allMatch (room -> !room .isUnderMaintenance ());
118
- });
119
- }
120
-
121
- @ Test
122
- void shouldFindVipRoomsReadyForGuests () {
123
- List <Room > rooms = this .repository .findVipRoomsReadyForGuests ();
124
- SoftAssertions .assertSoftly (softly -> {
125
- softly .assertThat (rooms ).hasSize (2 );
126
- softly .assertThat (rooms ).allMatch (room -> room .getType ().equals (RoomType .VIP_SUITE ));
127
- softly .assertThat (rooms ).allMatch (room -> room .getStatus ().equals (RoomStatus .AVAILABLE ));
128
- softly .assertThat (rooms ).allMatch (room -> !room .isUnderMaintenance ());
129
- });
130
- }
131
-
132
- @ Test
133
- void shouldFindAvailableSmokingRooms () {
134
- List <Room > rooms = this .repository .findAvailableSmokingRooms ();
135
- SoftAssertions .assertSoftly (softly -> {
136
- softly .assertThat (rooms ).hasSize (2 );
137
- softly .assertThat (rooms ).allMatch (room -> room .isSmokingAllowed ());
138
- softly .assertThat (rooms ).allMatch (room -> room .getStatus ().equals (RoomStatus .AVAILABLE ));
139
- });
140
- }
141
-
142
- @ Test
143
- void shouldFindRoomsNeedingCleaning () {
144
- List <Room > rooms = this .repository .findRoomsNeedingCleaning ();
145
- SoftAssertions .assertSoftly (softly -> {
146
- softly .assertThat (rooms ).hasSize (2 );
147
- softly .assertThat (rooms ).allMatch (room -> !room .getCleanStatus ().equals (CleanStatus .CLEAN ));
148
- softly .assertThat (rooms ).allMatch (room -> !room .getStatus ().equals (RoomStatus .OUT_OF_SERVICE ));
149
- });
150
- }
151
-
152
- @ ParameterizedTest (name = "should find rooms by type {0}" )
153
- @ EnumSource (RoomType .class )
154
- void shouldFindRoomByType (RoomType type ) {
155
- List <Room > rooms = this .repository .findByType (type );
156
- SoftAssertions .assertSoftly (softly -> softly .assertThat (rooms ).allMatch (room -> room .getType ().equals (type )));
157
- }
107
+ }
108
+
109
+ @ AfterEach
110
+ void cleanUp () {
111
+ repository .deleteBy ();
112
+ }
113
+
114
+ @ Test
115
+ void shouldFindRoomReadyToGuest () {
116
+ List <Room > rooms = this .repository .findAvailableStandardRooms ();
117
+ SoftAssertions .assertSoftly (softly -> {
118
+ softly .assertThat (rooms ).hasSize (3 );
119
+ softly .assertThat (rooms ).allMatch (room -> room .getStatus ().equals (RoomStatus .AVAILABLE ));
120
+ softly .assertThat (rooms ).allMatch (room -> !room .isUnderMaintenance ());
121
+ });
122
+ }
123
+
124
+ @ Test
125
+ void shouldFindVipRoomsReadyForGuests () {
126
+ List <Room > rooms = this .repository .findVipRoomsReadyForGuests ();
127
+ SoftAssertions .assertSoftly (softly -> {
128
+ softly .assertThat (rooms ).hasSize (2 );
129
+ softly .assertThat (rooms ).allMatch (room -> room .getType ().equals (RoomType .VIP_SUITE ));
130
+ softly .assertThat (rooms ).allMatch (room -> room .getStatus ().equals (RoomStatus .AVAILABLE ));
131
+ softly .assertThat (rooms ).allMatch (room -> !room .isUnderMaintenance ());
132
+ });
133
+ }
134
+
135
+ @ Test
136
+ void shouldFindAvailableSmokingRooms () {
137
+ List <Room > rooms = this .repository .findAvailableSmokingRooms ();
138
+ SoftAssertions .assertSoftly (softly -> {
139
+ softly .assertThat (rooms ).hasSize (2 );
140
+ softly .assertThat (rooms ).allMatch (room -> room .isSmokingAllowed ());
141
+ softly .assertThat (rooms ).allMatch (room -> room .getStatus ().equals (RoomStatus .AVAILABLE ));
142
+ });
143
+ }
144
+
145
+ @ Test
146
+ void shouldFindRoomsNeedingCleaning () {
147
+ List <Room > rooms = this .repository .findRoomsNeedingCleaning ();
148
+ SoftAssertions .assertSoftly (softly -> {
149
+ softly .assertThat (rooms ).hasSize (2 );
150
+ softly .assertThat (rooms ).allMatch (room -> !room .getCleanStatus ().equals (CleanStatus .CLEAN ));
151
+ softly .assertThat (rooms ).allMatch (room -> !room .getStatus ().equals (RoomStatus .OUT_OF_SERVICE ));
152
+ });
153
+ }
154
+
155
+ @ ParameterizedTest (name = "should find rooms by type {0}" )
156
+ @ EnumSource (RoomType .class )
157
+ void shouldFindRoomByType (RoomType type ) {
158
+ List <Room > rooms = this .repository .findByType (type );
159
+ SoftAssertions .assertSoftly (softly -> softly .assertThat (rooms ).allMatch (room -> room .getType ().equals (type )));
160
+ }
161
+
162
+ @ ParameterizedTest
163
+ @ MethodSource ("room" )
164
+ void shouldSaveRoom (Room room ) {
165
+ Room updateRoom = this .repository .newRoom (room );
166
+
167
+ SoftAssertions .assertSoftly (softly -> {
168
+ softly .assertThat (updateRoom ).isNotNull ();
169
+ softly .assertThat (updateRoom .getId ()).isNotNull ();
170
+ softly .assertThat (updateRoom .getRoomNumber ()).isEqualTo (room .getRoomNumber ());
171
+ softly .assertThat (updateRoom .getType ()).isEqualTo (room .getType ());
172
+ softly .assertThat (updateRoom .getStatus ()).isEqualTo (room .getStatus ());
173
+ softly .assertThat (updateRoom .getCleanStatus ()).isEqualTo (room .getCleanStatus ());
174
+ softly .assertThat (updateRoom .isSmokingAllowed ()).isEqualTo (room .isSmokingAllowed ());
175
+ });
176
+ }
177
+
178
+ static Stream <Arguments > room () {
179
+ Room room = new RoomBuilder ()
180
+ .roomNumber (101 )
181
+ .type (RoomType .VIP_SUITE )
182
+ .status (RoomStatus .AVAILABLE )
183
+ .cleanStatus (CleanStatus .CLEAN )
184
+ .smokingAllowed (false )
185
+ .build ();
186
+
187
+ return Stream .of (Arguments .of (room ));
188
+ }
158
189
}
0 commit comments