Skip to main content
summaryrefslogblamecommitdiffstats
blob: 0a4cf1b6531f71e3b8f5418bba0b302a6b3f4bcc (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                                                                                
                                                       



                                                                        



                                                       
                                                                                 
 

                                      

                        




                                                                           
                                          

                          
                       



                                                           


                                                                                           


                                           


                                                                                            


                                         



                                                                                                


                                       






                                                                                                       


                                       






                                                                                                       


                                       




                                                                                                       


         
/*******************************************************************************
 * Copyright (c) 2004, 2008 Willian Mitsuda and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Willian Mitsuda - initial API and implementation
 *     Frank Becker - improvements
 *******************************************************************************/

package org.eclipse.mylyn.tasks.tests;

import java.util.Locale;

import junit.framework.TestCase;

import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentSizeFormatter;

/**
 * Tests attachment size value formatting.
 * 
 * @author Willian Mitsuda
 * @author Frank Becker
 */
public class AttachmentSizeFormatterTest extends TestCase {

	public void testInvalidString() {
		AttachmentSizeFormatter formatter = AttachmentSizeFormatter.getInstance();
		assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, formatter.format(null));
		assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, formatter.format("x"));
	}

	public void testNotAValidNumber() {
		AttachmentSizeFormatter formatter = AttachmentSizeFormatter.getInstance();
		assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, formatter.format("-5"));
		assertEquals(AttachmentSizeFormatter.UNKNOWN_SIZE, formatter.format("1.0"));
	}

	public void testByteFormatter() {
		AttachmentSizeFormatter formatter = new AttachmentSizeFormatter(Locale.ENGLISH);
		assertEquals("1 byte", formatter.format("1"));
		assertEquals("2 bytes", formatter.format("2"));
		assertEquals("1023 bytes", formatter.format("1023"));
	}

	public void testKBFormatter() {
		AttachmentSizeFormatter formatterEnglish = new AttachmentSizeFormatter(Locale.ENGLISH);
		assertEquals("1.00 KB", formatterEnglish.format("1024"));
		assertEquals("1024.00 KB", formatterEnglish.format("1048575"));

		AttachmentSizeFormatter formatterGerman = new AttachmentSizeFormatter(Locale.GERMAN);
		assertEquals("1,00 KB", formatterGerman.format("1024"));
		assertEquals("1024,00 KB", formatterGerman.format("1048575"));
	}

	public void testMBFormatter() {
		AttachmentSizeFormatter formatterEnglish = new AttachmentSizeFormatter(Locale.ENGLISH);
		assertEquals("1.00 MB", formatterEnglish.format("1048576"));
		assertEquals("1024.00 MB", formatterEnglish.format("1073741823"));

		AttachmentSizeFormatter formatterGerman = new AttachmentSizeFormatter(Locale.GERMAN);
		assertEquals("1,00 MB", formatterGerman.format("1048576"));
		assertEquals("1024,00 MB", formatterGerman.format("1073741823"));
	}

	public void testGBFormatter() {
		AttachmentSizeFormatter formatterEnglish = new AttachmentSizeFormatter(Locale.ENGLISH);
		assertEquals("1.00 GB", formatterEnglish.format("1073741824"));

		AttachmentSizeFormatter formatterGerman = new AttachmentSizeFormatter(Locale.GERMAN);
		assertEquals("1,00 GB", formatterGerman.format("1073741824"));
	}

}

Back to the top