aboutsummaryrefslogtreecommitdiff
path: root/subsonic-main/src/test/java/net/sourceforge/subsonic/service
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2012-07-02 21:24:02 -0700
committerScott Jackson <daneren2005@gmail.com>2012-07-02 21:24:02 -0700
commita1a18f77a50804e0127dfa4b0f5240c49c541184 (patch)
tree19a38880afe505beddb5590379a8134d7730a277 /subsonic-main/src/test/java/net/sourceforge/subsonic/service
parentb61d787706979e7e20f4c3c4f93c1f129d92273f (diff)
downloaddsub-a1a18f77a50804e0127dfa4b0f5240c49c541184.tar.gz
dsub-a1a18f77a50804e0127dfa4b0f5240c49c541184.tar.bz2
dsub-a1a18f77a50804e0127dfa4b0f5240c49c541184.zip
Initial Commit
Diffstat (limited to 'subsonic-main/src/test/java/net/sourceforge/subsonic/service')
-rw-r--r--subsonic-main/src/test/java/net/sourceforge/subsonic/service/MusicIndexServiceTestCase.java76
-rw-r--r--subsonic-main/src/test/java/net/sourceforge/subsonic/service/SecurityServiceTestCase.java59
-rw-r--r--subsonic-main/src/test/java/net/sourceforge/subsonic/service/SettingsServiceTestCase.java140
-rw-r--r--subsonic-main/src/test/java/net/sourceforge/subsonic/service/StatusServiceTestCase.java83
-rw-r--r--subsonic-main/src/test/java/net/sourceforge/subsonic/service/metadata/MediaFileTestCase.java60
-rw-r--r--subsonic-main/src/test/java/net/sourceforge/subsonic/service/metadata/MetaDataParserTestCase.java92
6 files changed, 510 insertions, 0 deletions
diff --git a/subsonic-main/src/test/java/net/sourceforge/subsonic/service/MusicIndexServiceTestCase.java b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/MusicIndexServiceTestCase.java
new file mode 100644
index 00000000..18fa2443
--- /dev/null
+++ b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/MusicIndexServiceTestCase.java
@@ -0,0 +1,76 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.service;
+
+import junit.framework.TestCase;
+import net.sourceforge.subsonic.domain.MusicIndex;
+
+import java.util.List;
+
+/**
+ * Unit test of {@link MusicIndex}.
+ *
+ * @author Sindre Mehus
+ */
+public class MusicIndexServiceTestCase extends TestCase {
+
+ private final MusicIndexService musicIndexService = new MusicIndexService();
+
+ public void testCreateIndexFromExpression() throws Exception {
+ MusicIndex index = musicIndexService.createIndexFromExpression("A");
+ assertEquals("A", index.getIndex());
+ assertEquals(1, index.getPrefixes().size());
+ assertEquals("A", index.getPrefixes().get(0));
+
+ index = musicIndexService.createIndexFromExpression("The");
+ assertEquals("The", index.getIndex());
+ assertEquals(1, index.getPrefixes().size());
+ assertEquals("The", index.getPrefixes().get(0));
+
+ index = musicIndexService.createIndexFromExpression("X-Z(XYZ)");
+ assertEquals("X-Z", index.getIndex());
+ assertEquals(3, index.getPrefixes().size());
+ assertEquals("X", index.getPrefixes().get(0));
+ assertEquals("Y", index.getPrefixes().get(1));
+ assertEquals("Z", index.getPrefixes().get(2));
+ }
+
+ public void testCreateIndexesFromExpression() throws Exception {
+ List<MusicIndex> indexes = musicIndexService.createIndexesFromExpression("A B The X-Z(XYZ)");
+ assertEquals(4, indexes.size());
+
+ assertEquals("A", indexes.get(0).getIndex());
+ assertEquals(1, indexes.get(0).getPrefixes().size());
+ assertEquals("A", indexes.get(0).getPrefixes().get(0));
+
+ assertEquals("B", indexes.get(1).getIndex());
+ assertEquals(1, indexes.get(1).getPrefixes().size());
+ assertEquals("B", indexes.get(1).getPrefixes().get(0));
+
+ assertEquals("The", indexes.get(2).getIndex());
+ assertEquals(1, indexes.get(2).getPrefixes().size());
+ assertEquals("The", indexes.get(2).getPrefixes().get(0));
+
+ assertEquals("X-Z", indexes.get(3).getIndex());
+ assertEquals(3, indexes.get(3).getPrefixes().size());
+ assertEquals("X", indexes.get(3).getPrefixes().get(0));
+ assertEquals("Y", indexes.get(3).getPrefixes().get(1));
+ assertEquals("Z", indexes.get(3).getPrefixes().get(2));
+ }
+} \ No newline at end of file
diff --git a/subsonic-main/src/test/java/net/sourceforge/subsonic/service/SecurityServiceTestCase.java b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/SecurityServiceTestCase.java
new file mode 100644
index 00000000..001b124c
--- /dev/null
+++ b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/SecurityServiceTestCase.java
@@ -0,0 +1,59 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.service;
+
+import junit.framework.*;
+/**
+ * Unit test of {@link SecurityService}.
+ *
+ * @author Sindre Mehus
+ */
+public class SecurityServiceTestCase extends TestCase {
+
+ public void testIsFileInFolder() {
+ SecurityService service = new SecurityService();
+
+ assertTrue(service.isFileInFolder("/music/foo.mp3", "\\"));
+ assertTrue(service.isFileInFolder("/music/foo.mp3", "/"));
+
+ assertTrue(service.isFileInFolder("/music/foo.mp3", "/music"));
+ assertTrue(service.isFileInFolder("\\music\\foo.mp3", "/music"));
+ assertTrue(service.isFileInFolder("/music/foo.mp3", "\\music"));
+ assertTrue(service.isFileInFolder("/music/foo.mp3", "\\music\\"));
+
+ assertFalse(service.isFileInFolder("", "/tmp"));
+ assertFalse(service.isFileInFolder("foo.mp3", "/tmp"));
+ assertFalse(service.isFileInFolder("/music/foo.mp3", "/tmp"));
+ assertFalse(service.isFileInFolder("/music/foo.mp3", "/tmp/music"));
+
+ // Test that references to the parent directory (..) is not allowed.
+ assertTrue(service.isFileInFolder("/music/foo..mp3", "/music"));
+ assertTrue(service.isFileInFolder("/music/foo..", "/music"));
+ assertTrue(service.isFileInFolder("/music/foo.../", "/music"));
+ assertFalse(service.isFileInFolder("/music/foo/..", "/music"));
+ assertFalse(service.isFileInFolder("../music/foo", "/music"));
+ assertFalse(service.isFileInFolder("/music/../foo", "/music"));
+ assertFalse(service.isFileInFolder("/music/../bar/../foo", "/music"));
+ assertFalse(service.isFileInFolder("/music\\foo\\..", "/music"));
+ assertFalse(service.isFileInFolder("..\\music/foo", "/music"));
+ assertFalse(service.isFileInFolder("/music\\../foo", "/music"));
+ assertFalse(service.isFileInFolder("/music/..\\bar/../foo", "/music"));
+ }
+}
+
diff --git a/subsonic-main/src/test/java/net/sourceforge/subsonic/service/SettingsServiceTestCase.java b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/SettingsServiceTestCase.java
new file mode 100644
index 00000000..bbb2fda0
--- /dev/null
+++ b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/SettingsServiceTestCase.java
@@ -0,0 +1,140 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.service;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+
+/**
+ * Unit test of {@link SettingsService}.
+ *
+ * @author Sindre Mehus
+ */
+public class SettingsServiceTestCase extends TestCase {
+
+ private static final File SUBSONIC_HOME = new File("/tmp/subsonic");
+
+ private SettingsService settingsService;
+
+ @Override
+ protected void setUp() throws Exception {
+ System.setProperty("subsonic.home", SUBSONIC_HOME.getPath());
+ new File(SUBSONIC_HOME, "subsonic.properties").delete();
+ settingsService = new SettingsService();
+ }
+
+ public void testSubsonicHome() {
+ assertEquals("Wrong Subsonic home.", SUBSONIC_HOME, SettingsService.getSubsonicHome());
+ }
+
+ public void testDefaultValues() {
+ assertEquals("Wrong default language.", "en", settingsService.getLocale().getLanguage());
+ assertEquals("Wrong default cover art limit.", 30, settingsService.getCoverArtLimit());
+ assertEquals("Wrong default index creation interval.", 1, settingsService.getIndexCreationInterval());
+ assertEquals("Wrong default index creation hour.", 3, settingsService.getIndexCreationHour());
+ assertEquals("Wrong default theme.", "default", settingsService.getThemeId());
+ assertEquals("Wrong default stream port.", 0, settingsService.getStreamPort());
+ assertNull("Wrong default license email.", settingsService.getLicenseEmail());
+ assertNull("Wrong default license code.", settingsService.getLicenseCode());
+ assertNull("Wrong default license date.", settingsService.getLicenseDate());
+ assertEquals("Wrong default Podcast episode retention count.", 10, settingsService.getPodcastEpisodeRetentionCount());
+ assertEquals("Wrong default Podcast episode download count.", 1, settingsService.getPodcastEpisodeDownloadCount());
+ assertTrue("Wrong default Podcast folder.", settingsService.getPodcastFolder().endsWith("Podcast"));
+ assertEquals("Wrong default Podcast update interval.", 24, settingsService.getPodcastUpdateInterval());
+ assertEquals("Wrong default rewrite URL enabled.", true, settingsService.isRewriteUrlEnabled());
+ assertEquals("Wrong default LDAP enabled.", false, settingsService.isLdapEnabled());
+ assertEquals("Wrong default LDAP URL.", "ldap://host.domain.com:389/cn=Users,dc=domain,dc=com", settingsService.getLdapUrl());
+ assertNull("Wrong default LDAP manager DN.", settingsService.getLdapManagerDn());
+ assertNull("Wrong default LDAP manager password.", settingsService.getLdapManagerPassword());
+ assertEquals("Wrong default LDAP search filter.", "(sAMAccountName={0})", settingsService.getLdapSearchFilter());
+ assertEquals("Wrong default LDAP auto-shadowing.", false, settingsService.isLdapAutoShadowing());
+ }
+
+ public void testChangeSettings() {
+ settingsService.setIndexString("indexString");
+ settingsService.setIgnoredArticles("a the foo bar");
+ settingsService.setShortcuts("new incoming \"rock 'n' roll\"");
+ settingsService.setMusicFileTypes("mp3 ogg aac");
+ settingsService.setCoverArtFileTypes("jpeg gif png");
+ settingsService.setCoverArtLimit(99);
+ settingsService.setWelcomeMessage("welcomeMessage");
+ settingsService.setLoginMessage("loginMessage");
+ settingsService.setLocale(Locale.CANADA_FRENCH);
+ settingsService.setThemeId("dark");
+ settingsService.setIndexCreationInterval(4);
+ settingsService.setIndexCreationHour(9);
+ settingsService.setStreamPort(8080);
+ settingsService.setLicenseEmail("sindre@foo.bar.no");
+ settingsService.setLicenseCode(null);
+ settingsService.setLicenseDate(new Date(223423412351253L));
+ settingsService.setPodcastEpisodeRetentionCount(5);
+ settingsService.setPodcastEpisodeDownloadCount(-1);
+ settingsService.setPodcastFolder("d:/podcasts");
+ settingsService.setPodcastUpdateInterval(-1);
+ settingsService.setRewriteUrlEnabled(false);
+ settingsService.setLdapEnabled(true);
+ settingsService.setLdapUrl("newLdapUrl");
+ settingsService.setLdapManagerDn("admin");
+ settingsService.setLdapManagerPassword("secret");
+ settingsService.setLdapSearchFilter("newLdapSearchFilter");
+ settingsService.setLdapAutoShadowing(true);
+
+ verifySettings(settingsService);
+
+ settingsService.save();
+ verifySettings(settingsService);
+
+ verifySettings(new SettingsService());
+ }
+
+ private void verifySettings(SettingsService ss) {
+ assertEquals("Wrong index string.", "indexString", ss.getIndexString());
+ assertEquals("Wrong ignored articles.", "a the foo bar", ss.getIgnoredArticles());
+ assertEquals("Wrong shortcuts.", "new incoming \"rock 'n' roll\"", ss.getShortcuts());
+ assertTrue("Wrong ignored articles array.", Arrays.equals(new String[] {"a", "the", "foo", "bar"}, ss.getIgnoredArticlesAsArray()));
+ assertTrue("Wrong shortcut array.", Arrays.equals(new String[] {"new", "incoming", "rock 'n' roll"}, ss.getShortcutsAsArray()));
+ assertEquals("Wrong music mask.", "mp3 ogg aac", ss.getMusicFileTypes());
+ assertTrue("Wrong music mask array.", Arrays.equals(new String[] {"mp3", "ogg", "aac"}, ss.getMusicFileTypesAsArray()));
+ assertEquals("Wrong cover art mask.", "jpeg gif png", ss.getCoverArtFileTypes());
+ assertTrue("Wrong cover art mask array.", Arrays.equals(new String[] {"jpeg", "gif", "png"}, ss.getCoverArtFileTypesAsArray()));
+ assertEquals("Wrong cover art limit.", 99, ss.getCoverArtLimit());
+ assertEquals("Wrong welcome message.", "welcomeMessage", ss.getWelcomeMessage());
+ assertEquals("Wrong login message.", "loginMessage", ss.getLoginMessage());
+ assertEquals("Wrong locale.", Locale.CANADA_FRENCH, ss.getLocale());
+ assertEquals("Wrong theme.", "dark", ss.getThemeId());
+ assertEquals("Wrong index creation interval.", 4, ss.getIndexCreationInterval());
+ assertEquals("Wrong index creation hour.", 9, ss.getIndexCreationHour());
+ assertEquals("Wrong stream port.", 8080, ss.getStreamPort());
+ assertEquals("Wrong license email.", "sindre@foo.bar.no", ss.getLicenseEmail());
+ assertEquals("Wrong license code.", null, ss.getLicenseCode());
+ assertEquals("Wrong license date.", new Date(223423412351253L), ss.getLicenseDate());
+ assertEquals("Wrong Podcast episode retention count.", 5, settingsService.getPodcastEpisodeRetentionCount());
+ assertEquals("Wrong Podcast episode download count.", -1, settingsService.getPodcastEpisodeDownloadCount());
+ assertEquals("Wrong Podcast folder.", "d:/podcasts", settingsService.getPodcastFolder());
+ assertEquals("Wrong Podcast update interval.", -1, settingsService.getPodcastUpdateInterval());
+ assertEquals("Wrong rewrite URL enabled.", false, settingsService.isRewriteUrlEnabled());
+ assertTrue("Wrong LDAP enabled.", settingsService.isLdapEnabled());
+ assertEquals("Wrong LDAP URL.", "newLdapUrl", settingsService.getLdapUrl());
+ assertEquals("Wrong LDAP manager DN.", "admin", settingsService.getLdapManagerDn());
+ assertEquals("Wrong LDAP manager password.", "secret", settingsService.getLdapManagerPassword());
+ assertEquals("Wrong LDAP search filter.", "newLdapSearchFilter", settingsService.getLdapSearchFilter());
+ assertTrue("Wrong LDAP auto-shadowing.", settingsService.isLdapAutoShadowing());
+ }
+}
diff --git a/subsonic-main/src/test/java/net/sourceforge/subsonic/service/StatusServiceTestCase.java b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/StatusServiceTestCase.java
new file mode 100644
index 00000000..47f27fbf
--- /dev/null
+++ b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/StatusServiceTestCase.java
@@ -0,0 +1,83 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.service;
+
+import junit.framework.TestCase;
+import net.sourceforge.subsonic.domain.Player;
+import net.sourceforge.subsonic.domain.TransferStatus;
+
+import java.util.Arrays;
+
+/**
+ * Unit test of {@link StatusService}.
+ *
+ * @author Sindre Mehus
+ */
+public class StatusServiceTestCase extends TestCase {
+
+ private StatusService service;
+ private Player player1;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ service = new StatusService();
+ player1 = new Player();
+ player1.setId("1");
+ }
+
+ public void testSimpleAddRemove() {
+ TransferStatus status = service.createStreamStatus(player1);
+ assertTrue("Wrong status.", status.isActive());
+ assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getAllStreamStatuses());
+ assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getStreamStatusesForPlayer(player1));
+
+ service.removeStreamStatus(status);
+ assertFalse("Wrong status.", status.isActive());
+ assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getAllStreamStatuses());
+ assertEquals("Wrong list of statuses.", Arrays.asList(status), service.getStreamStatusesForPlayer(player1));
+ }
+
+ public void testMultipleStreamsSamePlayer() {
+ TransferStatus statusA = service.createStreamStatus(player1);
+ TransferStatus statusB = service.createStreamStatus(player1);
+
+ assertEquals("Wrong list of statuses.", Arrays.asList(statusA, statusB), service.getAllStreamStatuses());
+ assertEquals("Wrong list of statuses.", Arrays.asList(statusA, statusB), service.getStreamStatusesForPlayer(player1));
+
+ // Stop stream A.
+ service.removeStreamStatus(statusA);
+ assertFalse("Wrong status.", statusA.isActive());
+ assertTrue("Wrong status.", statusB.isActive());
+ assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getAllStreamStatuses());
+ assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getStreamStatusesForPlayer(player1));
+
+ // Stop stream B.
+ service.removeStreamStatus(statusB);
+ assertFalse("Wrong status.", statusB.isActive());
+ assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getAllStreamStatuses());
+ assertEquals("Wrong list of statuses.", Arrays.asList(statusB), service.getStreamStatusesForPlayer(player1));
+
+ // Start stream C.
+ TransferStatus statusC = service.createStreamStatus(player1);
+ assertTrue("Wrong status.", statusC.isActive());
+ assertEquals("Wrong list of statuses.", Arrays.asList(statusC), service.getAllStreamStatuses());
+ assertEquals("Wrong list of statuses.", Arrays.asList(statusC), service.getStreamStatusesForPlayer(player1));
+ }
+}
diff --git a/subsonic-main/src/test/java/net/sourceforge/subsonic/service/metadata/MediaFileTestCase.java b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/metadata/MediaFileTestCase.java
new file mode 100644
index 00000000..ccc728ea
--- /dev/null
+++ b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/metadata/MediaFileTestCase.java
@@ -0,0 +1,60 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.service.metadata;
+
+import junit.framework.TestCase;
+import net.sourceforge.subsonic.domain.MediaFile;
+
+/**
+ * Unit test of {@link MediaFile}.
+ *
+ * @author Sindre Mehus
+ */
+public class MediaFileTestCase extends TestCase {
+
+ public void testGetDurationAsString() throws Exception {
+ doTestGetDurationAsString(0, "0:00");
+ doTestGetDurationAsString(1, "0:01");
+ doTestGetDurationAsString(10, "0:10");
+ doTestGetDurationAsString(33, "0:33");
+ doTestGetDurationAsString(59, "0:59");
+ doTestGetDurationAsString(60, "1:00");
+ doTestGetDurationAsString(61, "1:01");
+ doTestGetDurationAsString(70, "1:10");
+ doTestGetDurationAsString(119, "1:59");
+ doTestGetDurationAsString(120, "2:00");
+ doTestGetDurationAsString(1200, "20:00");
+ doTestGetDurationAsString(1201, "20:01");
+ doTestGetDurationAsString(3599, "59:59");
+ doTestGetDurationAsString(3600, "1:00:00");
+ doTestGetDurationAsString(3601, "1:00:01");
+ doTestGetDurationAsString(3661, "1:01:01");
+ doTestGetDurationAsString(4200, "1:10:00");
+ doTestGetDurationAsString(4201, "1:10:01");
+ doTestGetDurationAsString(4210, "1:10:10");
+ doTestGetDurationAsString(36000, "10:00:00");
+ doTestGetDurationAsString(360000, "100:00:00");
+ }
+
+ private void doTestGetDurationAsString(int seconds, String expected) {
+ MediaFile mediaFile = new MediaFile();
+ mediaFile.setDurationSeconds(seconds);
+ assertEquals("Error in getDurationString().", expected, mediaFile.getDurationString());
+ }
+} \ No newline at end of file
diff --git a/subsonic-main/src/test/java/net/sourceforge/subsonic/service/metadata/MetaDataParserTestCase.java b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/metadata/MetaDataParserTestCase.java
new file mode 100644
index 00000000..254e93d0
--- /dev/null
+++ b/subsonic-main/src/test/java/net/sourceforge/subsonic/service/metadata/MetaDataParserTestCase.java
@@ -0,0 +1,92 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2009 (C) Sindre Mehus
+ */
+package net.sourceforge.subsonic.service.metadata;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+import net.sourceforge.subsonic.domain.MediaFile;
+
+/**
+ * Unit test of {@link MetaDataParser}.
+ *
+ * @author Sindre Mehus
+ */
+public class MetaDataParserTestCase extends TestCase {
+
+ public void testRemoveTrackNumberFromTitle() throws Exception {
+
+ MetaDataParser parser = new MetaDataParser() {
+ public MetaData getRawMetaData(File file) {
+ return null;
+ }
+
+ public void setMetaData(MediaFile file, MetaData metaData) {
+ }
+
+ public boolean isEditingSupported() {
+ return false;
+ }
+
+ public boolean isApplicable(File file) {
+ return false;
+ }
+ };
+
+ assertEquals("", parser.removeTrackNumberFromTitle("", null));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("kokos", null));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("01 kokos", null));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("01 - kokos", null));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("01-kokos", null));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("01 - kokos", null));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("99 - kokos", null));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("99.- kokos", null));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle(" 01 kokos", null));
+ assertEquals("400 years", parser.removeTrackNumberFromTitle("400 years", null));
+ assertEquals("49ers", parser.removeTrackNumberFromTitle("49ers", null));
+ assertEquals("01", parser.removeTrackNumberFromTitle("01", null));
+ assertEquals("01", parser.removeTrackNumberFromTitle("01 ", null));
+ assertEquals("01", parser.removeTrackNumberFromTitle(" 01 ", null));
+ assertEquals("01", parser.removeTrackNumberFromTitle(" 01", null));
+
+ assertEquals("", parser.removeTrackNumberFromTitle("", 1));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("01 kokos", 1));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("01 - kokos", 1));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("01-kokos", 1));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("99 - kokos", 99));
+ assertEquals("kokos", parser.removeTrackNumberFromTitle("99.- kokos", 99));
+ assertEquals("01 kokos", parser.removeTrackNumberFromTitle("01 kokos", 2));
+ assertEquals("1 kokos", parser.removeTrackNumberFromTitle("1 kokos", 2));
+ assertEquals("50 years", parser.removeTrackNumberFromTitle("50 years", 1));
+ assertEquals("years", parser.removeTrackNumberFromTitle("50 years", 50));
+ assertEquals("15 Step", parser.removeTrackNumberFromTitle("15 Step", 1));
+ assertEquals("Step", parser.removeTrackNumberFromTitle("15 Step", 15));
+
+ assertEquals("49ers", parser.removeTrackNumberFromTitle("49ers", 1));
+ assertEquals("49ers", parser.removeTrackNumberFromTitle("49ers", 49));
+ assertEquals("01", parser.removeTrackNumberFromTitle("01", 1));
+ assertEquals("01", parser.removeTrackNumberFromTitle("01 ", 1));
+ assertEquals("01", parser.removeTrackNumberFromTitle(" 01 ", 1));
+ assertEquals("01", parser.removeTrackNumberFromTitle(" 01", 1));
+ assertEquals("01", parser.removeTrackNumberFromTitle("01", 2));
+ assertEquals("01", parser.removeTrackNumberFromTitle("01 ", 2));
+ assertEquals("01", parser.removeTrackNumberFromTitle(" 01 ", 2));
+ assertEquals("01", parser.removeTrackNumberFromTitle(" 01", 2));
+ }
+} \ No newline at end of file