Revize da24dbb4
Přidáno uživatelem Dominik Poch před téměř 6 roky(ů)
server/src/main/java/cz/zcu/yamanager/domain/DefaultSettings.java | ||
---|---|---|
20 | 20 |
/** |
21 | 21 |
* The ID of default settings. |
22 | 22 |
*/ |
23 |
private final long id;
|
|
23 |
private Long id;
|
|
24 | 24 |
|
25 | 25 |
/** |
26 | 26 |
* The default number of available sick days. |
27 | 27 |
*/ |
28 |
private int sickDayCount;
|
|
28 |
private Integer sickDayCount;
|
|
29 | 29 |
|
30 | 30 |
/** |
31 | 31 |
* The default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days. |
... | ... | |
33 | 33 |
private LocalDateTime notification; |
34 | 34 |
|
35 | 35 |
/** |
36 |
* Creates an empty default settings for testing purposes only. |
|
37 |
* It just sets id to zero. |
|
38 |
*/ |
|
39 |
public DefaultSettings() { |
|
40 |
DefaultSettings.log.trace("Creating a new instance of the class DefaultSettings."); |
|
41 |
this.id = 0; |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Creates a new default settings with the specified number of available sick days, date and time of a notification. |
|
36 |
* Returns the ID of this default settings. |
|
46 | 37 |
* |
47 |
* @param sickDayCount the default number of available sick days |
|
48 |
* @param notification the default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days |
|
49 |
* @throws IllegalArgumentException when the given sickDayCount value is negative |
|
38 |
* @return the ID of this default settings |
|
50 | 39 |
*/ |
51 |
public DefaultSettings(final Integer sickDayCount, final LocalDateTime notification) throws IllegalArgumentException {
|
|
52 |
this(0, sickDayCount, notification);
|
|
40 |
public Long getId() {
|
|
41 |
return this.id;
|
|
53 | 42 |
} |
54 | 43 |
|
55 | 44 |
/** |
56 |
* Creates a new default settings with the specified id, number of available sick days, date and time of a notification.
|
|
45 |
* Replaces the ID of this default settings with the given one.
|
|
57 | 46 |
* |
58 |
* @param id the ID of default settings |
|
59 |
* @param sickDayCount the default number of available sick days |
|
60 |
* @param notification the default date and time of sending an email warning about an incoming reset of remaining overtimes and sick days |
|
61 |
* @throws IllegalArgumentException when the given sickDayCount value is negative |
|
47 |
* @param id the given ID |
|
62 | 48 |
*/ |
63 |
public DefaultSettings(final long id, final Integer sickDayCount, final LocalDateTime notification) throws IllegalArgumentException { |
|
64 |
DefaultSettings.log.trace("Creating a new instance of the class DefaultSettings"); |
|
65 |
DefaultSettings.log.debug("DefaultSettings: id={}, sickDayCount={}, notification={}", id, sickDayCount, notification); |
|
49 |
public void setId(final Long id) { |
|
50 |
DefaultSettings.log.debug("Setting a new id: {}", id); |
|
66 | 51 |
|
67 | 52 |
this.id = id; |
68 |
this.setSickDayCount(sickDayCount); |
|
69 |
this.setNotification(notification); |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Returns the ID of this default settings. |
|
74 |
* |
|
75 |
* @return the ID of this default settings |
|
76 |
*/ |
|
77 |
public long getId() { |
|
78 |
return this.id; |
|
79 | 53 |
} |
80 | 54 |
|
81 | 55 |
/** |
server/src/test/java/cz/zcu/yamanager/domain/DefaultSettingsTest.java | ||
---|---|---|
31 | 31 |
* Tests the method {@code setSickDayCount} with common values where no problem should occur. |
32 | 32 |
*/ |
33 | 33 |
@Test |
34 |
void testSetSickDaysCount() {
|
|
34 |
void setSickDaysCount_valid() {
|
|
35 | 35 |
this.defaultSettings.setSickDayCount(10); |
36 | 36 |
assertEquals(10, this.defaultSettings.getSickDayCount()); |
37 | 37 |
} |
... | ... | |
40 | 40 |
* Tests the method {@code setSickDayCount} with zero which is a threshold value. |
41 | 41 |
*/ |
42 | 42 |
@Test |
43 |
void testSetSickDaysCountZero() {
|
|
43 |
void setSickDaysCount_zeroInput() {
|
|
44 | 44 |
this.defaultSettings.setSickDayCount(0); |
45 | 45 |
assertEquals(0, this.defaultSettings.getSickDayCount()); |
46 | 46 |
} |
... | ... | |
49 | 49 |
* Tests the method {@code setSickDayCount} with negative one which is a threshold value. |
50 | 50 |
*/ |
51 | 51 |
@Test |
52 |
void testSetSickDaysCountNegativeOne() {
|
|
52 |
void setSickDaysCount_negativeOneInput() {
|
|
53 | 53 |
assertThrows(IllegalArgumentException.class, () -> this.defaultSettings.setSickDayCount(-1)); |
54 | 54 |
} |
55 | 55 |
|
... | ... | |
57 | 57 |
* Tests the method {@code setSickDayCount} with negative value. |
58 | 58 |
*/ |
59 | 59 |
@Test |
60 |
void testSetSickDaysCountNegative() {
|
|
60 |
void setSickDaysCount_negativeInput() {
|
|
61 | 61 |
assertThrows(IllegalArgumentException.class, () -> this.defaultSettings.setSickDayCount(-10)); |
62 | 62 |
} |
63 | 63 |
|
... | ... | |
65 | 65 |
* Tests the method {@code setSickDayCount} with null value. |
66 | 66 |
*/ |
67 | 67 |
@Test |
68 |
void testSetSickDaysCountObjectNull() {
|
|
68 |
void setSickDaysCount_nullInput() {
|
|
69 | 69 |
assertThrows(IllegalArgumentException.class, () -> this.defaultSettings.setSickDayCount(null)); |
70 | 70 |
} |
71 | 71 |
|
72 |
/** |
|
73 |
* Tests the method {@code setNotification} with common values where no problem should occur. |
|
74 |
*/ |
|
75 |
@Test |
|
76 |
void setNotification_valid() { |
|
77 |
this.defaultSettings.setNotification(LocalDateTime.of(2010,5,1,20,0)); |
|
78 |
assertEquals(LocalDateTime.of(2010,5,1,20,0), this.defaultSettings.getNotification()); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Tests the method {@code setNotification} with null value. |
|
83 |
*/ |
|
84 |
@Test |
|
85 |
void setNotification_nullInput() { |
|
86 |
assertThrows(IllegalArgumentException.class, () -> this.defaultSettings.setNotification(null)); |
|
87 |
} |
|
88 |
|
|
72 | 89 |
/** |
73 | 90 |
* Tests the method {@code toString}. |
74 | 91 |
*/ |
75 | 92 |
@Test |
76 | 93 |
void testToString() { |
77 |
DefaultSettings defaultSettings = new DefaultSettings(5, 1, LocalDateTime.of(2008,10,30,20,0)); |
|
94 |
DefaultSettings defaultSettings = new DefaultSettings(); |
|
95 |
defaultSettings.setId(5L); |
|
96 |
defaultSettings.setSickDayCount(1); |
|
97 |
defaultSettings.setNotification(LocalDateTime.of(2008,10,30,20,0)); |
|
78 | 98 |
assertEquals("DefaultSettings{id=5, sickDayCount=1, notification=2008-10-30T20:00}", defaultSettings.toString()); |
79 | 99 |
} |
80 | 100 |
} |
Také k dispozici: Unified diff
Final version of the class DefaultSettings with its tests