@Test public void update() { // given Long galleryId = 2l; String photoTitle = "Updated titile"; String photoDesc = "Desc photo"; String photoSrc = "folder/img.jpg"; Photo expectedPhoto = expectedPhotoList.get(0); PhotoForm photoForm = new PhotoForm(); photoForm.setId(expectedPhoto.getId()); photoForm.setGalleryId(galleryId); photoForm.setTitle(photoTitle); photoForm.setDescription(photoDesc); photoForm.setImageSrc(photoSrc); when(photoRepository.findOne(expectedPhoto.getId())).thenReturn(expectedPhoto); when(photoRepository.save(expectedPhoto)).thenReturn(expectedPhoto); photoService.setPhotoRepository(photoRepository); // execute Photo actualPhoto = photoService.update(photoForm); // assert PhotoTestUtils.assertPhoto(expectedPhoto, actualPhoto); assertEquals(photoForm.getGalleryId(), actualPhoto.getGalleryId()); assertEquals(photoForm.getTitle(), actualPhoto.getTitle()); assertEquals(photoForm.getDescription(), actualPhoto.getDescription()); assertEquals(photoForm.getImageSrc(), actualPhoto.getImageSrc()); verify(photoRepository, times(1)).findOne(expectedPhoto.getId()); verify(photoRepository, times(1)).save(expectedPhoto); verifyNoMoreInteractions(photoRepository); }