Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 0b244cd2

Přidáno uživatelem Dominik Poch před téměř 6 roky(ů)

Final version of the class VacationDay with its tests

Zobrazit rozdíly:

server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java
23 23
    /**
24 24
     * The ID of this vacation.
25 25
     */
26
    private final long id;
26
    private Long id;
27 27

  
28 28
    /**
29 29
     * The date of this vacation.
......
43 43
    /**
44 44
     * The date and time of a creation of this vacation.
45 45
     */
46
    private final LocalDateTime creationDate;
46
    private LocalDateTime creationDate;
47 47

  
48 48
    /**
49 49
     * The approval status of this vacation.
......
56 56
    private VacationType type;
57 57

  
58 58
    /**
59
     * Creates an empty vacation for testing purposes only.
60
     * It just sets id to zero and creation date to nowte.
61
     */
62
    public VacationDay() {
63
        VacationDay.log.trace("Creating a new instance of the class VacationDay.");
64
        this.id = 0;
65
        this.creationDate = LocalDateTime.now();
66
    }
67

  
68
    /**
69
     * Creates a new sick day with the specified id, date, date when a sick day request was created and its approval status.
70
     *
71
     * @param id           the ID of the sick day
72
     * @param date         the date of the sick day
73
     * @param creationDate the date and time of the creation of the sick day
74
     * @param status       the approval status of the sick day
75
     */
76
    public VacationDay(final long id, final LocalDate date, final LocalDateTime creationDate, final Status status) {
77
        this(id, date, null, null, creationDate, status, VacationType.SICK_DAY);
78
    }
79

  
80
    /**
81
     * Creates a new overtime with the specified id, date, starting time, ending time, date when an overtime request was created and its approval status.
82
     *
83
     * @param id           the ID of the overtime
84
     * @param date         the date of the overtime
85
     * @param from         the starting time of the overtime
86
     * @param to           the ending time of the overtime
87
     * @param creationDate the date and time of the creation of the overtime
88
     * @param status       the approval status of the overtime
89
     */
90
    public VacationDay(final long id, final LocalDate date, final LocalTime from, final LocalTime to, final LocalDateTime creationDate, final Status status) {
91
        this(id, date, from, to, creationDate, status, VacationType.VACATION);
92
    }
93

  
94
    /**
95
     * Creates a new overtime or sick day with attributes known during insertion.
59
     * Returns the ID of this vacation.
96 60
     *
97
     * @param date         the date of a vacation
98
     * @param from         the starting time of a vacation
99
     * @param to           the ending time of a vacation
100
     * @param status       the approval status of a vacation
101
     * @param type         the type of a vacation
61
     * @return the ID of this vacation
102 62
     */
