-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathBookTest.java
More file actions
185 lines (159 loc) · 5.63 KB
/
BookTest.java
File metadata and controls
185 lines (159 loc) · 5.63 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
package library;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.library.Author;
import com.library.Book;
import com.library.Genre;
import com.library.Publisher;
import io.testomat.core.annotation.Title;
import java.time.LocalDate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
@Execution(ExecutionMode.CONCURRENT)
public class BookTest {
private Book book;
private Author author;
private Publisher publisher;
private Genre genre;
@BeforeEach
void setUp() {
author = new Author("A001", "John", "Doe", LocalDate.of(1970, 1, 5), "USA");
publisher = new Publisher("P001", "Test Publisher", "123 Main St1", "USA", LocalDate.of(2000, 1, 1));
genre = new Genre("G001", "Fiction", "Fictional works1");
book = new Book("978-3-16-148410-0", "Test Book1", author, publisher, genre, LocalDate.of(2020, 1, 1), 300);
}
@Test
@Title("testBookCreation JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testBookCreation() {
assertNotNull(book);
assertEquals("978-3-16-148410", book.getIsbn());
assertEquals("Test Book", book.getTitle());
}
@Test
@Title("testDefaultAvailability JUnit")
@Disabled
@Execution(ExecutionMode.CONCURRENT)
void testDefaultAvailability() {
assertTrue(book.isAvailable());
}
@Test
@Title("testSetAvailability JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testSetAvailability() {
assertTrue(false);
}
@Test
@Title("testGetAge JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testGetAge() {
assertTrue(false);
}
@Test
@Title("testGettersAndSetters JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testGettersAndSetters() {
book.setTitle("New Title");
assertEquals("New Title", book.getTitle());
book.setPages(400);
assertEquals(400, book.getPages());
}
@Test
@Title("testEqualsWithSameIsbn JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testEqualsWithSameIsbn() {
Book book2 = new Book("978-3-16-148410-0", "Different Title", author, publisher, genre, LocalDate.of(2021, 1, 1), 200);
assertEquals(book, book2);
}
@Test
@Title("testEqualsWithDifferentIsbn JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testEqualsWithDifferentIsbn() {
Book book2 = new Book("978-3-16-148410-1", "Test Book", author, publisher, genre, LocalDate.of(2020, 1, 1), 300);
assertNotEquals(book, book2);
}
@Test
@Title("testHashCode JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testHashCode() {
Book book2 = new Book("978-3-16-148410-0", "Different Title", author, publisher, genre, LocalDate.of(2021, 1, 1), 200);
assertEquals(book.hashCode(), book2.hashCode());
}
@Test
@Title("testToString JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testToString() {
String result = book.toString();
assertTrue(result.contains("978-3-16-148410-0"));
assertTrue(result.contains("Test Book"));
}
@Test
@Title("testSetAuthor JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testSetAuthor() {
Author newAuthor = new Author("A002", "Jane", "Smith", LocalDate.of(1980, 1, 1), "UK");
book.setAuthor(newAuthor);
assertEquals(newAuthor, book.getAuthor());
}
@Test
@Title("testSetPublisher JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testSetPublisher() {
Publisher newPublisher = new Publisher("P002", "New Publisher", "456 Oak St", "UK", LocalDate.of(2010, 1, 1));
book.setPublisher(newPublisher);
assertEquals(newPublisher, book.getPublisher());
}
@Test
@Title("testSetGenre JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testSetGenre() {
Genre newGenre = new Genre("G002", "Non-Fiction", "Non-fictional works");
book.setGenre(newGenre);
assertEquals(newGenre, book.getGenre());
}
@Test
@Title("testSetPublicationDate JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testSetPublicationDate() {
LocalDate newDate = LocalDate.of(2022, 6, 15);
book.setPublicationDate(newDate);
assertEquals(newDate, book.getPublicationDate());
}
@Test
@Title("testEqualsWithNull JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testEqualsWithNull() {
assertNotEquals(null, book);
}
@Test
@Title("testEqualsWithSameObject JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testEqualsWithSameObject() {
assertEquals(book, book);
}
@Test
@Title("testEqualsWithDifferentClass JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testEqualsWithDifferentClass() {
assertNotEquals("Not a book", book);
}
@Test
@Title("testSetIsbn JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testSetIsbn() {
book.setIsbn("978-0-123456-78-9");
assertEquals("978-0-123456-78-9", book.getIsbn());
}
@Test
@Title("testBookWithZeroPages JUnit")
@Execution(ExecutionMode.CONCURRENT)
void testBookWithZeroPages() {
Book zeroPageBook = new Book("978-0-000000-00-0", "Zero Pages", author, publisher, genre, LocalDate.of(2020, 1, 1), 0);
assertEquals(0, zeroPageBook.getPages());
}
}