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
19 package sk.baka.ambient.stream.shoutcast;
20
21 import java.io.InputStream;
22 import java.util.Arrays;
23 import java.util.List;
24
25 import junit.framework.TestCase;
26 import sk.baka.ambient.commons.TestUtils;
27
28 /***
29 * Tests {@link ShoutcastUtils}.
30 *
31 * @author Martin Vysny
32 */
33 public final class ShoutcastUtilsTest extends TestCase {
34 /***
35 * @throws Exception
36 */
37 public void testReadEmptyGenres() throws Exception {
38 final InputStream xml = TestUtils.stringToInputStream(
39 "<?xml version=\"1.0\"?><genrelist/>", "UTF-8");
40 final List<String> genres = ShoutcastUtils.parseGenres(xml);
41 assertTrue(genres.isEmpty());
42 }
43 /***
44 * @throws Exception
45 */
46 public void testReadSimpleGenres() throws Exception {
47 final InputStream xml = TestUtils.stringToInputStream(
48 "<?xml version=\"1.0\"?><genrelist>" + "<genre/>"
49 + "<genre name=\"gen\"/>"
50 + "<genre name=\"gen2\"></genre>" + "</genrelist>",
51 "UTF-8");
52 final List<String> genres = ShoutcastUtils.parseGenres(xml);
53 assertEquals(Arrays.asList("gen", "gen2"), genres);
54 }
55
56 /***
57 *
58 */
59 public void testRemoveAsciiGraphics() {
60 assertEquals("test", ShoutcastUtils.removeAsciiGraphics("test"));
61 assertNull(ShoutcastUtils.removeAsciiGraphics(null));
62 assertEquals("", ShoutcastUtils.removeAsciiGraphics(""));
63 assertEquals("", ShoutcastUtils.removeAsciiGraphics(" "));
64 assertEquals("", ShoutcastUtils.removeAsciiGraphics(" ~~~"));
65 assertEquals("test", ShoutcastUtils.removeAsciiGraphics(" ~~~ test"));
66 assertEquals("test", ShoutcastUtils.removeAsciiGraphics("test ..::.."));
67 assertEquals("test", ShoutcastUtils
68 .removeAsciiGraphics("[[[test ..::.."));
69 }
70 }