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 pathTaskTest.java
163 lines (151 loc) · 4.33 KB
/
TaskTest.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
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
package test;
import static org.junit.jupiter.api.Assertions.*;
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.Task;
/**
*
* @author Eric Slutz
*
* SNHU CS-320
* Module 4 Milestone
*
*/
class TaskTest {
/**
* Tests creating a task with valid arguments.
*
* @param testId values to be tested
*/
@ParameterizedTest
@ValueSource(strings = {
"0",
"01",
"012",
"0123",
"01234",
"012345",
"0123456",
"01234567",
"0123456789" })
void testCreateTaskWithValidId(String testId) {
assertTrue(new Task(testId, "name", "description").getTaskId() == testId);
}
/**
* Tests creating a task with invalid null or empty argument for taskId.
*
* @param testId values to be tested
*/
@ParameterizedTest
@NullSource
@ValueSource(strings = {
"",
" " })
void testCreateTaskWithInvalidNullOrEmptyId(String testId) {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Task(testId, "name", "description"));
assertEquals("taskId must have a value.", exception.getMessage());
}
/**
* Tests creating a task with invalid length argument for taskId.
*
* @param testId values to be tested
*/
@Test
void testCreateTaskWithInvalidLengthId() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Task("01234567890", "name", "description"));
assertEquals("taskId cannot be longer than 10 characters.", exception.getMessage());
}
/**
* Tests creating a task with valid arguments.
*
* @param testId values to be tested
*/
@ParameterizedTest
@ValueSource(strings = {
"0",
"01",
"012",
"0123",
"01234",
"012345",
"0123456",
"01234567",
"0123456789",
"01234567890123456789" })
void testCreateTaskWithValidName(String testName) {
assertTrue(new Task("id", testName, "description").getName() == testName);
}
/**
* Tests creating a task with invalid null or empty argument for name.
*
* @param testName values to be tested
*/
@ParameterizedTest
@NullSource
@ValueSource(strings = {
"",
" " })
void testCreateContactWithInvalidNullOrEmptyName(String testName) {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Task("id", testName, "description"));
assertEquals("name must have a value.", exception.getMessage());
}
/**
* Tests creating a task with invalid length argument for name.
*
* @param testName values to be tested
*/
@Test
void testCreateContactWithInvalidLengthName() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Task("id", "012345678901234567890", "description"));
assertEquals("name cannot be longer than 20 characters.", exception.getMessage());
}
/**
* Tests creating a task with valid arguments.
*
* @param testDescription values to be tested
*/
@ParameterizedTest
@ValueSource(strings = {
"0",
"01",
"012",
"0123",
"01234",
"012345",
"0123456",
"01234567",
"0123456789",
"01234567890123456789",
"012345678901234567890123456789",
"0123456789012345678901234567890123456789",
"01234567890123456789012345678901234567890123456789" })
void testCreateTaskWithValidDescription(String testDescription) {
assertTrue(new Task("id", "name", testDescription).getDescription() == testDescription);
}
/**
* Tests creating a task with invalid argument for description.
*
* @param testDescription values to be tested
*/
@ParameterizedTest
@NullSource
@ValueSource(strings = {
"",
" " })
void testCreateTaskWithInvalidNullOrEmptyDescription(String testDescription) {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Task("id", "name", testDescription));
assertEquals("description must have a value.", exception.getMessage());
}
/**
* Tests creating a task with invalid length argument for description.
*
* @param testDescription values to be tested
*/
@Test
void testCreateTaskWithInvalidLengthDescription() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> new Task("id", "name", "012345678901234567890123456789012345678901234567890"));
assertEquals("description cannot be longer than 50 characters.", exception.getMessage());
}
}