103
    public VacationDay(final LocalDate date, final LocalTime from, final LocalTime to, final Status status, final VacationType type) {
104
        this(0, date, from, to, null, status, type);
63
    public long getId() {
64
        return this.id;
105 65
    }
106 66

  
107 67
    /**
108
     * Creates a new overtime or sick day with all attributes.
68
     * Replaces the ID of this vacation with the given one.
109 69
     *
110
     * @param id           the ID of a vacation
111
     * @param date         the date of a vacation
112
     * @param from         the starting time of a vacation
113
     * @param to           the ending time of a vacation
114
     * @param creationDate the date and time of a creation of a vacation
115
     * @param status       the approval status of a vacation
116
     * @param type         the type of a vacation
70
     * @param id the given ID
117 71
     */
118
    public VacationDay(final long id, final LocalDate date, final LocalTime from, final LocalTime to, final LocalDateTime creationDate, final Status status, final VacationType type) {
119
        VacationDay.log.trace("Creating a new instance of the class VacationDay.");
120
        VacationDay.log.debug("VacationDay: id={}, date={}, from={}, to={}, creationDate={}, status={}, type={}", id, date, from, to, creationDate, status, type);
72
    public void setId(final Long id) {
73
        VacationDay.log.debug("Setting a new id: {}", id);
121 74

  
122 75
        this.id = id;
123
        this.setDate(date);
124
        this.setType(type);
125
        this.setTime(from, to);
126
        this.creationDate = creationDate;
127
        this.setStatus(status);
128
    }
129

  
130
    /**
131
     * Returns the ID of this vacation.
132
     *
133
     * @return the ID of this vacation
134
     */
135
    public long getId() {
136
        return this.id;
137 76
    }
138 77

  
139 78
    /**
......
264 203
        return this.creationDate;
265 204
    }
266 205

  
206
    /**
207
     * Replaces the creation date of this vacation with the given date and time.
208
     *
209
     * @param creationDate the new creation date
210
     */
211
    public void setCreationDate(final LocalDateTime creationDate) {
212
        VacationDay.log.debug("Setting a new creation date of this vacation: {}", creationDate);
213

  
214
        this.creationDate = creationDate;
215
    }
216

  
267 217
    /**
268 218
     * Returns the approval status of this vacation.
269 219
     *
......
332 282
        return "VacationDay{" +
333 283
                "id=" + this.id +
334 284
                ", date=" + this.date +
335
                ", from=" + String.valueOf(this.from) +
336
                ", to=" + String.valueOf(this.to) +
285
                ", from=" + this.from +
286
                ", to=" + this.to +
337 287
                ", creationDate=" + this.creationDate +
338 288
                ", status=" + this.status +
339 289
                ", type=" + this.type +
server/src/test/java/cz/zcu/yamanager/domain/VacationDayTest.java
1 1
package cz.zcu.yamanager.domain;
2 2

  
3 3
import cz.zcu.yamanager.dto.Status;
4
import cz.zcu.yamanager.dto.VacationType;
4 5
import org.junit.jupiter.api.BeforeEach;
5 6
import org.junit.jupiter.api.Test;
6 7

  
......
28 29
        this.vacationDay = new VacationDay();
29 30
    }
30 31

  
32
    /**
33
     * Tests the method {@code setDate} with common values where no problem should occur.
34
     */
35
    @Test
36
    void setDate_valid() {
37
        LocalDate date = LocalDate.of(2000,10,12);
38
        this.vacationDay.setDate(date);
39
        assertEquals(date, this.vacationDay.getDate());
40
    }
41

  
42
    /**
43
     * Tests the method {@code setDate} with null input value.
44
     */
45
    @Test
46
    void setDate_nullInput() {
47
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setDate(null));
48
    }
49

  
50
    /**
51
     * Tests the method {@code setFrom} with a null input, null ending time and null vacation type.
52
     */
53
    @Test
54
    void setFrom_nullFrom_nullTo_nullType_valid() {
55
        this.vacationDay.setFrom(null);
56
        assertNull(this.vacationDay.getFrom());
57
    }
58

  
59
    /**
60
     * Tests the method {@code setFrom} with a null input, ending time and null vacation type.
61
     */
62
    @Test
63
    void setFrom_nullFrom_to_nullType_valid() {
64
        this.vacationDay.setTo(LocalTime.of(20, 0));
65
        this.vacationDay.setFrom(null);
66
        assertNull(this.vacationDay.getFrom());
67
    }
68

  
69
    /**
70
     * Tests the method {@code setFrom} with an input, null ending time and null vacation type.
71
     */
72
    @Test
73
    void setFrom_from_nullTo_nullType_valid() {
74
        LocalTime from = LocalTime.of(10,0);
75
        this.vacationDay.setFrom(from);
76
        assertEquals(from, this.vacationDay.getFrom());
77
    }
78

  
79
    /**
80
     * Tests the method {@code setFrom} with an input, ending time and null vacation type.
81
     */
82
    @Test
83
    void setFrom_from_to_nullType_valid() {
84
        LocalTime to = LocalTime.of(20, 0);
85
        this.vacationDay.setTo(to);
86
        LocalTime from = LocalTime.of(10,0);
87
        this.vacationDay.setFrom(from);
88
        assertEquals(from, this.vacationDay.getFrom());
89
    }
90

  
91
    /**
92
     * Tests the method {@code setFrom} with same input and ending time and null vacation type.
93
     */
94
    @Test
95
    void setFrom_from_to_nullType_same() {
96
        LocalTime to = LocalTime.of(10, 0);
97
        this.vacationDay.setTo(to);
98
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(to));
99
    }
