Repository navigation
Expand file tree
/
Copy pathPostTest.java
More file actions
185 lines (157 loc) · 10.3 KB
/
Copy pathPostTest.java
File metadata and controls
185 lines (157 loc) · 10.3 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
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class PostTest {
// Test cases for addPost()
@Test
public void testAddValidPost() {
// Test data 1: Creating a valid post
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(1, "Sample Post Title", validBody1, new String[] { "tag1", "tag2" }, "Difficult", "Highly Needed");
assertTrue(post1.addPost(), "Valid post should be added successfully");
// Test data 2: Another valid post
String validBody2 = "another valid body ".repeat(30);
Post post2 = new Post(2, "Another Sample Title", validBody2, new String[] { "tag3", "tag4", "blah" }, "Very Difficult", "Immediately Needed");
assertTrue(post2.addPost(), "Another valid post should be added successfully");
}
@Test
public void testAddInvalidPostTooShortTitle() {
// Test data 1: Creating an invalid post with a short title
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(3, "short", validBody1, new String[] { "tag1", "tag2" }, "Difficult", "Highly Needed");
assertFalse(post1.addPost(), "Post with title too short should not be added");
// Test data 2: Another invalid post with a short title
String validBody2 = "another valid body ".repeat(60);
Post post2 = new Post(4, "invalid", validBody2, new String[] { "tag3", "tag4" }, "Easy", "Ordinary");
assertFalse(post2.addPost(), "Post with a short title should fail addition");
}
@Test
public void testAddInvalidPostNullTitle() {
// Test data 1: Creating an invalid post with an empty title
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(3, "", validBody1, new String[] { "tag1", "tag2" }, "Difficult", "Highly Needed");
assertFalse(post1.addPost(), "Post with lack of title should not be added");
// Test data 2: Another invalid post with a title consisting of only whitespace
String validBody2 = "another valid body ".repeat(60);
Post post2 = new Post(4, " ", validBody2, new String[] { "tag3", "tag4" }, "Easy", "Ordinary");
assertFalse(post2.addPost(), "Post with lack of title should not be added");
}
@Test
public void testAddInvalidPostNotEnoughTags() {
// Test data 1: Creating an invalid post with too little tags (<2)
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(5, "Sample Title", validBody1, new String[] { "tag1" }, "Difficult", "Highly Needed");
assertFalse(post1.addPost(), "Post with less than 2 tags should not be added");
// Test data 2: Another invalid post with too little tags (<2)
String validBody2 = "another valid body ".repeat(60);
Post post2 = new Post(6, "Another Sample Title", validBody2, new String[] { }, "Easy", "Highly Needed");
assertFalse(post2.addPost(), "Post with less than 2 tags should not be added");
}
@Test
public void testAddInvalidPostTooManyTags() {
// Test data 1: Creating an invalid post with too many tags (>5)
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(5, "Sample Title", validBody1, new String[] { "tag1", "tag2", "tag3", "tag4", "tag5", "tag6" }, "Difficult", "Highly Needed");
assertFalse(post1.addPost(), "Post with more than 5 tags should not be added");
// Test data 2: Another invalid post with too many tags (>3), because type is Easy
String validBody2 = "another valid body ".repeat(60);
Post post2 = new Post(6, "Another Sample Title", validBody2, new String[] { "tag1", "tag2", "tag3", "tag4" }, "Easy", "Highly Needed");
assertFalse(post2.addPost(), "Post with too many tags for 'Easy' type should fail to add");
}
@Test
public void testAddInvalidPostIncompatibleTypeAndEmergency() {
// Test data 1: Creating an invalid post with incompatible type and emergency level
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(7, "Sample Title", validBody1, new String[] { "tag1", "tag2" }, "Easy", "Immediately Needed");
assertFalse(post1.addPost(), "Post with mismatched type and urgency should fail");
// Test data 2: Another invalid post with incompatible type and emergency level
String validBody2 = "valid body ".repeat(60);
Post post2 = new Post(8, "Another Sample Title", validBody2, new String[] { "tag3", "tag4" }, "Very Difficult", "Ordinary");
assertFalse(post2.addPost(), "Post with conflicting type and urgency should not be added");
}
// Test cases for addComment()
@Test
public void testAddValidComment() {
// Test data 1: Adding a valid comment
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(9, "Sample Title", validBody1, new String[] { "tag1", "tag2" }, "Difficult", "Highly Needed");
post1.addPost();
assertTrue(post1.addComment("This is a valid comment."), "Valid comment should be added successfully");
// Test data 2: Adding another valid comment
String validBody2 = "valid body ".repeat(60);
Post post2 = new Post(10, "Another Sample Title", validBody2, new String[] { "tag3", "tag4" }, "Very Difficult", "Immediately Needed");
post2.addPost();
assertTrue(post2.addComment("This is another valid comment."), "Another valid comment should be added successfully");
}
@Test
public void testAddInvalidCommentTooShort() {
// Test data 1: Adding an invalid comment with too few words
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(11, "Sample Title", validBody1, new String[] { "tag1", "tag2" }, "Difficult", "Highly Needed");
post1.addPost();
assertFalse(post1.addComment("Short comment."), "Comment with too few words should not be added");
// Test data 2: Adding another invalid comment with too few words
String validBody2 = "another valid body ".repeat(60);
Post post2 = new Post(12, "Another Sample Title", validBody2, new String[] { "tag3", "tag4" }, "Easy", "Ordinary");
post2.addPost();
assertFalse(post2.addComment("Too short."), "Another short comment should not be added");
}
@Test
public void testAddInvalidCommentTooLong() {
// Test data 1: Adding an invalid comment with too many words
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(11, "Sample Title", validBody1, new String[] { "tag1", "tag2" }, "Difficult", "Highly Needed");
post1.addPost();
assertFalse(post1.addComment("Long comment long comment long commment long comment long comment long comment."), "Comment with too few words should not be added");
// Test data 2: Adding another invalid comment with too many words
String validBody2 = "another valid body ".repeat(60);
Post post2 = new Post(12, "Another Sample Title", validBody2, new String[] { "tag3", "tag4" }, "Easy", "Ordinary");
post2.addPost();
assertFalse(post2.addComment("This comment is too long like way way way way way way way way way way way way too long."), "Another short comment should not be added");
}
@Test
public void testAddInvalidCommentEmpty() {
// Test data 1: Adding an invalid comment that's empty
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(11, "Sample Title", validBody1, new String[] { "tag1", "tag2" }, "Difficult", "Highly Needed");
post1.addPost();
assertFalse(post1.addComment(""), "Comment with too few words should not be added");
// Test data 2: Adding another invalid comment with only whitespaces
String validBody2 = "another valid body ".repeat(60);
Post post2 = new Post(12, "Another Sample Title", validBody2, new String[] { "tag3", "tag4" }, "Easy", "Ordinary");
post2.addPost();
assertFalse(post2.addComment(" "), "Another short comment should not be added");
}
@Test
public void testAddInvalidCommentFormat() {
// Test data 1: Adding an invalid comment with improper formatting
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(13, "Sample Title", validBody1, new String[] { "tag1", "tag2" }, "Difficult", "Highly Needed");
post1.addPost();
assertFalse(post1.addComment("this is not Properly Formatted."), "Comment with incorrect formatting should not be added");
// Test data 2: Adding another invalid comment with improper formatting
String validBody2 = "valid body ".repeat(60);
Post post2 = new Post(14, "Another Sample Title", validBody2, new String[] { "tag3", "tag4" }, "Very Difficult", "Immediately Needed");
post2.addPost();
assertFalse(post2.addComment("this again is not properly formatted."), "Another comment with incorrect formatting should not be added");
}
@Test
public void testAddInvalidCommentEasyPostLimit() {
// Test data 1: Adding a comment when the maximum comment length of easy posts is exceeded, making it invalid
String validBody1 = "valid body ".repeat(60);
Post post1 = new Post(15, "Sample Title", validBody1, new String[] { "tag1", "tag2" }, "Easy", "Highly Needed");
post1.addPost();
post1.addComment("This is Comment 1");
post1.addComment("This is Comment 2");
post1.addComment("This is Comment 3");
assertFalse(post1.addComment("This comment exceeds the limit for an 'Easy' post."), "Comment exceeding limit for 'Easy' post should not be added");
// Test data 2: Adding a comment when the maximum comment length of easy posts is exceeded, making it invalid
String validBody2 = "valid body ".repeat(60);
Post post2 = new Post(16, "Another Sample Title", validBody2, new String[] { "tag3", "tag4" }, "Easy", "Ordinary");
post2.addPost();
post2.addComment("This is Comment 1");
post2.addComment("This is Comment 2");
post2.addComment("This is Comment 3");
post1.addComment("This is Comment 4");
assertFalse(post2.addComment("This comment exceeds the limit for an 'Easy' post."), "Comment exceeding limit for 'Easy' post should not be added");
}
}