1   package com.melloware.jukes.file.tag;
2   
3   import com.melloware.jukes.AbstractTestCase;
4   import com.melloware.jukes.exception.MusicTagException;
5   
6   /**
7    * Test case to excercise the MP3 ID3 library jaudiotagger.
8    * <p>
9    * Copyright (c) 2006
10   * Melloware, Inc. <http://www.melloware.com>
11   * @author Emil A. Lefkof III <info@melloware.com>
12   * @version 4.0
13   */
14  public class MusicTagTest
15      extends AbstractTestCase { 
16      
17      private MusicTag tag = null;
18  
19      /**
20       * Constructor for MusicTagTest.
21       * @param arg0
22       */
23      public MusicTagTest(String arg0) {
24          super(arg0);
25  
26      }
27  
28      public static void main(String[] args) {
29          junit.textui.TestRunner.run(MusicTagTest.class);
30      }
31  
32      /*
33       * Test method for 'com.melloware.jukes.file.MusicTag.extractTitleFromFilename()'
34       */
35      public void testExtractTitleFromFilename() {
36          assertNotNull(tag.extractTitleFromFilename());
37      }
38  
39      /*
40       * Test method for 'com.melloware.jukes.file.MusicTag.getDisc()'
41       */
42      public void testGetDisc() {
43          assertEquals("Disc", tag.getDisc());
44      }
45  
46      /*
47       * Test method for 'com.melloware.jukes.file.MusicTag.getArtist()'
48       */
49      public void testGetArtist() {
50          assertEquals("Artist", tag.getArtist());
51      }
52  
53      /*
54       * Test method for 'com.melloware.jukes.file.MusicTag.getComment()'
55       */
56      public void testGetComment() {
57          assertEquals("Comment", tag.getComment());
58      }
59  
60      /*
61       * Test method for 'com.melloware.jukes.file.MusicTag.getEncodedBy()'
62       */
63      public void testGetEncodedBy() {
64          assertEquals("Junit", tag.getEncodedBy());
65      }
66  
67      /*
68       * Test method for 'com.melloware.jukes.file.MusicTag.getGenre()'
69       */
70      public void testGetGenre() {
71          assertEquals("Rock", tag.getGenre());
72      }
73  
74      /*
75       * Test method for 'com.melloware.jukes.file.MusicTag.getHeaderInfo()'
76       */
77      public void testGetHeaderInfo() {
78          assertNotNull(tag.getHeaderInfo());
79      }
80  
81      /*
82       * Test method for 'com.melloware.jukes.file.MusicTag.getTitle()'
83       */
84      public void testGetTitle() {
85          assertEquals("Title", tag.getTitle());
86      }
87  
88      /*
89       * Test method for 'com.melloware.jukes.file.MusicTag.getTrack()'
90       */
91      public void testGetTrack() {
92          assertEquals("01", tag.getTrack());
93      }
94  
95      /*
96       * Test method for 'com.melloware.jukes.file.MusicTag.getYear()'
97       */
98      public void testGetYear() {
99          assertEquals("2006", tag.getYear());
100     }
101 
102     /*
103      * Test method for 'com.melloware.jukes.file.MusicTag.hashCode()'
104      */
105     public void testHashCode() {
106         assertTrue(tag.hashCode() != 0);
107     }
108 
109     /*
110      * Test method for 'com.melloware.jukes.file.MusicTag.removeTags()'
111      */
112     public void testRemoveTags() {
113         try {
114             tag.removeTags();
115         } catch (MusicTagException ex) {
116             fail("MusicTagException: Could not remove tags.");
117         }
118     }
119 
120     /*
121      * Test method for 'com.melloware.jukes.file.MusicTag.save()'
122      */
123     public void testSave() {
124         try {
125             tag.save();
126         } catch (MusicTagException ex) {
127             fail("MusicTagException: Could not save tags.");
128         }
129     }
130 
131     /*
132      * Test method for 'com.melloware.jukes.file.MusicTag.setDisc(String)'
133      */
134     public void testSetDisc() {
135         tag.setDisc("test");
136         assertEquals("test", tag.getDisc());
137     }
138 
139     /*
140      * Test method for 'com.melloware.jukes.file.MusicTag.setArtist(String)'
141      */
142     public void testSetArtist() {
143         tag.setArtist("test");
144         assertEquals("test", tag.getArtist());
145     }
146 
147     /*
148      * Test method for 'com.melloware.jukes.file.MusicTag.setComment(String)'
149      */
150     public void testSetComment() {
151         tag.setComment("test");
152         assertEquals("test", tag.getComment());
153     }
154 
155     /*
156      * Test method for 'com.melloware.jukes.file.MusicTag.setEncodedBy(String)'
157      */
158     public void testSetEncodedBy() {
159         tag.setEncodedBy("test");
160         assertEquals("test", tag.getEncodedBy());
161     }
162 
163     /*
164      * Test method for 'com.melloware.jukes.file.MusicTag.setGenre(String)'
165      */
166     public void testSetGenre() {
167         tag.setGenre("test");
168         assertEquals("test", tag.getGenre());
169     }
170 
171     /*
172      * Test method for 'com.melloware.jukes.file.MusicTag.setTitle(String)'
173      */
174     public void testSetTitle() {
175         tag.setTitle("test");
176         assertEquals("test", tag.getTitle());
177     }
178 
179     /*
180      * Test method for 'com.melloware.jukes.file.MusicTag.setTrack(String)'
181      */
182     public void testSetTrack() {
183         tag.setTrack("2");
184         assertEquals("02", tag.getTrack());
185     }
186 
187     /*
188      * Test method for 'com.melloware.jukes.file.MusicTag.setYear(String)'
189      */
190     public void testSetYear() {
191         tag.setYear("1870");
192         assertEquals("1870", tag.getYear());
193     }
194 
195     /*
196      * Test method for 'com.melloware.jukes.file.MusicTag.toString()'
197      */
198     public void testToString() {
199         assertNotNull(tag.toString());
200     }
201 
202     /*
203      * @see TestCase#setUp()
204      */
205     protected void setUp()
206                   throws Exception {
207         super.setUp();
208         
209         try {
210             tag = TagFactory.getTag("C:/dev/melloware/jukes/trunk/src/test/java/com/melloware/jukes/file/01 - Test.mp3");
211             tag.setDisc("Disc");
212             tag.setArtist("Artist");
213             tag.setComment("Comment");
214             tag.setEncodedBy("Junit");
215             tag.setGenre("Rock");
216             tag.setTitle("Title");
217             tag.setTrack("1");
218             tag.setYear("2006");
219         } catch (MusicTagException ex) {
220             fail("Tag could not be created");
221         }
222     }
223 
224     /*
225      * @see TestCase#tearDown()
226      */
227     protected void tearDown()
228                      throws Exception {
229         super.tearDown();
230         if (tag != null) {
231             tag = null;
232         }
233     }
234 
235 }