100

  
101
    /**
102
     * Tests the method {@code setFrom} with same input and ending time and null vacation type.
103
     */
104
    @Test
105
    void setFrom_from_to_nullType_wrongOrder() {
106
        LocalTime to = LocalTime.of(10, 0);
107
        this.vacationDay.setTo(to);
108
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(LocalTime.of(20,0)));
109
    }
110

  
111
    /**
112
     * Tests the method {@code setFrom} with a null input, null ending time and sick day vacation type.
113
     */
114
    @Test
115
    void setFrom_nullFrom_nullTo_sickDay_valid() {
116
        this.vacationDay.setType(VacationType.SICK_DAY);
117
        this.vacationDay.setFrom(null);
118
        assertNull(this.vacationDay.getFrom());
119
    }
120

  
121
    /**
122
     * Tests the method {@code setFrom} with an input and sick day vacation type.
123
     */
124
    @Test
125
    void setFrom_from_sickDay() {
126
        this.vacationDay.setType(VacationType.SICK_DAY);
127
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(LocalTime.of(20,0)));
128
    }
129

  
130
    /**
131
     * Tests the method {@code setFrom} with a null input, null ending time and vacation vacation type.
132
     */
133
    @Test
134
    void setFrom_nullFrom_vacation_valid() {
135
        this.vacationDay.setFrom(null);
136
        assertNull(this.vacationDay.getFrom());
137
    }
138

  
139
    /**
140
     * Tests the method {@code setFrom} with an input, null ending time and vacation vacation type.
141
     */
142
    @Test
143
    void setFrom_from_nullTo_vacation_valid() {
144
        this.vacationDay.setType(VacationType.VACATION);
145
        LocalTime from = LocalTime.of(10,0);
146
        this.vacationDay.setFrom(from);
147
        assertEquals(from, this.vacationDay.getFrom());
148
    }
149

  
150
    /**
151
     * Tests the method {@code setFrom} with an input, ending time and vacation vacation type.
152
     */
153
    @Test
154
    void setFrom_from_to_vacation_valid() {
155
        this.vacationDay.setType(VacationType.VACATION);
156
        LocalTime to = LocalTime.of(20, 0);
157
        this.vacationDay.setTo(to);
158
        LocalTime from = LocalTime.of(10,0);
159
        this.vacationDay.setFrom(from);
160
        assertEquals(from, this.vacationDay.getFrom());
161
    }
162

  
163
    /**
164
     * Tests the method {@code setFrom} with same input and ending time and vacation vacation type.
165
     */
166
    @Test
167
    void setFrom_from_to_vacation_same() {
168
        this.vacationDay.setType(VacationType.VACATION);
169
        LocalTime to = LocalTime.of(10, 0);
170
        this.vacationDay.setTo(to);
171
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(LocalTime.of(10,0)));
172
    }
173

  
174
    /**
175
     * Tests the method {@code setFrom} with same input and ending time and vacation vacation type.
176
     */
177
    @Test
178
    void setFrom_from_to_vacation_wrongOrder() {
179
        this.vacationDay.setType(VacationType.VACATION);
180
        LocalTime to = LocalTime.of(10, 0);
181
        this.vacationDay.setTo(to);
182
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(LocalTime.of(20,0)));
183
    }
184

  
185
    /**
186
     * Tests the method {@code setTo} with a null input, null starting time and null vacation type.
187
     */
188
    @Test
189
    void setTo_nullTo_nullFrom_nullType_valid() {
190
        this.vacationDay.setTo(null);
191
        assertNull(this.vacationDay.getTo());
192
    }
193

  
194
    /**
195
     * Tests the method {@code setTo} with a null input, starting time and null vacation type.
196
     */
197
    @Test
198
    void setTo_nullTo_from_nullType_valid() {
199
        this.vacationDay.setFrom(LocalTime.of(20, 0));
200
        this.vacationDay.setTo(null);
201
        assertNull(this.vacationDay.getTo());
202
    }
203

  
204
    /**
205
     * Tests the method {@code setTo} with an input, null starting time and null vacation type.
206
     */
207
    @Test
