/** Tests a sync operation if no songs can be found. */ @Test public void testProduceResultsNoSongs() { initMocks(); List<SongEntity> songs = Collections.emptyList(); List<Command> syncCmds = Collections.emptyList(); controller.startSynchronization(0); Command endCmd = EasyMock.createMock(Command.class); queue.execute(endCmd); EasyMock.replay(endCmd, observer, controller, queue); SyncCommandTestImpl cmd = new SyncCommandTestImpl(init, observer, controller, queue, null) { @Override protected EntityManager getEntityManager() { return jpaHelper.getEM(); } @Override OAuthTemplate createOAuthTemplate() { throw new UnsupportedOperationException("Unexpected method call!"); } }; cmd.installMockEndCommand(endCmd); cmd.installMockEntities(songs, syncCmds); cmd.produceResults(jpaHelper.getEM()); EasyMock.verify(endCmd, observer, controller, queue); }
/** Tests whether a limit is taken into account when retrieving songs. */ @Test public void testFetchSongsWithLimit() { persistTestSongs(); SyncCommandTestImpl cmd = createCommand(SONG_COUNT - 1); List<SongEntity> songs = cmd.fetchSongsToSync(jpaHelper.getEM()); assertEquals("Wrong number of songs", SONG_COUNT - 1, songs.size()); for (SongEntity song : songs) { assertTrue("No play count: " + song, song.getCurrentPlayCount() > 0); } }
/** Tests whether the song entities have been fully initialized. */ @Test public void testFetchSongsInitialized() { persistTestSongs(); SyncCommandTestImpl cmd = createCommand(null); List<SongEntity> songs = cmd.fetchSongsToSync(jpaHelper.getEM()); jpaHelper.closeEM(); for (SongEntity song : songs) { assertNotNull("No artist", song.getArtist()); assertNotNull("No album", song.getAlbum()); } }
/** Tests whether all songs that need to be synchronized are found. */ @Test public void testFetchSongsToSyncNoLimit() { persistTestSongs(); SyncCommandTestImpl cmd = createCommand(null); List<SongEntity> songs = cmd.fetchSongsToSync(jpaHelper.getEM()); assertEquals("Wrong number of songs", SONG_COUNT, songs.size()); for (int i = 1; i <= SONG_COUNT; i++) { String songName = SONG_NAME + i; boolean found = false; for (SongEntity song : songs) { if (songName.equals(song.getName())) { found = true; break; } } assertTrue("Song not found: " + i, found); } }