View Javadoc

1   package org.itracker.core.resources;
2   
3   import org.junit.Test;
4   
5   import static org.junit.Assert.*;
6   
7   public class MessageFormatTest {
8       @Test
9       public void testFormat() {
10          Object[] options = {"administrator", "administer", "the network"};
11          String message = MessageFormat.format("The {0} {1} {2}", options);
12          assertEquals("The administrator administer the network", message);
13      }
14  
15      @Test
16      public void testWrongOptions() {
17          Object[] options = {};
18          String message = MessageFormat.format("The {0} {1} {2}", options);
19          assertEquals("The   ", message);
20      }
21  
22      @Test
23      public void testNumberFormat() {
24          Integer a = new Integer(1);
25          Integer b = new Integer(2);
26          Integer c = a + b;
27          Object[] options = {a, b, c};
28          String message = MessageFormat.format("{0,number} + {1,number} equals {2,number}", options);
29          assertEquals(a + " + " + b + " equals " + c, message);
30      }
31  
32      @Test
33      public void testDecimalFormat() {
34          Double a = new Double(1);
35          Double b = new Double(2);
36          Double c = a - b;
37          Object[] options = {a, b, c};
38          String message = MessageFormat.format("{0,number,#.##} - {1,number,#.##} equals {2,number,#.##;(#.##)}", options);
39          assertEquals("1 - 2 equals (1)", message);
40      }
41  
42      @Test
43      public void testWrongDecimalFormat() {
44          Double a = new Double(((double) 1) / 3);
45          Object[] options = {a};
46          String message = MessageFormat.format("{0,number,\\.\\.\\.}", options);
47          assertEquals(a.toString(), message);
48      }
49  
50  }
51  
52