208
    void setTo_to_nullFrom_nullType_valid() {
209
        LocalTime to = LocalTime.of(10,0);
210
        this.vacationDay.setTo(to);
211
        assertEquals(to, this.vacationDay.getTo());
212
    }
213

  
214
    /**
215
     * Tests the method {@code setTo} with an input, starting time and null vacation type.
216
     */
217
    @Test
218
    void setTo_to_from_nullType_valid() {
219
        LocalTime from = LocalTime.of(10, 0);
220
        this.vacationDay.setFrom(from);
221
        LocalTime to = LocalTime.of(20,0);
222
        this.vacationDay.setTo(to);
223
        assertEquals(to, this.vacationDay.getTo());
224
    }
225

  
226
    /**
227
     * Tests the method {@code setTo} with same input and starting time and null vacation type.
228
     */
229
    @Test
230
    void setTo_to_from_nullType_same() {
231
        LocalTime from = LocalTime.of(10, 0);
232
        this.vacationDay.setFrom(from);
233
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(LocalTime.of(10,0)));
234
    }
235

  
236
    /**
237
     * Tests the method {@code setTo} with same input and starting time and null vacation type.
238
     */
239
    @Test
240
    void setTo_to_from_nullType_wrongOrder() {
241
        LocalTime from = LocalTime.of(20, 0);
242
        this.vacationDay.setFrom(from);
243
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(LocalTime.of(10,0)));
244
    }
245

  
246
    /**
247
     * Tests the method {@code setTo} with a null input, null starting time and sick day vacation type.
248
     */
249
    @Test
250
    void setTo_nullTo_nullFrom_sickDay_valid() {
251
        this.vacationDay.setType(VacationType.SICK_DAY);
252
        this.vacationDay.setTo(null);
253
        assertNull(this.vacationDay.getTo());
254
    }
255

  
256
    /**
257
     * Tests the method {@code setTo} with an input and sick day vacation type.
258
     */
259
    @Test
260
    void setTo_to_sickDay() {
261
        this.vacationDay.setType(VacationType.SICK_DAY);
262
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(LocalTime.of(20,0)));
263
    }
264

  
265
    /**
266
     * Tests the method {@code setTo} with a null input, null starting time and vacation vacation type.
267
     */
268
    @Test
269
    void setTo_nullTo_vacation_valid() {
270
        this.vacationDay.setTo(null);
271
        assertNull(this.vacationDay.getTo());
272
    }
273

  
274
    /**
275
     * Tests the method {@code setTo} with an input, null starting time and vacation vacation type.
276
     */
277
    @Test
278
    void setTo_to_nullFrom_vacation_valid() {
279
        this.vacationDay.setType(VacationType.VACATION);
280
        LocalTime to = LocalTime.of(10,0);
281
        this.vacationDay.setTo(to);
282
        assertEquals(to, this.vacationDay.getTo());
283
    }
284

  
285
    /**
286
     * Tests the method {@code setTo} with an input, starting time and vacation vacation type.
287
     */
288
    @Test
289
    void setTo_to_from_vacation_valid() {
290
        this.vacationDay.setType(VacationType.VACATION);
291
        LocalTime from = LocalTime.of(10, 0);
292
        this.vacationDay.setFrom(from);
293
        LocalTime to = LocalTime.of(20,0);
294
        this.vacationDay.setTo(to);
295
        assertEquals(to, this.vacationDay.getTo());
296
    }
297

  
298
    /**
299
     * Tests the method {@code setTo} with same input and starting time and vacation vacation type.
300
     */
301
    @Test
302
    void setTo_to_from_vacation_same() {
303
        this.vacationDay.setType(VacationType.VACATION);
304
        LocalTime from = LocalTime.of(10, 0);
305
        this.vacationDay.setFrom(from);
306
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(from));
307
    }
308

  
309
    /**
310
     * Tests the method {@code setTo} with same input and starting time and vacation vacation type.
311
     */
312
    @Test
313
    void setTo_to_from_vacation_wrongOrder() {
314
        this.vacationDay.setType(VacationType.VACATION);
315
        LocalTime from = LocalTime.of(20, 0);
316
        this.vacationDay.setFrom(from);
317
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(LocalTime.of(10,0)));
318
    }
