Skip to main content
summaryrefslogtreecommitdiffstats
blob: 818a14463c47092e60898bd32c57853608c4d1d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*******************************************************************************
 * Copyright (c) 2004, 2007 Mylyn project committers 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
 *******************************************************************************/
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 format for many situations
 * <p>
 * <strong>This test may fail if run in non-english locales because the decimal point is localized; the workaround is to
 * change your locale to en_US or append the following parameter to program arguments on JUnit plug-in test: "-nl en_US"</strong>
 * 
 * @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