View Javadoc

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.commons;
20  
21  import java.util.Arrays;
22  
23  import junit.framework.TestCase;
24  
25  /***
26   * Tests the {@link MiscUtils} class.
27   * 
28   * @author Martin Vysny
29   */
30  public final class MiscUtilsTest extends TestCase {
31  	/***
32  	 * 
33  	 */
34  	public void testFormatByteLength() {
35  		assertEquals("5b", MiscUtils.formatByteLength(5));
36  		assertEquals("4.9kb", MiscUtils.formatByteLength(5 * 1024 - 1));
37  		assertEquals("5kb", MiscUtils.formatByteLength(5 * 1024));
38  		assertEquals("5Mb", MiscUtils.formatByteLength(5 * 1024 * 1024));
39  		assertEquals("200Gb", MiscUtils
40  				.formatByteLength(200L * 1024 * 1024 * 1024));
41  		assertEquals("199.9Gb", MiscUtils.formatByteLength(200L * 1024 * 1024
42  				* 1024 - 1));
43  	}
44  
45  	/***
46  	 * 
47  	 */
48  	public void testFixAlbumArtistName() {
49  		assertNull(MiscUtils.fixArtistAlbumName(null));
50  		assertEquals("Future Sound of London, The", MiscUtils
51  				.fixArtistAlbumName("   The Future Sound of London "));
52  		assertEquals("cranberries, the", MiscUtils
53  				.fixArtistAlbumName("the   cranberries"));
54  		assertEquals("flUKE", MiscUtils.fixArtistAlbumName("flUKE "));
55  	}
56  
57  	/***
58  	 * 
59  	 */
60  	public void testArrayHexa() {
61  		checkArray(null);
62  		checkArray(new byte[] {});
63  		checkArray(new byte[] { 0, 0, 0 });
64  		checkArray(new byte[] { -128, 0 });
65  		checkArray(new byte[] { -128, 0, 127, -1, -2, -54, 54, 1, -127, 126 });
66  	}
67  
68  	private void checkArray(byte[] bs) {
69  		assertTrue(Arrays.equals(bs, MiscUtils.fromHexa(MiscUtils.toHexa(bs))));
70  	}
71  }