@Test(expectedExceptions = NullPointerException.class) public void removeSong() { System.out.println("removeSong"); when(albumDao.removeSong(backInBlackAlbum, shootToThrillSong)).thenReturn(backInBlackAlbum); AlbumDTO result = albumFacade.removeSong(backInBlackAlbum.getId(), shootToThrillSong.getId()); assertEquals(mappingService.mapTo(backInBlackAlbum, AlbumDTO.class), result); }
@Test public void updateReleaseDate() { System.out.println("updateRelease"); when(albumDao.update(backInBlackAlbum)).thenReturn(backInBlackAlbum); when(albumDao.findById(any(Long.class))).thenReturn(backInBlackAlbum); AlbumDTO result = albumFacade.updateAlbumReleaseDate(1l, Date.valueOf("1945-10-15")); assertEquals(mappingService.mapTo(backInBlackAlbum, AlbumDTO.class), result); }
@Test public void updateTitle() { System.out.println("updateTitle"); when(albumDao.update(backInBlackAlbum)).thenReturn(backInBlackAlbum); when(albumDao.findById(any(Long.class))).thenReturn(backInBlackAlbum); AlbumDTO result = albumFacade.updateAlbumTitle(1l, "new"); assertEquals(mappingService.mapTo(backInBlackAlbum, AlbumDTO.class), result); }
@Test public void testFindAlbumByTitle() { System.out.println("findAlbumByTitle"); when(albumDao.findByTitle(any(String.class))).thenReturn(backInBlackAlbum); AlbumDTO result = albumFacade.findByTitle(backInBlackAlbum.getTitle()); assertEquals(mappingService.mapTo(backInBlackAlbum, AlbumDTO.class), result); }
@Test public void testFindAll() { System.out.println("findAll"); List<Album> expectedResult = new ArrayList<>(); expectedResult.add(backInBlackAlbum); when(albumDao.findAll()).thenReturn(expectedResult); List<AlbumDTO> found = albumFacade.findAll(); Assert.assertEquals(expectedResult.size(), found.size()); for (int i = 0; i < expectedResult.size(); i++) { Assert.assertEquals( mappingService.mapTo(expectedResult.get(i), AlbumDTO.class), found.get(i)); } }