1 /***
2 * Ambient - A music player for the Android platform
3 Copyright (C) 2007 Martin Vysny
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 package sk.baka.ambient.playlist;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import sk.baka.ambient.collection.TrackMetadataBean;
24 import sk.baka.ambient.commons.Interval;
25
26 /***
27 * Tests the {@link StaticPlaylistStrategy} strategy.
28 *
29 * @author mvy
30 */
31 public class StaticPlaylistStrategyTest extends AbstractPlaylistStrategyTest {
32
33 @Override
34 protected IPlaylistStrategy getStrategy() {
35 return new StaticPlaylistStrategy(null);
36 }
37
38 /***
39 * Checks if next/previous on the -1th track will return correct values.
40 */
41 public void testPlaylistWrap() {
42 assertEquals(-1, strategy.next());
43 strategy.add(0, tracks);
44 assertEquals(tracks.size() - 1, strategy.previous());
45 assertEquals(-1, strategy.next());
46 assertEquals(0, strategy.next());
47 }
48
49 /***
50 *
51 */
52 public void testRequeueTracks() {
53 strategy.add(0, tracks);
54 verifyQueueProperties(0);
55 Interval queueInterval = new Interval(5, 5);
56 strategy.queue(queueInterval);
57 queueInterval = new Interval(15, 5);
58 strategy.queue(queueInterval);
59 queueInterval = new Interval(15, 5);
60 strategy.queue(queueInterval);
61 List<TrackMetadataBean> expectedQueue = new ArrayList<TrackMetadataBean>(
62 tracks.subList(5, 10));
63 expectedQueue.addAll(tracks.subList(15, 20));
64 assertEqualsQueue(expectedQueue);
65 verifyQueueProperties(10);
66 queueInterval = new Interval(8, 10);
67 strategy.queue(queueInterval);
68 expectedQueue = new ArrayList<TrackMetadataBean>(tracks.subList(5, 10));
69 expectedQueue.addAll(tracks.subList(15, 20));
70 expectedQueue.addAll(tracks.subList(10, 15));
71 assertEqualsQueue(expectedQueue);
72 verifyQueueProperties(15);
73 }
74
75 /***
76 *
77 */
78 public void testRandomTrackPlaysEachTrackOnce() {
79 strategy.add(0, tracks);
80 strategy.setRandom(Random.TRACK);
81 assertNextTracksUnordered(tracks, true);
82 }
83
84 /***
85 *
86 */
87 public void testRandomAlbumPlaysEachTrackOnce() {
88 strategy.add(0, tracks);
89 strategy.setRandom(Random.ALBUM);
90 assertNextTracksUnordered(tracks, true);
91 }
92
93 /***
94 *
95 */
96 @Override
97 public void testNormalOrder() {
98 strategy.add(0, tracks);
99 assertNextTracks(tracks, true);
100 }
101
102 /***
103 * When the currently played track is removed from the playlist, current
104 * track must be set to -1.
105 */
106 public void testRemovingPlayedTrack() {
107 strategy.add(0, tracks);
108 strategy.play(15);
109 strategy.remove(new Interval(10, 10));
110 assertEquals(-1, strategy.getCurrentlyPlaying());
111 }
112
113 /***
114 *
115 */
116 public void testSetModeRandomAlbum() {
117 strategy.add(0, tracks);
118 strategy.next();
119 assertEquals(1, strategy.next());
120 strategy.setRandom(Random.ALBUM);
121 strategy.next();
122 assertEquals(tracks.get(10), getCurrentlyPlaying());
123 strategy.next();
124 assertEquals(tracks.get(11), getCurrentlyPlaying());
125 }
126
127 }