-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProjectTest.java
More file actions
732 lines (647 loc) · 27.9 KB
/
ProjectTest.java
File metadata and controls
732 lines (647 loc) · 27.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
package contactapp.domain;
import java.lang.reflect.Field;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* Tests the Project class.
*
* <p>Verifies:
* <ul>
* <li>Successful creation with valid data</li>
* <li>Updates via setters with valid data</li>
* <li>Invalid inputs cause IllegalArgumentException with specific validation messages</li>
* <li>Atomic update behavior (all-or-nothing)</li>
* </ul>
*
* <p>Tests are in the same package as Project to access package-private methods.
*/
public class ProjectTest {
/**
* Verifies the constructor stores every field when valid data is supplied.
*/
@Test
void testSuccessfulCreation() {
Project project = new Project(
"1",
"Project Alpha",
"A test project",
ProjectStatus.ACTIVE
);
// Check that each field has the expected value for the project object
assertThat(project)
.hasFieldOrPropertyWithValue("projectId", "1")
.hasFieldOrPropertyWithValue("name", "Project Alpha")
.hasFieldOrPropertyWithValue("description", "A test project")
.hasFieldOrPropertyWithValue("status", ProjectStatus.ACTIVE);
}
/**
* Ensures setters accept valid data and mutate the stored state accordingly.
*/
@Test
void testValidSetters() {
Project project = new Project("1", "Project Alpha", "A test project", ProjectStatus.ACTIVE);
project.setName("Project Beta");
project.setDescription("Updated description");
project.setStatus(ProjectStatus.ON_HOLD);
// Check that each field has the updated value for the project object
assertThat(project)
.hasFieldOrPropertyWithValue("name", "Project Beta")
.hasFieldOrPropertyWithValue("description", "Updated description")
.hasFieldOrPropertyWithValue("status", ProjectStatus.ON_HOLD);
}
/**
* Confirms the constructor trims text inputs before persisting them.
*/
@Test
void testConstructorTrimsStoredValues() {
Project project = new Project(
" 100 ",
" Project Alpha ",
" A test project ",
ProjectStatus.ACTIVE
);
assertThat(project.getProjectId()).isEqualTo("100");
assertThat(project.getName()).isEqualTo("Project Alpha");
assertThat(project.getDescription()).isEqualTo("A test project");
}
/**
* Verifies that empty description is allowed (min length = 0).
*/
@Test
void testEmptyDescriptionIsValid() {
Project project = new Project("1", "Project Alpha", "", ProjectStatus.ACTIVE);
assertThat(project.getDescription()).isEmpty();
}
/**
* Verifies that whitespace-only description becomes empty after trimming.
*/
@Test
void testWhitespaceDescriptionBecomesEmpty() {
Project project = new Project("1", "Project Alpha", " ", ProjectStatus.ACTIVE);
assertThat(project.getDescription()).isEmpty();
}
/**
* Enumerates invalid constructor inputs (id, name, description, status).
*/
@CsvSource(
value = {
// projectId validation
"' ', 'Project Alpha', 'A test project', ACTIVE, 'Project ID must not be null or blank'"
, "'', 'Project Alpha', 'A test project', ACTIVE, 'Project ID must not be null or blank'"
, "null, 'Project Alpha', 'A test project', ACTIVE, 'Project ID must not be null or blank'"
, "12345678901, 'Project Alpha', 'A test project', ACTIVE, 'Project ID length must be between 1 and 10'"
// name validation
, "1, ' ', 'A test project', ACTIVE, 'name must not be null or blank'"
, "1, '', 'A test project', ACTIVE, 'name must not be null or blank'"
, "1, null, 'A test project', ACTIVE, 'name must not be null or blank'"
, "1, 'This is a very long project name that exceeds fifty characters', 'A test project', ACTIVE, 'name length must be between 1 and 50'"
// description validation
, "1, 'Project Alpha', null, ACTIVE, 'description must not be null or blank'"
, "1, 'Project Alpha', 'This is a very long description that exceeds one hundred characters and should be rejected by validation logic', ACTIVE, 'description length must be between 0 and 100'"
// status validation
, "1, 'Project Alpha', 'A test project', null, 'status must not be null'"
},
// Specify that the string "null" should be treated as a null value
nullValues = "null"
)
/**
* Verifies the constructor rejects each invalid input combination defined above.
*/
@ParameterizedTest
void testFailedCreation(
String projectId,
String name,
String description,
String statusStr,
String expectedMessage // expected exception message
) {
ProjectStatus status = statusStr == null ? null : ProjectStatus.valueOf(statusStr);
// Check that creating a Project with invalid inputs throws an exception with the expected message
assertThatThrownBy(() -> new Project(projectId, name, description, status))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(expectedMessage);
}
/**
* Drives invalid name values for the setter validation test.
*/
@CsvSource(
value = {
"' ', 'name must not be null or blank'"
, "'', 'name must not be null or blank'"
, "null, 'name must not be null or blank'"
, "'This is a very long project name that exceeds fifty characters', 'name length must be between 1 and 50'"
},
nullValues = "null"
)
/**
* Ensures {@link Project#setName(String)} throws for blank/null/too-long names.
*/
@ParameterizedTest
void testFailedSetName(String invalidName, String expectedMessage) {
Project project = new Project("1", "Project Alpha", "A test project", ProjectStatus.ACTIVE);
// Check that invalid name updates throw the proper exception message
assertThatThrownBy(() -> project.setName(invalidName))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(expectedMessage);
}
/**
* Drives invalid description values for the setter validation test.
*/
@CsvSource(
value = {
"null, 'description must not be null or blank'"
, "'This is a very long description that exceeds one hundred characters and should be rejected by validation logic', 'description length must be between 0 and 100'"
},
nullValues = "null"
)
/**
* Ensures {@link Project#setDescription(String)} throws for null/too-long descriptions.
*/
@ParameterizedTest
void testFailedSetDescription(String invalidDescription, String expectedMessage) {
Project project = new Project("1", "Project Alpha", "A test project", ProjectStatus.ACTIVE);
// Check that invalid description updates throw the proper exception message
assertThatThrownBy(() -> project.setDescription(invalidDescription))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(expectedMessage);
}
/**
* Ensures {@link Project#setStatus(ProjectStatus)} throws for null status.
*/
@Test
void testFailedSetStatus() {
Project project = new Project("1", "Project Alpha", "A test project", ProjectStatus.ACTIVE);
// Check that null status update throws the proper exception message
assertThatThrownBy(() -> project.setStatus(null))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("status must not be null");
}
/**
* Supplies invalid arguments to {@link #testUpdateRejectsInvalidValuesAtomically}.
*/
private static Stream<Arguments> invalidUpdateValues() {
return Stream.of(
Arguments.of(" ", "A test project", ProjectStatus.ACTIVE, "name must not be null or blank"),
Arguments.of("Project Alpha", "This is a very long description that exceeds one hundred characters and should be rejected by validation logic", ProjectStatus.ACTIVE, "description length must be between 0 and 100"),
Arguments.of("Project Alpha", "A test project", null, "status must not be null")
);
}
/**
* Ensures {@link Project#update(String, String, ProjectStatus)} rejects invalid data
* and leaves state unchanged (atomic update behavior).
*/
@ParameterizedTest
@MethodSource("invalidUpdateValues")
void testUpdateRejectsInvalidValuesAtomically(
String newName,
String newDescription,
ProjectStatus newStatus,
String expectedMessage) {
Project project = new Project("1", "Project Alpha", "A test project", ProjectStatus.ACTIVE);
assertThatThrownBy(() -> project.update(newName, newDescription, newStatus))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage(expectedMessage);
assertThat(project)
.hasFieldOrPropertyWithValue("name", "Project Alpha")
.hasFieldOrPropertyWithValue("description", "A test project")
.hasFieldOrPropertyWithValue("status", ProjectStatus.ACTIVE);
}
/**
* Ensures the copy guard rejects corrupted state (null internal fields).
*
* <p>Added to kill PITest mutant: "removed call to validateCopySource" in Project.copy().
* This test uses reflection to corrupt each internal field and verify copy() throws.
* Parameterized to achieve full branch coverage of the validateCopySource null checks.
*/
@ParameterizedTest(name = "copy rejects null {0}")
@MethodSource("nullFieldProvider")
void testCopyRejectsNullInternalState(String fieldName) throws Exception {
Project project = new Project("901", "Project Alpha", "A test project", ProjectStatus.ACTIVE);
// Use reflection to corrupt internal state (simulate memory corruption or serialization bugs)
Field field = Project.class.getDeclaredField(fieldName);
field.setAccessible(true);
field.set(project, null);
assertThatThrownBy(project::copy)
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("project copy source must not be null");
}
/**
* Provides field names for the null internal state test.
*/
static Stream<String> nullFieldProvider() {
return Stream.of("projectId", "name", "description", "status");
}
/**
* Verifies that copy() creates an independent instance with the same values.
*/
@Test
void testCopyCreatesIndependentInstance() {
Project original = new Project("1", "Project Alpha", "A test project", ProjectStatus.ACTIVE);
Project copy = original.copy();
// Verify copy has same values
assertThat(copy)
.hasFieldOrPropertyWithValue("projectId", "1")
.hasFieldOrPropertyWithValue("name", "Project Alpha")
.hasFieldOrPropertyWithValue("description", "A test project")
.hasFieldOrPropertyWithValue("status", ProjectStatus.ACTIVE);
// Verify copy is independent (modifying copy doesn't affect original)
copy.setName("Project Beta");
assertThat(original.getName()).isEqualTo("Project Alpha");
assertThat(copy.getName()).isEqualTo("Project Beta");
}
/**
* Verifies that update() accepts all valid values and mutates state.
*/
@Test
void testUpdateWithValidValues() {
Project project = new Project("1", "Project Alpha", "A test project", ProjectStatus.ACTIVE);
project.update("Project Beta", "Updated description", ProjectStatus.COMPLETED);
assertThat(project)
.hasFieldOrPropertyWithValue("name", "Project Beta")
.hasFieldOrPropertyWithValue("description", "Updated description")
.hasFieldOrPropertyWithValue("status", ProjectStatus.COMPLETED);
}
// ==================== Additional Boundary and Edge Case Tests ====================
/**
* Tests project ID at exact maximum length boundary (10 characters).
*
* <p><b>Why this test exists:</b> Ensures that a project ID with exactly 10 characters
* is accepted. Catches mutants that change {@code >} to {@code >=} in length validation.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary: {@code >} to {@code >=}</li>
* <li>Replaced MAX_ID_LENGTH constant</li>
* </ul>
*/
@Test
void constructor_acceptsProjectIdAtMaximumLength() {
final Project project = new Project("1234567890", "Project Name", "Description", ProjectStatus.ACTIVE);
assertThat(project.getProjectId()).isEqualTo("1234567890");
assertThat(project.getProjectId()).hasSize(10);
}
/**
* Tests project ID one character over maximum length (11 characters).
*
* <p><b>Why this test exists:</b> Ensures that a project ID with 11 characters
* is rejected. Tests the boundary from the rejection side.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary</li>
* <li>Removed length validation</li>
* </ul>
*/
@Test
void constructor_rejectsProjectIdOneOverMaximumLength() {
assertThatThrownBy(() ->
new Project("12345678901", "Project Name", "Description", ProjectStatus.ACTIVE))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Project ID length must be between 1 and 10");
}
/**
* Tests project name at exact maximum length boundary (50 characters).
*
* <p><b>Why this test exists:</b> Ensures that a project name with exactly 50 characters
* is accepted. Tests the upper boundary of name validation.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary in validateLength</li>
* <li>Replaced MAX_PROJECT_NAME_LENGTH constant</li>
* </ul>
*/
@Test
void constructor_acceptsNameAtMaximumLength() {
final String maxName = "12345678901234567890123456789012345678901234567890"; // 50 chars
final Project project = new Project("1", maxName, "Description", ProjectStatus.ACTIVE);
assertThat(project.getName()).isEqualTo(maxName);
assertThat(project.getName()).hasSize(50);
}
/**
* Tests project name one character over maximum length (51 characters).
*
* <p><b>Why this test exists:</b> Ensures that a project name with 51 characters
* is rejected. Tests the boundary from the other side.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary</li>
* <li>Removed validation check</li>
* </ul>
*/
@Test
void constructor_rejectsNameOneOverMaximumLength() {
final String tooLongName = "123456789012345678901234567890123456789012345678901"; // 51 chars
assertThatThrownBy(() ->
new Project("1", tooLongName, "Description", ProjectStatus.ACTIVE))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("name length must be between 1 and 50");
}
/**
* Tests project description at exact maximum length boundary (100 characters).
*
* <p><b>Why this test exists:</b> Ensures that a description with exactly 100 characters
* is accepted. Tests the upper boundary of description validation.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary: {@code >} to {@code >=}</li>
* <li>Replaced MAX_PROJECT_DESCRIPTION_LENGTH constant</li>
* </ul>
*/
@Test
void constructor_acceptsDescriptionAtMaximumLength() {
final String maxDesc = "1234567890".repeat(10); // 100 chars
final Project project = new Project("1", "Project Name", maxDesc, ProjectStatus.ACTIVE);
assertThat(project.getDescription()).isEqualTo(maxDesc);
assertThat(project.getDescription()).hasSize(100);
}
/**
* Tests project description one character over maximum length (101 characters).
*
* <p><b>Why this test exists:</b> Ensures that a description with 101 characters
* is rejected. Tests the boundary from the other side.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary</li>
* <li>Removed validation check</li>
* </ul>
*/
@Test
void constructor_rejectsDescriptionOneOverMaximumLength() {
final String tooLongDesc = "1234567890".repeat(10) + "1"; // 101 chars
assertThatThrownBy(() ->
new Project("1", "Project Name", tooLongDesc, ProjectStatus.ACTIVE))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("description length must be between 0 and 100");
}
/**
* Tests that description can be exactly zero characters (empty string after trimming).
*
* <p><b>Why this test exists:</b> Project description has minLength = 0, which is
* different from other domain objects. This tests the special case where empty
* is allowed. Catches mutants that change {@code minLength == 0} check.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary: {@code minLength == 0} to {@code minLength != 0}</li>
* <li>Removed special case handling for empty descriptions</li>
* </ul>
*/
@Test
void constructor_acceptsEmptyDescriptionAfterTrimming() {
final Project project = new Project("1", "Project Name", "", ProjectStatus.ACTIVE);
assertThat(project.getDescription()).isEmpty();
assertThat(project.getDescription()).hasSize(0);
}
/**
* Tests setName with a name at exact maximum length.
*
* <p><b>Why this test exists:</b> Ensures setName correctly validates and accepts
* a 50-character name through the setter path.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary in setter</li>
* </ul>
*/
@Test
void setName_acceptsNameAtMaximumLength() {
final Project project = new Project("1", "Initial", "Description", ProjectStatus.ACTIVE);
final String maxName = "12345678901234567890123456789012345678901234567890"; // 50 chars
project.setName(maxName);
assertThat(project.getName()).isEqualTo(maxName);
assertThat(project.getName()).hasSize(50);
}
/**
* Tests setName with a single character (minimum length).
*
* <p><b>Why this test exists:</b> Ensures setName accepts the minimum valid
* length (1 character). Tests the lower boundary.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary: {@code <} to {@code <=}</li>
* </ul>
*/
@Test
void setName_acceptsMinimumLengthName() {
final Project project = new Project("1", "Initial", "Description", ProjectStatus.ACTIVE);
project.setName("A");
assertThat(project.getName()).isEqualTo("A");
assertThat(project.getName()).hasSize(1);
}
/**
* Tests setDescription with a description at exact maximum length.
*
* <p><b>Why this test exists:</b> Ensures setDescription correctly validates
* and accepts a 100-character description.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary in setter</li>
* </ul>
*/
@Test
void setDescription_acceptsDescriptionAtMaximumLength() {
final Project project = new Project("1", "Project", "Initial", ProjectStatus.ACTIVE);
final String maxDesc = "1234567890".repeat(10); // 100 chars
project.setDescription(maxDesc);
assertThat(project.getDescription()).isEqualTo(maxDesc);
assertThat(project.getDescription()).hasSize(100);
}
/**
* Tests setDescription with empty string (minimum length = 0).
*
* <p><b>Why this test exists:</b> Ensures setDescription accepts empty string
* since description has minLength = 0. Tests the special lower boundary.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional check for empty description</li>
* <li>Removed special case for minLength == 0</li>
* </ul>
*/
@Test
void setDescription_acceptsEmptyDescription() {
final Project project = new Project("1", "Project", "Initial", ProjectStatus.ACTIVE);
project.setDescription("");
assertThat(project.getDescription()).isEmpty();
assertThat(project.getDescription()).hasSize(0);
}
/**
* Tests update() with maximum length values for name and description.
*
* <p><b>Why this test exists:</b> Ensures atomic update works correctly when
* both fields are at their maximum length boundaries.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed conditional boundary in update validation</li>
* <li>Swapped field assignments</li>
* </ul>
*/
@Test
void update_acceptsMaximumLengthValues() {
final Project project = new Project("1", "Old", "Old desc", ProjectStatus.ACTIVE);
final String maxName = "12345678901234567890123456789012345678901234567890"; // 50 chars
final String maxDesc = "1234567890".repeat(10); // 100 chars
project.update(maxName, maxDesc, ProjectStatus.COMPLETED);
assertThat(project.getName()).isEqualTo(maxName);
assertThat(project.getDescription()).isEqualTo(maxDesc);
assertThat(project.getStatus()).isEqualTo(ProjectStatus.COMPLETED);
}
/**
* Tests update() with empty description.
*
* <p><b>Why this test exists:</b> Ensures update() correctly handles the special
* case of empty description (minLength = 0).
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed empty description handling in update</li>
* </ul>
*/
@Test
void update_acceptsEmptyDescription() {
final Project project = new Project("1", "Old", "Old desc", ProjectStatus.ACTIVE);
project.update("New Name", "", ProjectStatus.ON_HOLD);
assertThat(project.getName()).isEqualTo("New Name");
assertThat(project.getDescription()).isEmpty();
assertThat(project.getStatus()).isEqualTo(ProjectStatus.ON_HOLD);
}
/**
* Tests that setStatus actually updates the status value.
*
* <p><b>Why this test exists:</b> Ensures setStatus correctly assigns the new
* status. Catches mutants that don't assign or assign wrong value.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Removed assignment in setStatus</li>
* <li>Assigned wrong status value</li>
* </ul>
*/
@Test
void setStatus_updatesStatusCorrectly() {
final Project project = new Project("1", "Project", "Desc", ProjectStatus.ACTIVE);
project.setStatus(ProjectStatus.ARCHIVED);
assertThat(project.getStatus()).isEqualTo(ProjectStatus.ARCHIVED);
assertThat(project.getStatus()).isNotEqualTo(ProjectStatus.ACTIVE);
}
/**
* Tests all possible ProjectStatus enum values can be set.
*
* <p><b>Why this test exists:</b> Ensures all enum values are valid and can be
* set without errors. Tests that no enum values are accidentally rejected.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Added validation that rejects specific enum values</li>
* </ul>
*/
@Test
void constructor_acceptsAllProjectStatusValues() {
// Test each enum value
assertThatNoException().isThrownBy(() ->
new Project("1", "Project", "Desc", ProjectStatus.ACTIVE));
assertThatNoException().isThrownBy(() ->
new Project("2", "Project", "Desc", ProjectStatus.ON_HOLD));
assertThatNoException().isThrownBy(() ->
new Project("3", "Project", "Desc", ProjectStatus.COMPLETED));
assertThatNoException().isThrownBy(() ->
new Project("4", "Project", "Desc", ProjectStatus.ARCHIVED));
}
/**
* Tests copy() with a project that has an empty description.
*
* <p><b>Why this test exists:</b> Ensures copy() correctly handles the special
* case of empty description (minLength = 0).
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Changed empty description handling in copy</li>
* <li>Failed to copy empty description</li>
* </ul>
*/
@Test
void copy_handlesEmptyDescriptionCorrectly() {
final Project original = new Project("99", "Project Name", "", ProjectStatus.ACTIVE);
final Project copy = original.copy();
assertThat(copy.getDescription()).isEmpty();
assertThat(copy.getDescription()).hasSize(0);
assertThat(copy).isNotSameAs(original);
}
/**
* Tests that modifying a copy doesn't affect the original project.
*
* <p><b>Why this test exists:</b> Ensures copy() creates a true independent copy
* without shared mutable state.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Returned 'this' instead of new instance</li>
* </ul>
*/
@Test
void copy_modificationsToopyDontAffectOriginal() {
final Project original = new Project("99", "Project Alpha", "Description", ProjectStatus.ACTIVE);
final Project copy = original.copy();
// Modify the copy
copy.setName("Project Beta");
copy.setDescription("New Description");
copy.setStatus(ProjectStatus.COMPLETED);
// Verify original is unchanged
assertThat(original.getName()).isEqualTo("Project Alpha");
assertThat(original.getDescription()).isEqualTo("Description");
assertThat(original.getStatus()).isEqualTo(ProjectStatus.ACTIVE);
}
/**
* Tests that validateAndTrimText correctly trims input before validation.
*
* <p><b>Why this test exists:</b> Ensures leading/trailing whitespace is removed
* before length validation. A string with spaces that becomes valid after trimming
* should be accepted.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Removed trim() call before validation</li>
* <li>Validated before trimming</li>
* </ul>
*/
@Test
void constructor_trimsNameBeforeValidation() {
final Project project = new Project("1", " ProjectName ", "Desc", ProjectStatus.ACTIVE);
// Name should be trimmed
assertThat(project.getName()).isEqualTo("ProjectName");
assertThat(project.getName()).doesNotStartWith(" ");
assertThat(project.getName()).doesNotEndWith(" ");
}
/**
* Tests that description is trimmed even when it becomes empty.
*
* <p><b>Why this test exists:</b> Ensures whitespace-only description becomes
* empty after trimming, which is valid since minLength = 0.
*
* <p><b>Mutants killed:</b>
* <ul>
* <li>Removed trim() call for description</li>
* <li>Changed empty handling after trim</li>
* </ul>
*/
@Test
void constructor_trimsWhitespaceDescriptionToEmpty() {
final Project project = new Project("1", "Project", " ", ProjectStatus.ACTIVE);
// Whitespace-only description should become empty after trim
assertThat(project.getDescription()).isEmpty();
}
}