@Before public void setupLibrary() { directory = TestUtils.buildTestDirectory(getClass()); library = new MediaLibrary(); library.setName("I like monkeys"); library.setBaseDirectory(directory); }
@Test(expected = DuplicateMediaLibraryException.class) public void testDuplicateMediaLibraryName() throws DuplicateMediaLibraryException { MediaLibrary duplicate = new MediaLibrary(); duplicate.setName("I like monkeys"); duplicate.setBaseDirectory(TestUtils.buildTestDirectory(getClass())); dao.save(library); dao.save(duplicate); }
@Test public void testSaveNoFiles() throws DuplicateMediaLibraryException { String name = library.getName(); dao.save(library); MediaLibrary savedLibrary = dao.read(name); assertNotNull(savedLibrary); assertSame(library, savedLibrary); }
@Test public void testReadAll() throws DuplicateMediaLibraryException { dao.save(library); library = null; setupLibrary(); library.setName("Here is a new name"); dao.save(library); Collection<MediaLibrary> libraries = dao.readAll(); assertEquals(2, libraries.size()); }
@Test public void testMovieIsSavedCorrectly() throws IOException, CremaException { File file = TestUtils.buildFileRelativeToDirectory(directory, "movie.mpg"); library.addMovie(file); assertFalse(library.getMoviesByFilePath().isEmpty()); dao.save(library); MediaLibrary savedLibrary = dao.read(library.getName()); Movie movie = savedLibrary.getMoviesByFilePath().values().iterator().next(); assertSame(library, savedLibrary); assertFalse(savedLibrary.getMoviesByFilePath().isEmpty()); assertEquals("movie.mpg", movie.getFirstMediaFile().getRelativePath()); }