@@ -69,6 +69,12 @@ public class AlbumControllerTest {
6969 private User user ;
7070 private Photo photo ;
7171
72+ /**
73+ * Test setup method
74+ * Initializes common test data and mock configurations used across all test methods.
75+ * Creates sample UserPrincipal, User, AlbumRequest, and AlbumResponse objects
76+ * that will be used for mocking service responses and testing controller behavior.
77+ */
7278 @ Before
7379 public void setUp () {
7480 mockMvc = MockMvcBuilders .standaloneSetup (albumController ).build ();
@@ -99,6 +105,10 @@ public void setUp() {
99105 album .setPhoto (Arrays .asList (photo ));
100106 }
101107
108+ /**
109+ * Test successful retrieval of all albums with pagination
110+ * Verifies that the getAllAlbums endpoint returns a paginated response with correct data
111+ */
102112 @ Test
103113 public void testGetAllAlbums_Success () throws Exception {
104114 PagedResponse <AlbumResponse > pagedResponse = new PagedResponse <>(
@@ -115,6 +125,10 @@ public void testGetAllAlbums_Success() throws Exception {
115125 verify (albumService , times (1 )).getAllAlbums (anyInt (), anyInt ());
116126 }
117127
128+ /**
129+ * Test successful album creation
130+ * Verifies that a new album can be created with valid data and returns the created album
131+ */
118132 @ Test
119133 public void testAddAlbum_Success () throws Exception {
120134 when (albumService .addAlbum (any (AlbumRequest .class ), any (UserPrincipal .class )))
@@ -130,6 +144,10 @@ public void testAddAlbum_Success() throws Exception {
130144 verify (albumService , times (1 )).addAlbum (any (AlbumRequest .class ), any (UserPrincipal .class ));
131145 }
132146
147+ /**
148+ * Test album creation without authentication
149+ * Verifies behavior when attempting to create an album without proper authentication
150+ */
133151 @ Test
134152 public void testAddAlbum_Unauthorized () throws Exception {
135153 // Note: Security filters are disabled in test setup, so this returns 200 instead of 403
@@ -142,6 +160,10 @@ public void testAddAlbum_Unauthorized() throws Exception {
142160 .andExpect (status ().isCreated ());
143161 }
144162
163+ /**
164+ * Test album creation with invalid data
165+ * Verifies that the system properly handles invalid album data (empty title)
166+ */
145167 @ Test
146168 public void testAddAlbum_InvalidData () throws Exception {
147169 // Note: No validation annotations on AlbumRequest, so empty title is accepted
@@ -160,6 +182,10 @@ public void testAddAlbum_InvalidData() throws Exception {
160182 verify (albumService , times (1 )).addAlbum (any (AlbumRequest .class ), any (UserPrincipal .class ));
161183 }
162184
185+ /**
186+ * Test successful retrieval of a specific album
187+ * Verifies that an album can be retrieved by its ID with correct data
188+ */
163189 @ Test
164190 public void testGetAlbum_Success () throws Exception {
165191 when (albumService .getAlbum (anyLong ())).thenReturn (new ResponseEntity <>(album , HttpStatus .OK ));
@@ -173,6 +199,10 @@ public void testGetAlbum_Success() throws Exception {
173199 verify (albumService , times (1 )).getAlbum (anyLong ());
174200 }
175201
202+ /**
203+ * Test retrieval of non-existent album
204+ * Verifies that the system returns 404 when trying to retrieve an album that doesn't exist
205+ */
176206 @ Test
177207 public void testGetAlbum_NonExistentAlbum () throws Exception {
178208 when (albumService .getAlbum (anyLong ())).thenThrow (new ResourceNotFoundException ("Album" , "id" , 999L ));
@@ -184,6 +214,10 @@ public void testGetAlbum_NonExistentAlbum() throws Exception {
184214 verify (albumService , times (1 )).getAlbum (anyLong ());
185215 }
186216
217+ /**
218+ * Test successful album update
219+ * Verifies that an existing album can be updated with new data
220+ */
187221 @ Test
188222 public void testUpdateAlbum_Success () throws Exception {
189223 AlbumRequest updateRequest = new AlbumRequest ();
@@ -206,6 +240,10 @@ public void testUpdateAlbum_Success() throws Exception {
206240 verify (albumService , times (1 )).updateAlbum (anyLong (), any (AlbumRequest .class ), any (UserPrincipal .class ));
207241 }
208242
243+ /**
244+ * Test album update without authentication
245+ * Verifies behavior when attempting to update an album without proper authentication
246+ */
209247 @ Test
210248 public void testUpdateAlbum_Unauthorized () throws Exception {
211249 // Note: Security filters are disabled in test setup, so this returns 200 instead of 403
@@ -221,6 +259,10 @@ public void testUpdateAlbum_Unauthorized() throws Exception {
221259 .andExpect (status ().isOk ());
222260 }
223261
262+ /**
263+ * Test album update with invalid data
264+ * Verifies that the system properly handles invalid update data (empty title)
265+ */
224266 @ Test
225267 public void testUpdateAlbum_InvalidData () throws Exception {
226268 // Note: No validation annotations on AlbumRequest, so empty title is accepted
@@ -239,6 +281,10 @@ public void testUpdateAlbum_InvalidData() throws Exception {
239281 verify (albumService , times (1 )).updateAlbum (anyLong (), any (AlbumRequest .class ), any (UserPrincipal .class ));
240282 }
241283
284+ /**
285+ * Test successful album deletion
286+ * Verifies that an album can be deleted and returns a success response
287+ */
242288 @ Test
243289 public void testDeleteAlbum_Success () throws Exception {
244290 ApiResponse apiResponse = new ApiResponse (true , "Album deleted successfully" );
@@ -256,6 +302,10 @@ public void testDeleteAlbum_Success() throws Exception {
256302 verify (albumService , times (1 )).deleteAlbum (anyLong (), any (UserPrincipal .class ));
257303 }
258304
305+ /**
306+ * Test album deletion without authentication
307+ * Verifies behavior when attempting to delete an album without proper authentication
308+ */
259309 @ Test
260310 public void testDeleteAlbum_Unauthorized () throws Exception {
261311 // Note: Security filters are disabled in test setup, so this returns 200 instead of 403
@@ -271,6 +321,10 @@ public void testDeleteAlbum_Unauthorized() throws Exception {
271321 .andExpect (jsonPath ("$.message" ).value ("Album deleted successfully" ));
272322 }
273323
324+ /**
325+ * Test deletion of non-existent album
326+ * Verifies that the system returns 404 when trying to delete an album that doesn't exist
327+ */
274328 @ Test
275329 public void testDeleteAlbum_NonExistentAlbum () throws Exception {
276330 when (albumService .deleteAlbum (anyLong (), any (UserPrincipal .class )))
@@ -284,6 +338,10 @@ public void testDeleteAlbum_NonExistentAlbum() throws Exception {
284338 verify (albumService , times (1 )).deleteAlbum (anyLong (), any (UserPrincipal .class ));
285339 }
286340
341+ /**
342+ * Test successful retrieval of all photos by album
343+ * Verifies that all photos belonging to a specific album can be retrieved with pagination
344+ */
287345 @ Test
288346 public void testGetAllPhotosByAlbum_Success () throws Exception {
289347 PhotoResponse photoResponse = new PhotoResponse (1L , "Test Photo" , "http://example.com/photo.jpg" , "http://example.com/photo-thumb.jpg" , 1L );
0 commit comments