|
17 | 17 | import java.util.UUID; |
18 | 18 | import java.util.stream.Stream; |
19 | 19 |
|
20 | | -import static org.junit.jupiter.api.Assertions.*; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
21 | 23 | import static org.mockito.ArgumentMatchers.any; |
22 | | -import static org.mockito.Mockito.*; |
23 | | - |
24 | | -/** |
25 | | - * @ExtendWith(MockitoExtension.class): tells JUnit 5 to use Mockito's extension and automatically |
26 | | - * initializes all @Mock and @InjectMocks fields when running this test class. @Mock: Creates a fake |
27 | | - * version (mock) of the dependency. @InjectMocks: creates an instance of the real class under |
28 | | - * test. @BeforeEach: Runs before each test method in the class. @Test: Marks the method as a test |
29 | | - * case that JUnit should execute. |
| 24 | +import static org.mockito.Mockito.never; |
| 25 | +import static org.mockito.Mockito.when; |
| 26 | +import static org.mockito.Mockito.verify; |
| 27 | +import static org.mockito.Mockito.times; |
| 28 | + |
| 29 | + |
| 30 | +/**. |
| 31 | + * Explains how this test class uses Mockito: |
| 32 | + * - JUnit is extended using MockitoExtension |
| 33 | + * - @Mock creates fake dependencies |
| 34 | + * - @InjectMocks creates the real service with mocks injected |
| 35 | + * - @BeforeEach runs before every test |
| 36 | + * - @Test marks a test method |
30 | 37 | */ |
31 | 38 |
|
32 | 39 | // Annotation tells JUnit to use Mockito |
@@ -203,20 +210,6 @@ void testCreateBook_RepositoryFailure_ThrowsException() { |
203 | 210 |
|
204 | 211 | // ----- EDGE cases --------- |
205 | 212 |
|
206 | | - @Test |
207 | | - void testCreateBook_RepositoryReturnsNull_HandlesGracefully() { |
208 | | - // Arrange |
209 | | - when(testBookRepository.save(any(Book.class))).thenReturn(null); |
210 | | - |
211 | | - // Act & assert |
212 | | - assertThrows( |
213 | | - IllegalStateException.class, |
214 | | - () -> { |
215 | | - testBookService.createBook(validBookRequest); |
216 | | - } |
217 | | - ); |
218 | | - } |
219 | | - |
220 | 213 | @ParameterizedTest(name = "{0}") // Display the test name |
221 | 214 | @MethodSource("provideLongFieldTestCases") |
222 | 215 | void testCreateBook_VeryLongFields_Success( |
|
0 commit comments