319

  
31 320
    /**
32 321
     * Tests the method {@code setTime} with common values where no problem should occur.
33 322
     */
34 323
    @Test
35
    void testSetTime() {
324
    void setTime_nullType_valid() {
36 325
        LocalTime from = LocalTime.of(10,0);
37 326
        LocalTime to = LocalTime.of(20,0);
38 327
        this.vacationDay.setTime(from, to);
......
44 333
     * Tests the method {@code setTime} with the same times.
45 334
     */
46 335
    @Test
47
    void testSetTimeSame() {
336
    void setTime_nullType_same() {
48 337
        LocalTime from = LocalTime.of(10,0);
49 338
        LocalTime to = LocalTime.of(10,0);
50 339
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(from, to));
......
54 343
     * Tests the method {@code setTime} with later start.
55 344
     */
56 345
    @Test
57
    void testSetTimeLater() {
346
    void setTime_nullType_wrongOrder() {
58 347
        LocalTime from = LocalTime.of(20,0);
59 348
        LocalTime to = LocalTime.of(10,0);
60 349
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(from, to));
......
64 353
     * Tests the method {@code setTime} with null {@code from} input.
65 354
     */
66 355
    @Test
67
    void testSetTimeNullFrom() {
356
    void setTime_nullFrom_nullType_valid() {
68 357
        LocalTime to = LocalTime.of(10,0);
69 358
        this.vacationDay.setTime(null, to);
70 359
        assertNull(this.vacationDay.getFrom());
......
75 364
     * Tests the method {@code setTime} with null {@code to} input.
76 365
     */
77 366
    @Test
78
    void testSetTimeNullTo() {
367
    void setTime_nullTo_nullType_valid() {
79 368
        LocalTime from = LocalTime.of(20,0);
80 369
        this.vacationDay.setTime(from, null);
81 370
        assertNull(this.vacationDay.getTo());
......
86 375
     * Tests the method {@code setTime} with null input.
87 376
     */
88 377
    @Test
89
    void setSetTimeNull() {
378
    void setTime_nullFrom_nullTo_nullType_valid() {
90 379
        this.vacationDay.setTime(null, null);
91 380
        assertNull(this.vacationDay.getFrom());
92 381
        assertNull(this.vacationDay.getTo());
93 382
    }
94 383

  
95 384
    /**
96
     * Tests the method {@code setFrom} with common values where no problem should occur.
385
     * Tests the method {@code setTime} with null input and sick day vacation type.
97 386
     */
98 387
    @Test
99
    void testSetFrom() {
100
        LocalTime to = LocalTime.of(20, 0);
101
        this.vacationDay.setTo(to);
102
        LocalTime from = LocalTime.of(10,0);
103
        this.vacationDay.setFrom(from);
104
        assertEquals(from, this.vacationDay.getFrom());
388
    void setTime_nullFrom_nullTo_sickDay_valid() {
389
        this.vacationDay.setType(VacationType.SICK_DAY);
390
        this.vacationDay.setTime(null, null);
391
        assertNull(this.vacationDay.getFrom());
392
        assertNull(this.vacationDay.getTo());
105 393
    }
106 394

  
107 395
    /**
108
     * Tests the method {@code setFrom} when ending time is null.
396
     * Tests the method {@code setTime} with from, null to and sick day vacation type.
109 397
     */
110 398
    @Test
111
    void testSetFromNull() {
112
        LocalTime from = LocalTime.of(10,0);
113
        this.vacationDay.setFrom(from);
114
        assertEquals(from, this.vacationDay.getFrom());
399
    void setTime_from_nullTo_sickDay() {
400
        this.vacationDay.setType(VacationType.SICK_DAY);
401
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(LocalTime.of(10,0), null));
115 402
    }
116 403

  
117 404
    /**
118
     * Tests the method {@code setFrom} with the same times.
405
     * Tests the method {@code setTime} with null from, to and sick day vacation type.
119 406
     */
120 407
    @Test
121
    void testSetFromSame() {
122
        LocalTime to = LocalTime.of(10, 0);
123
        this.vacationDay.setTo(to);
124
        LocalTime from = LocalTime.of(10,0);
125
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(from));
408
    void setTime_nullFrom_to_sickDay() {
409
        this.vacationDay.setType(VacationType.SICK_DAY);
410
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(null, LocalTime.of(10,0)));
126 411
    }
127 412

  
128 413
    /**
129
     * Tests the method {@code setFrom} with later start.
414
     * Tests the method {@code setTime} with from, to and sick day vacation type.
130 415
     */
131 416
    @Test
132
    void testSetFromLater() {
133
        LocalTime to = LocalTime.of(10, 0);
134
        this.vacationDay.setTo(to);
135
        LocalTime from = LocalTime.of(20,0);
136
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setFrom(from));
417
    void setTime_from_to_sickDay() {
418
        this.vacationDay.setType(VacationType.SICK_DAY);
419
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(LocalTime.of(10,0), LocalTime.of(20,0)));
137 420
    }
138 421

  
139 422
    /**
140
     * Tests the method {@code setFrom} with a null input.
423
     * Tests the method {@code setTime} with null input and vacation vacation type.
141 424
     */
142 425
    @Test
143
    void testSetFromNullInput() {
144
        this.vacationDay.setFrom(null);
145
        assertNull(this.vacationDay.getFrom());
426
    void setTime_nullFrom_nullTo_vacation() {
427
        this.vacationDay.setType(VacationType.VACATION);
428
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(null, null));
146 429
    }
147 430

  
148 431
    /**
149
     * Tests the method {@code setTo} with common values where no problem should occur.
432
     * Tests the method {@code setTime} with from, null to and vacation vacation type.
150 433
     */
151 434
    @Test
152
    void testSetTo() {
153
        LocalTime from = LocalTime.of(10,0);
154
        this.vacationDay.setFrom(from);
155
        LocalTime to = LocalTime.of(20, 0);
156
        this.vacationDay.setTo(to);
157
        assertEquals(to, this.vacationDay.getTo());
435
    void setTime_from_nullTo_vacation() {
436
        this.vacationDay.setType(VacationType.VACATION);
437
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(LocalTime.of(10,0), null));
158 438
    }
159 439

  
160 440
    /**
161
     * Tests the method {@code setTo} when starting time is null.
441
     * Tests the method {@code setTime} with null from, to and vacation vacation type.
162 442
     */
163 443
    @Test
164
    void testSetToNull() {
165
        LocalTime to = LocalTime.of(10,0);
166
        this.vacationDay.setTo(to);
444
    void setTime_nullFrom_to_vacation() {
445
        this.vacationDay.setType(VacationType.VACATION);
446
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(null, LocalTime.of(10,0)));
447
    }
448

  
449
    /**
450
     * Tests the method {@code setTime} with from, to and vacation vacation type.
451
     */
452
    @Test
453
    void setTime_from_to_vacation_valid() {
454
        this.vacationDay.setType(VacationType.VACATION);
455
        LocalTime from = LocalTime.of(10,0);
456
        LocalTime to = LocalTime.of(20,0);
457
        this.vacationDay.setTime(from, to);
458
        assertEquals(from, this.vacationDay.getFrom());
167 459
        assertEquals(to, this.vacationDay.getTo());
168 460
    }
169 461

  
170 462
    /**
171
     * Tests the method {@code setTo} with the same times.
463
     * Tests the method {@code setTime} with same from and to and vacation vacation type.
172 464
     */
173 465
    @Test
174
    void testSetToSame() {
466
    void setTime_from_to_vacation_same() {
467
        this.vacationDay.setType(VacationType.VACATION);
175 468
        LocalTime from = LocalTime.of(10,0);
176
        this.vacationDay.setFrom(from);
177
        LocalTime to = LocalTime.of(10, 0);
178
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(to));
469
        LocalTime to = LocalTime.of(10,0);
470
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(from, to));
179 471
    }
180 472

  
181 473
    /**
182
     * Tests the method {@code setTo} with earlier end.
474
     * Tests the method {@code setTime} with later from than to and vacation vacation type.
183 475
     */
184 476
    @Test
185
    void testSetToEarlier() {
477
    void setTime_from_to_vacation_wrongOrder() {
478
        this.vacationDay.setType(VacationType.VACATION);
186 479
        LocalTime from = LocalTime.of(20,0);
187
        this.vacationDay.setFrom(from);
188
        LocalTime to = LocalTime.of(10, 0);
189
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTo(to));
480
        LocalTime to = LocalTime.of(10,0);
481
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setTime(from, to));
190 482
    }
191 483

  
192 484
    /**
193
     * Tests the method {@code setTo} with a null input.
485
     * Tests the method {@code setStatus} with common values where no problem should occur.
194 486
     */
195 487
    @Test
196
    void testSetToNullInput() {
197
        this.vacationDay.setTo(null);
488
    void setStatus_valid() {
489
        this.vacationDay.setStatus(Status.ACCEPTED);
490
        assertEquals(Status.ACCEPTED, this.vacationDay.getStatus());
491
    }
492

  
493
    /**
494
     * Tests the method {@code setStatus} with null value.
495
     */
496
    @Test
497
    void setStatus_nullInput() {
498
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setStatus(null));
499
    }
500

  
501
    /**
502
     * Tests the method {@code setType} with with vacation input.
503
     */
504
    @Test
505
    void setType_valid() {
506
        this.vacationDay.setType(VacationType.VACATION);
507
        assertEquals(VacationType.VACATION, this.vacationDay.getType());
508
    }
509

  
510
    /**
511
     * Tests the method {@code setType} with sick day input.
512
     */
513
    @Test
514
    void setType_sickDay_valid() {
515
        this.vacationDay.setType(VacationType.SICK_DAY);
516
        assertEquals(VacationType.SICK_DAY, this.vacationDay.getType());
517
        assertNull(this.vacationDay.getFrom());
198 518
        assertNull(this.vacationDay.getTo());
199 519
    }
200 520

  
201 521
    /**
202
     * Tests the method {@code toString} for a vacation.
522
     * Tests the method {@code setType} with null value.
523
     */
524
    @Test
525
    void setType_nullInput() {
526
        assertThrows(IllegalArgumentException.class, () -> this.vacationDay.setType(null));
527
    }
528

  
529
    /**
530
     * Tests the method {@code toString}.
203 531
     */
204 532
    @Test
205
    void testToStringVacation() {
206
        VacationDay vacationDay = new VacationDay(5, LocalDate.of(2010,1,9), LocalTime.of(12,15), LocalTime.of(22,30), LocalDateTime.of(2008,10,30,20,0), Status.ACCEPTED);
533
    void toString_valid() {
534
        VacationDay vacationDay = new VacationDay();
535
        vacationDay.setId(5L);
536
        vacationDay.setDate(LocalDate.of(2010,1,9));
537
        vacationDay.setFrom(LocalTime.of(12,15));
538
        vacationDay.setTo(LocalTime.of(22,30));
539
        vacationDay.setCreationDate(LocalDateTime.of(2008,10,30,20,0));
540
        vacationDay.setStatus(Status.ACCEPTED);
541
        vacationDay.setType(VacationType.VACATION);
207 542
        assertEquals("VacationDay{id=5, date=2010-01-09, from=12:15, to=22:30, creationDate=2008-10-30T20:00, status=ACCEPTED, type=VACATION}", vacationDay.toString());
208 543
    }
209 544

  
......
211 546
     * Tests the method {@code toString} for a sick day.
212 547
     */
213 548
    @Test
214
    void testToStringSickDay() {
215
        VacationDay vacationDay = new VacationDay(5, LocalDate.of(2010,1,9), LocalDateTime.of(2008,10,30,20,0), Status.ACCEPTED);
216
        assertEquals("VacationDay{id=5, date=2010-01-09, from=null, to=null, creationDate=2008-10-30T20:00, status=ACCEPTED, type=SICK_DAY}", vacationDay.toString());
549
    void toString_null() {
550
        VacationDay vacationDay = new VacationDay();
551
        assertEquals("VacationDay{id=null, date=null, from=null, to=null, creationDate=null, status=null, type=null}", vacationDay.toString());
217 552
    }
218 553
}

Také k dispozici: Unified diff