@@ -356,7 +356,7 @@ void updateTask_asOwner_shouldUpdateFieldsAndPublishBothEvents() {
356356
357357 when (taskBodyRepository .findById (1L )).thenReturn (Optional .of (taskBody ));
358358 when (securityFacade .hasRole ("ADMIN" )).thenReturn (false );
359- when (taskBodyRepository .save (any (TaskBody .class ))).thenReturn (taskBody );
359+ when (taskBodyRepository .saveAndFlush (any (TaskBody .class ))).thenReturn (taskBody );
360360 when (fileManagerFacade .getFilesByEntity (any (), eq (1L ), any ())).thenReturn (testFiles );
361361 when (taskBodyMapper .toResponse (taskBody , testFiles , "creator@mail.com" )).thenReturn (updatedResponse );
362362 when (securityFacade .getCurrentUserId ()).thenReturn (Optional .of (100L ));
@@ -369,7 +369,7 @@ void updateTask_asOwner_shouldUpdateFieldsAndPublishBothEvents() {
369369 assertEquals ("creator@mail.com" , result .createdByEmail ());
370370
371371 ArgumentCaptor <TaskBody > captor = ArgumentCaptor .forClass (TaskBody .class );
372- verify (taskBodyRepository ).save (captor .capture ());
372+ verify (taskBodyRepository ).saveAndFlush (captor .capture ());
373373 assertEquals ("Updated Title" , captor .getValue ().getTitle ());
374374 assertEquals ("Updated Description" , captor .getValue ().getDescription ());
375375
@@ -385,7 +385,7 @@ void updateTask_shouldPublishAttachEvent() {
385385
386386 when (taskBodyRepository .findById (1L )).thenReturn (Optional .of (taskBody ));
387387 when (securityFacade .hasRole ("ADMIN" )).thenReturn (true );
388- when (taskBodyRepository .save (any (TaskBody .class ))).thenReturn (taskBody );
388+ when (taskBodyRepository .saveAndFlush (any (TaskBody .class ))).thenReturn (taskBody );
389389 when (fileManagerFacade .getFilesByEntity (any (), eq (1L ), any ())).thenReturn (testFiles );
390390 when (taskBodyMapper .toResponse (taskBody , testFiles , "creator@mail.com" )).thenReturn (taskResponse );
391391 when (securityFacade .getCurrentUserId ()).thenReturn (Optional .of (100L ));
@@ -404,7 +404,7 @@ void updateTask_shouldPublishDetachEvent() {
404404
405405 when (taskBodyRepository .findById (1L )).thenReturn (Optional .of (taskBody ));
406406 when (securityFacade .hasRole ("ADMIN" )).thenReturn (true );
407- when (taskBodyRepository .save (any (TaskBody .class ))).thenReturn (taskBody );
407+ when (taskBodyRepository .saveAndFlush (any (TaskBody .class ))).thenReturn (taskBody );
408408 when (fileManagerFacade .getFilesByEntity (any (), eq (1L ), any ())).thenReturn (testFiles );
409409 when (taskBodyMapper .toResponse (taskBody , testFiles , "creator@mail.com" )).thenReturn (taskResponse );
410410 when (securityFacade .getCurrentUserId ()).thenReturn (Optional .of (100L ));
@@ -425,7 +425,7 @@ void updateTask_nonExistingTask_shouldThrowTaskNotFoundException() {
425425
426426 assertThrows (TaskNotFoundException .class , () -> taskService .updateTask (99L , request ));
427427
428- verify (taskBodyRepository , never ()).save (any ());
428+ verify (taskBodyRepository , never ()).saveAndFlush (any ());
429429 }
430430
431431 @ Test
@@ -439,7 +439,7 @@ void updateTask_notOwnerNotAdmin_shouldThrowTaskAccessRestrictedException() {
439439
440440 assertThrows (TaskAccessRestrictedException .class , () -> taskService .updateTask (1L , request ));
441441
442- verify (taskBodyRepository , never ()).save (any ());
442+ verify (taskBodyRepository , never ()).saveAndFlush (any ());
443443 }
444444
445445 // ---- addTaskOwner ----
@@ -454,7 +454,7 @@ void addTaskOwner_asAdmin_toOrgUser_shouldSucceed() {
454454 when (securityFacade .getCurrentUserId ()).thenReturn (Optional .of (100L ));
455455 when (taskBodyRepository .findById (1L )).thenReturn (Optional .of (taskBody ));
456456 when (userFacade .findByEmail ("newowner@mail.com" )).thenReturn (Optional .of (newOwner ));
457- when (taskBodyRepository .save (any (TaskBody .class ))).thenReturn (taskBody );
457+ when (taskBodyRepository .saveAndFlush (any (TaskBody .class ))).thenReturn (taskBody );
458458 when (fileManagerFacade .getFilesByEntity (any (), eq (1L ), any ())).thenReturn (testFiles );
459459 when (taskBodyMapper .toResponse (any (TaskBody .class ), any (), eq ("creator@mail.com" ))).thenReturn (taskResponse );
460460
@@ -564,7 +564,7 @@ void removeTaskOwner_shouldSucceed() {
564564 when (securityFacade .getCurrentUserId ()).thenReturn (Optional .of (100L ));
565565 when (taskBodyRepository .findById (1L )).thenReturn (Optional .of (taskBody ));
566566 when (userFacade .findByEmail ("currentowner@mail.com" )).thenReturn (Optional .of (owner ));
567- when (taskBodyRepository .save (any (TaskBody .class ))).thenReturn (taskBody );
567+ when (taskBodyRepository .saveAndFlush (any (TaskBody .class ))).thenReturn (taskBody );
568568 when (fileManagerFacade .getFilesByEntity (any (), eq (1L ), any ())).thenReturn (testFiles );
569569 when (taskBodyMapper .toResponse (taskBody , testFiles , "creator@mail.com" )).thenReturn (taskResponse );
570570
0 commit comments