Projekt

Obecné

Profil

« Předchozí | Další » 

Revize d7676f17

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

Re #7545 Fix errors in tests and domain classes

Zobrazit rozdíly:

server/src/main/java/cz/zcu/yamanager/domain/DefaultSettings.java
51 51
     */
52 52
    public DefaultSettings(final long id, final int sickDayCount, final LocalDateTime notification) throws IllegalArgumentException {
53 53
        DefaultSettings.log.trace("Creating a new instance of the class DefaultSettings.");
54
        DefaultSettings.log.debug("DefaultSettings: id={},\nsickDayCount={},\nnotification={}", id, sickDayCount, notification);
54
        DefaultSettings.log.debug("DefaultSettings: id={}, sickDayCount={}, notification={}", id, sickDayCount, notification);
55 55

  
56 56
        this.id = id;
57 57
        this.setSickDayCount(sickDayCount);
server/src/main/java/cz/zcu/yamanager/domain/User.java
122 122
     */
123 123
    public User(final long id, final String firstName, final String lastName, final float vacationCount, final int totalSickDayCount, final int takenSickDayCount, final LocalDateTime notification, final String token, final String email, final String photo, final LocalDateTime creationDate, final UserRole role, final Status status) throws IllegalArgumentException {
124 124
        User.log.trace("Creating a new instance of the class User.");
125
        User.log.debug("User: id={},\nfirstName={},\nlastName={},\nvacationCount={},\ntotalSickDayCount={},\ntakenSickDayCount={},\nnotification={},\ntoken={},\nemail={},\nphoto={},\ncreationDate={},\nrole={},\nstatus={}", id, firstName, lastName, vacationCount, totalSickDayCount, takenSickDayCount, notification, token, email, photo, creationDate, role, status);
125
        User.log.debug("User: id={}, firstName={}, lastName={}, vacationCount={}, totalSickDayCount={}, takenSickDayCount={}, notification={}, token={}, email={}, photo={}, creationDate={}, role={}, status={}", id, firstName, lastName, vacationCount, totalSickDayCount, takenSickDayCount, notification, token, email, photo, creationDate, role, status);
126 126

  
127 127
        this.id = id;
128 128
        this.setFirstName(firstName);
server/src/main/java/cz/zcu/yamanager/domain/VacationDay.java
104 104
     */
105 105
    private VacationDay(final int id, final LocalDate date, final LocalTime from, final LocalTime to, final LocalDateTime creationDate, final Status status, final VacationType type) {
106 106
        VacationDay.log.trace("Creating a new instance of the class VacationDay.");
107
        VacationDay.log.debug("VacationDay: id={},\ndate={},\nfrom={},\nto={},\ncreationDate={},\nstatus={},\ntype={}", id, date, from, to, creationDate, status, type);
107
        VacationDay.log.debug("VacationDay: id={}, date={}, from={}, to={}, creationDate={}, status={}, type={}", id, date, from, to, creationDate, status, type);
108 108

  
109 109
        this.id = id;
110 110
        this.date = date;
......
161 161
    public void setFrom(final LocalTime from) throws IllegalArgumentException {
162 162
        VacationDay.log.debug("Settings a new value of the starting time of this vacation: {}", from);
163 163

  
164
        if(this.type == VacationType.SICKDAY) {
165
            VacationDay.log.info("The sick day must not have a starting time.");
166
            this.from = null;
167
        }
168

  
169
        if (this.to != null && from.compareTo(this.to) >= 0) {
164
        if (from != null && this.to != null && from.compareTo(this.to) >= 0) {
170 165
            VacationDay.log.warn("The vacation must not start after it ends. from={}, to={}", from, this.to);
171 166
            throw new IllegalArgumentException("time.order.error");
172 167
        }
......
193 188
    public void setTo(final LocalTime to) throws IllegalArgumentException {
194 189
        VacationDay.log.debug("Settings a new value of the ending time of this vacation: {}", to);
195 190

  
196
        if(this.type == VacationType.SICKDAY) {
197
            VacationDay.log.info("The sick day must not have an ending time.");
198
            this.to = null;
199
        }
200

  
201
        if (this.from != null && to.compareTo(this.from) <= 0) {
191
        if (to != null && this.from != null && to.compareTo(this.from) <= 0) {
202 192
            VacationDay.log.warn("The vacation must not end after it starts. from={}, to={}", this.from, to);
203 193
            throw new IllegalArgumentException("time.order.error");
204 194
        }
......
217 207
    public void setTime(final LocalTime from, final LocalTime to) throws IllegalArgumentException {
218 208
        VacationDay.log.debug("Settings a new value of the starting {} and the ending {} time of this vacation.", from, to);
219 209

  
220
        if(this.type == VacationType.SICKDAY) {
221
            VacationDay.log.info("The sick day must not have a starting and an ending time.");
222
            this.from = null;
223
            this.to = null;
224
        }
225

  
226
        if (from.compareTo(to) >= 0) {
210
        if (from != null && to != null && from.compareTo(to) >= 0) {
227 211
            VacationDay.log.warn("The vacation must not start after it ends. from={}, to={}", from, to);
228 212
            throw new IllegalArgumentException("time.order.error");
229 213
        }
......
277 261
     */
278 262
    public void setType(final VacationType type) {
279 263
        VacationDay.log.debug("Setting a new type of this vacation: {}", type);
280

  
281
        if(type == VacationType.SICKDAY) {
282
            VacationDay.log.info("The sick day must not have a starting and an ending time.");
283
            this.from = null;
284
            this.to = null;
285
        }
286

  
287 264
        this.type = type;
288 265
    }
289 266

  
......
297 274
        return "VacationDay{" +
298 275
                "id=" + this.id +
299 276
                ", date=" + this.date +
300
                ", from=" + this.from +
301
                ", to=" + this.to +
277
                ", from=" + String.valueOf(this.from) +
278
                ", to=" + String.valueOf(this.to) +
302 279
                ", creationDate=" + this.creationDate +
303 280
                ", status=" + this.status +
304 281
                ", type=" + this.type +
server/src/test/java/cz/zcu/yamanager/domain/DefaultSettingsTest.java
67 67
    @Test
68 68
    void testToString() {
69 69
        DefaultSettings defaultSettings = new DefaultSettings(5, 1, LocalDateTime.of(2008,10,30,20,0));
70
        assertEquals("DefaultSettings{id=5, sickDaysCount=1, notification=2008-10-30T20:00}", defaultSettings.toString());
70
        assertEquals("DefaultSettings{id=5, sickDayCount=1, notification=2008-10-30T20:00}", defaultSettings.toString());
71 71
    }
72 72
}
server/src/test/java/cz/zcu/yamanager/domain/UserTest.java
262 262
     */
263 263
    @Test
264 264
    void testToString() {
265
        User user = new User(5, "Jan", "Novák", 0, 10, 5, LocalDateTime.of(2008,10,30,20,0), "tokenContent", "novak@email.com", "url", LocalDateTime.of(2010,6,31,12,5), UserRole.EMPLOYER, Status.ACCEPTED);
266
        assertEquals("User{id=5, firstName=Jan, lastName=Novák, vacationsCount=0, totalSickDaysCount=10, takenSickDaysCount=5, notification=2008-10-30T20:00, token=tokenContent, email=novak@email.com, photo=url, creationDate=2010-6-31T12:05 , role=EMPLOYER, status=ACCEPTED}", user.toString());
265
        User user = new User(5, "Jan", "Nov\u00E1k", 0, 10, 5, LocalDateTime.of(2008,10,30,20,0), "tokenContent", "novak@email.com", "url", LocalDateTime.of(2010,7,31,12,5), UserRole.EMPLOYER, Status.ACCEPTED);
266
        assertEquals("User{id=5, firstName='Jan', lastName='Nov\u00E1k', vacationCount=0.0, totalSickDayCount=10, takenSickDayCount=5, notification=2008-10-30T20:00, token='tokenContent', email='novak@email.com', photo='url', creationDate=2010-07-31T12:05, role=EMPLOYER, status=ACCEPTED}", user.toString());
267 267
    }
268 268
}
server/src/test/java/cz/zcu/yamanager/domain/VacationDayTest.java
62 62
    }
63 63

  
64 64
    /**
65
     * Tests the method {@code setTime} with a sick day.
65
     * Tests the method {@code setTime} with null {@code from} input.
66 66
     */
67 67
    @Test
68
    void testSetTimeSickDay() {
69
        this.vacationDay.setType(VacationType.SICKDAY);
70
        LocalTime from = LocalTime.of(10,0);
71
        LocalTime to = LocalTime.of(20,0);
72
        this.vacationDay.setTime(from, to);
68
    void testSetTimeNullFrom() {
69
        LocalTime to = LocalTime.of(10,0);
70
        this.vacationDay.setTime(null, to);
71
        assertNull(this.vacationDay.getFrom());
72
        assertEquals(to, this.vacationDay.getTo());
73
    }
74

  
75
    /**
76
     * Tests the method {@code setTime} with null {@code to} input.
77
     */
78
    @Test
79
    void testSetTimeNullTo() {
80
        LocalTime from = LocalTime.of(20,0);
81
        this.vacationDay.setTime(from, null);
82
        assertNull(this.vacationDay.getTo());
83
        assertEquals(from, this.vacationDay.getFrom());
84
    }
85

  
86
    /**
87
     * Tests the method {@code setTime} with null input.
88
     */
89
    @Test
90
    void setSetTimeNull() {
91
        this.vacationDay.setTime(null, null);
73 92
        assertNull(this.vacationDay.getFrom());
74 93
        assertNull(this.vacationDay.getTo());
75 94
    }
......
119 138
    }
120 139

  
121 140
    /**
122
     * Tests the method {@code setFrom} with a sick day.
141
     * Tests the method {@code setFrom} with a null input.
123 142
     */
124 143
    @Test
125
    void testSetFromSickDay() {
126
        this.vacationDay.setType(VacationType.SICKDAY);
127
        LocalTime from = LocalTime.of(10,0);
128
        this.vacationDay.setFrom(from);
144
    void testSetFromNullInput() {
145
        this.vacationDay.setFrom(null);
129 146
        assertNull(this.vacationDay.getFrom());
130 147
    }
131 148

  
......
174 191
    }
175 192

  
176 193
    /**
177
     * Tests the method {@code setTo} with a sick day.
194
     * Tests the method {@code setTo} with a null input.
178 195
     */
179 196
    @Test
180
    void testSetToSickDay() {
181
        this.vacationDay.setType(VacationType.SICKDAY);
182
        LocalTime to = LocalTime.of(10,0);
183
        this.vacationDay.setTo(to);
197
    void testSetToNullInput() {
198
        this.vacationDay.setTo(null);
184 199
        assertNull(this.vacationDay.getTo());
185 200
    }
186 201

  
......
190 205
    @Test
191 206
    void testToStringVacation() {
192 207
        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);
193
        assertEquals("User{id=5, date=2010-1-9, from=12:15, to=22:30, notification=2008-10-30T20:00, status=ACCEPTED, type=VACATION}", vacationDay.toString());
208
        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());
194 209
    }
195 210

  
196 211
    /**
......
199 214
    @Test
200 215
    void testToStringSickDay() {
201 216
        VacationDay vacationDay = new VacationDay(5, LocalDate.of(2010,1,9), LocalDateTime.of(2008,10,30,20,0), Status.ACCEPTED);
202
        assertEquals("User{id=5, date=2010-1-9, from=null, to=null, notification=2008-10-30T20:00, status=ACCEPTED, type=SICKDAY}", vacationDay.toString());
217
        assertEquals("VacationDay{id=5, date=2010-01-09, from=null, to=null, creationDate=2008-10-30T20:00, status=ACCEPTED, type=SICKDAY}", vacationDay.toString());
203 218
    }
204 219
}

Také k dispozici: Unified diff