This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppointmentTest.java
124 lines (109 loc) · 3.76 KB
/
AppointmentTest.java
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
package test;
import static org.junit.jupiter.api.Assertions.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
import services.Appointment;
/**
*
* @author Eric Slutz
*
* SNHU CS-320
* Module 5 Milestone
*
*/
class AppointmentTest {
private Date testApptDate;
@BeforeEach
void setUp() {
try {
testApptDate = new SimpleDateFormat("yyyy-MM-dd").parse("2024-01-01");
} catch (ParseException ex) {
System.out.println(ex.getMessage());
}
}
@ParameterizedTest
@ValueSource(strings = {
"0",
"01",
"012",
"0123",
"01234",
"012345",
"0123456",
"01234567",
"0123456789" })
void testCreateAppointmentWithValidId(String testId) {
assertTrue(new Appointment(testId, testApptDate, "description").getAppointmentId() == testId);
}
@ParameterizedTest
@NullSource
@ValueSource(strings = {
"",
" " })
void testCreateAppointmentWithInvalidNullOrEmptyId(String testId) {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Appointment(testId, testApptDate, "description"));
assertEquals("apptId must have a value.", exception.getMessage());
}
@Test
void testCreateTaskWithInvalidLengthId() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Appointment("01234567890", testApptDate, "description"));
assertEquals("apptId cannot be longer than 10 characters.", exception.getMessage());
}
@Test
void testDateWithValidDate() throws ParseException {
assertTrue(new Appointment("id", testApptDate, "description").getDate() == testApptDate);
}
@ParameterizedTest
@NullSource
void testCreateAppointmentWithInvalidNullDate(Date testDate) {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Appointment("id", testDate, "description"));
assertEquals("date must have a value.", exception.getMessage());
}
@ParameterizedTest
@ValueSource(strings = {
"2018-01-01",
"2018-01-31" })
void testCreateAppointmentWithInvalidPastDate(String testDate) throws ParseException {
Date testPastApptDate = new SimpleDateFormat("yyyy-MM-dd").parse(testDate);
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Appointment("id", testPastApptDate, "description"));
assertEquals("date must must be in the future.", exception.getMessage());
}
@ParameterizedTest
@ValueSource(strings = {
"0",
"01",
"012",
"0123",
"01234",
"012345",
"0123456",
"01234567",
"0123456789",
"01234567890123456789",
"012345678901234567890123456789",
"0123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789" })
void testCreateAppointmentWithValidDescription(String testDescription) throws ParseException {
assertTrue(new Appointment("id", testApptDate, testDescription).getDescription() == testDescription);
}
@ParameterizedTest
@NullSource
@ValueSource(strings = {
"",
" " })
void testCreateAppointmentWithInvalidNullOrEmptyDescription(String testDescription) {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Appointment("id", testApptDate, testDescription));
assertEquals("description must have a value.", exception.getMessage());
}
@Test
void testCreateAppointmentWithInvalidLengthDescription() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Appointment("id", testApptDate, "012345678901234567890123456789012345678901234567890"));
assertEquals("description cannot be longer than 50 characters.", exception.getMessage());
}
}